Updated types

This commit is contained in:
2024-08-26 22:29:37 +02:00
parent 15cce327e3
commit 9050eff5a5
8 changed files with 36 additions and 36 deletions

View File

@@ -1,13 +1,13 @@
import { REST, Routes } from "discord.js" import { REST, Routes } from "discord.js"
import env from "../src/utils/Env" import env from "../src/utils/Env"
const rest = new REST({ version: "10" }).setToken(env.dev.devtoken!) const rest = new REST({ version: "10" }).setToken(env.dev.devtoken)
async function deleteCommands() { async function deleteCommands() {
try { try {
console.log("Started deleting application (/) commands.") console.log("Started deleting application (/) commands.")
await rest.put( await rest.put(
Routes.applicationGuildCommands(env.dev.devid!, env.dev.guildid!), Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid),
{ body: [] }, { body: [] },
) )
console.log("Successfully deleted application (/) commands.") console.log("Successfully deleted application (/) commands.")
@@ -15,4 +15,4 @@ async function deleteCommands() {
console.error(error) console.error(error)
} }
} }
deleteCommands() deleteCommands()

View File

@@ -3,7 +3,7 @@ import fs from "node:fs"
import { ICommand } from "../src/interfaces" import { ICommand } from "../src/interfaces"
import env from "../src/utils/Env" import env from "../src/utils/Env"
import color from "../src/utils/functions/colors" import color from "../src/utils/functions/colors"
const rest = new REST({ version: "10" }).setToken(env.prod.token!) const rest = new REST({ version: "10" }).setToken(env.prod.token)
const commands: RESTPutAPIApplicationCommandsJSONBody = [] const commands: RESTPutAPIApplicationCommandsJSONBody = []
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".ts")) const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".ts"))
@@ -26,7 +26,7 @@ for (const file of contentMenuCommands) {
console.log(color(commandsString.join("\n"), "lavender")) console.log(color(commandsString.join("\n"), "lavender"))
await rest.put( await rest.put(
Routes.applicationCommands(env.dev.clientid!), Routes.applicationCommands(env.dev.clientid),
{ body: commands }, { body: commands },
).then(() => { ).then(() => {
console.log(color(`Successfully reloaded ${commands.length} application (/) commands.`, "green")) console.log(color(`Successfully reloaded ${commands.length} application (/) commands.`, "green"))
@@ -36,4 +36,4 @@ for (const file of contentMenuCommands) {
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }
})() })()

View File

@@ -2,7 +2,7 @@ import { REST, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js"
import fs from "fs" import fs from "fs"
import env from "../src/utils/Env" import env from "../src/utils/Env"
import { ICommand } from "../src/interfaces" import { ICommand } from "../src/interfaces"
const rest = new REST({ version: "10" }).setToken(env.dev.devtoken!) const rest = new REST({ version: "10" }).setToken(env.dev.devtoken)
const commands: RESTPutAPIApplicationCommandsJSONBody = [] const commands: RESTPutAPIApplicationCommandsJSONBody = []
const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".ts")) const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".ts"))
@@ -26,7 +26,7 @@ for (const file of contentMenuCommands) {
console.log(`Started refreshing ${commands.length} application (/) commands.`) console.log(`Started refreshing ${commands.length} application (/) commands.`)
await rest.put( await rest.put(
Routes.applicationGuildCommands(env.dev.devid!, env.dev.guildid!), Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid),
{ body: commands }, { body: commands },
).then(() => { ).then(() => {
console.log(`Successfully reloaded ${commands.length} application (/) commands.`) console.log(`Successfully reloaded ${commands.length} application (/) commands.`)
@@ -35,4 +35,4 @@ for (const file of contentMenuCommands) {
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }
})() })()

View File

@@ -1,17 +1,17 @@
interface ProdEnv { interface ProdEnv {
token: string | undefined token: string
mongoURI: string | undefined mongoURI: string
dev: string | undefined dev: string
hypixelapikey: string | undefined hypixelapikey: string
redisURI: string | undefined redisURI: string
postgresURI: string | undefined postgresURI: string
} }
interface DevEnv { interface DevEnv {
devtoken: string | undefined devtoken: string
clientid: string | undefined clientid: string
devid: string | undefined devid: string
guildid: string | undefined guildid: string
} }
export default interface IEnv { export default interface IEnv {

View File

@@ -44,7 +44,7 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
}).sort((a, b) => a.name > b.name ? 1 : -1) }).sort((a, b) => a.name > b.name ? 1 : -1)
client.on("ready", async (c) => { client.on("ready", async (c) => {
const guildclient = c.guilds.cache.get(env.dev.guildid!)! const guildclient = c.guilds.cache.get(env.dev.guildid)!
const currentCommands = await guildclient.commands.fetch() const currentCommands = await guildclient.commands.fetch()
if (!currentCommands) return if (!currentCommands) return

View File

@@ -34,15 +34,15 @@ export class ExtendedClient extends Client {
let token: string let token: string
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") { if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
console.log(color("Running in development mode. [ts-node]", "lavender")) console.log(color("Running in development mode. [ts-node]", "lavender"))
token = env.dev.devtoken! token = env.dev.devtoken
autoDeployCommands("ts", this) autoDeployCommands("ts", this)
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) { } else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
console.log(color("Running in development mode.", "lavender")) console.log(color("Running in development mode.", "lavender"))
token = env.dev.devtoken! token = env.dev.devtoken
autoDeployCommands("js", this) autoDeployCommands("js", this)
} else { } else {
console.log(color("Running in production mode.", "green")) console.log(color("Running in production mode.", "green"))
token = env.prod.token! token = env.prod.token
} }
this.login(token) this.login(token)

View File

@@ -3,18 +3,18 @@ import "dotenv/config"
const env: IEnv = { const env: IEnv = {
prod: { prod: {
token: process.env.TOKEN, token: process.env.TOKEN!,
mongoURI: process.env.MONGOURI, mongoURI: process.env.MONGOURI!,
dev: process.env.DEV, dev: process.env.DEV!,
hypixelapikey: process.env.HYPIXELAPIKEY, hypixelapikey: process.env.HYPIXELAPIKEY!,
redisURI: process.env.REDISURI, redisURI: process.env.REDISURI!,
postgresURI: process.env.POSTGRESURI postgresURI: process.env.POSTGRESURI!
}, },
dev: { dev: {
devtoken: process.env.DEVTOKEN, devtoken: process.env.DEVTOKEN!,
clientid: process.env.CLIENTID, clientid: process.env.CLIENTID!,
devid: process.env.DEVID, devid: process.env.DEVID!,
guildid: process.env.GUILDID, guildid: process.env.GUILDID!
} }
} }

View File

@@ -9,7 +9,7 @@ import { Sequelize } from "sequelize"
import { YoutubeiExtractor } from "discord-player-youtubei" import { YoutubeiExtractor } from "discord-player-youtubei"
const client = new Client() const client = new Client()
const redis = new Redis(env.prod.redisURI!) const redis = new Redis(env.prod.redisURI)
const player = new Player(client) const player = new Player(client)
let sequelize: Sequelize let sequelize: Sequelize
@@ -19,7 +19,7 @@ if (process.env.NODE_ENV === "dev") {
storage: "data/db.sqlite" storage: "data/db.sqlite"
}) })
} else { } else {
sequelize = new Sequelize(env.prod.postgresURI!, { dialect: "postgres" }) sequelize = new Sequelize(env.prod.postgresURI, { dialect: "postgres" })
} }
let ft: "js" | "ts" let ft: "js" | "ts"
@@ -49,7 +49,7 @@ class Illegitimate {
console.log(color("Synced the db [dev]", "green")) console.log(color("Synced the db [dev]", "green"))
}) })
} }
// connect(env.prod.mongoURI!, {}).then(() => { // connect(env.prod.mongoURI, {}).then(() => {
// console.log(color("Connected to MongoDB", "green")) // console.log(color("Connected to MongoDB", "green"))
// }) // })
} }