Moved to bun
This commit is contained in:
@@ -33,6 +33,7 @@ export const topSub = new SlashCommandSubcommandBuilder()
|
||||
|
||||
const cmd: SubCommand = async ({ interaction }) => {
|
||||
await interaction.deferReply()
|
||||
await redis.connect()
|
||||
|
||||
const query = interaction.options.getString("query")!
|
||||
const type = interaction.options.getString("type") || "ign"
|
||||
@@ -227,6 +228,7 @@ const cmd: SubCommand = async ({ interaction }) => {
|
||||
|
||||
const cacheStatusText = cacheStatus ? " | [Cache]" : ""
|
||||
|
||||
await redis.close()
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
title: "Top members of " + guildName,
|
||||
|
||||
@@ -4,21 +4,13 @@ import { ICommand, IContextMenu } from "~/typings"
|
||||
import { ExtendedClient } from "./Client"
|
||||
import env from "./Env"
|
||||
import { log } from "./Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
|
||||
export default async function autoDeployCommands(client: ExtendedClient) {
|
||||
type CommandsType = RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody
|
||||
const commands: CommandsType[] = []
|
||||
let commandFiles: string[] = []
|
||||
let contentMenuCommands: string[] = []
|
||||
|
||||
if (fileType === "js") {
|
||||
commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType))
|
||||
contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||
} else if (fileType === "ts") {
|
||||
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
|
||||
contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||
}
|
||||
const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".ts"))
|
||||
const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const { default: command } = await import(`../commands/${file}`) as { default: ICommand }
|
||||
|
||||
@@ -32,14 +32,10 @@ export class ExtendedClient extends Client {
|
||||
|
||||
async start() {
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
||||
log.custom("Running in development mode. [tsx]", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.DEVTOKEN
|
||||
autoDeployCommands("ts", this)
|
||||
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
|
||||
if (process.env.NODE_ENV === "dev") {
|
||||
log.custom("Running in development mode.", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.DEVTOKEN
|
||||
autoDeployCommands("js", this)
|
||||
autoDeployCommands(this)
|
||||
} else {
|
||||
log.custom("Running in production mode.", "info", { type: "preset", color: "green" })
|
||||
token = env.prod.TOKEN
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import logToChannel from "~/utils/Functions/logtochannel"
|
||||
import tryCatch from "../Functions/trycatch"
|
||||
import { log } from "../Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadAutocompleteEvents(client: Client, ft: FileType) {
|
||||
export default async function loadAutocompleteEvents(client: Client) {
|
||||
const autocompletePath = path.join(import.meta.dirname, "..", "..", "components", "autocomplete")
|
||||
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft))
|
||||
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of autocompleteFiles) {
|
||||
const filePath = path.join(autocompletePath, file)
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import logToChannel from "~/utils/Functions/logtochannel"
|
||||
import tryCatch from "../Functions/trycatch"
|
||||
import { log } from "../Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadButtonEvents(client: Client, ft: FileType) {
|
||||
export default async function loadButtonEvents(client: Client) {
|
||||
const btnPath = path.join(import.meta.dirname, "..", "..", "components", "buttons")
|
||||
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(ft))
|
||||
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of btnFiles) {
|
||||
const filePath = path.join(btnPath, file)
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import logToChannel from "~/utils/Functions/logtochannel"
|
||||
import tryCatch from "../Functions/trycatch"
|
||||
import { log } from "../Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadSlashCommandsEvents(client: Client, ft: FileType) {
|
||||
export default async function loadSlashCommandsEvents(client: Client) {
|
||||
const cmdPath = path.join(import.meta.dirname, "..", "..", "commands")
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(ft))
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of cmdFiles) {
|
||||
const filePath = path.join(cmdPath, file)
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import logToChannel from "~/utils/Functions/logtochannel"
|
||||
import tryCatch from "../Functions/trycatch"
|
||||
import { log } from "../Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadContextMenuEvents(client: Client, ft: FileType) {
|
||||
export default async function loadContextMenuEvents(client: Client) {
|
||||
const contextMenuPath = path.join(import.meta.dirname, "..", "..", "commands-contextmenu")
|
||||
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft))
|
||||
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of contextMenuFiles) {
|
||||
const filePath = path.join(contextMenuPath, file)
|
||||
|
||||
@@ -2,11 +2,10 @@ import { CronJob } from "cron"
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { ICron } from "~/typings"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadCronEvents(ft: FileType) {
|
||||
export default async function loadCronEvents() {
|
||||
const cronPath = path.join(import.meta.dirname, "..", "..", "events", "cron")
|
||||
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(ft))
|
||||
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of cronFiles) {
|
||||
const filePath = path.join(cronPath, file)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { ExtendedClient as Client } from "~/utils/Client"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadEvents(client: Client, ft: FileType) {
|
||||
export default async function loadEvents(client: Client) {
|
||||
const serverDir = path.join(import.meta.dirname, "..", "..", "events", "server")
|
||||
const eventDirs = fs.readdirSync(serverDir)
|
||||
for (const eventDir of eventDirs) {
|
||||
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir)).filter(file => file.endsWith(ft))
|
||||
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir)).filter(file => file.endsWith(".ts"))
|
||||
const eventName = eventDir
|
||||
for (const eventFile of eventFiles) {
|
||||
const eventPath = path.join(serverDir, eventDir, eventFile)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { ExtendedClient } from "../Client"
|
||||
import { log } from "../Logger"
|
||||
import loadAutocompleteEvents from "./autocomplete"
|
||||
import loadButtonEvents from "./button"
|
||||
@@ -8,12 +8,12 @@ import loadCronEvents from "./cron"
|
||||
import loadEvents from "./events"
|
||||
import loadModalEvents from "./modal"
|
||||
|
||||
export default async function loadAllEvents(client: Client, ft: "js" | "ts") {
|
||||
await loadEvents(client, ft).then(() => log.info("Events loaded"))
|
||||
await loadButtonEvents(client, ft).then(() => log.info("Button events loaded"))
|
||||
await loadSlashCommandsEvents(client, ft).then(() => log.info("Slash commands loaded"))
|
||||
await loadContextMenuEvents(client, ft).then(() => log.info("Context menu events loaded"))
|
||||
await loadModalEvents(client, ft).then(() => log.info("Modal events loaded"))
|
||||
await loadAutocompleteEvents(client, ft).then(() => log.info("Autocomplete events loaded"))
|
||||
await loadCronEvents(ft).then(() => log.info("Cron events loaded"))
|
||||
export default async function loadAllEvents(client: ExtendedClient) {
|
||||
await loadEvents(client).then(() => log.info("Events loaded"))
|
||||
await loadButtonEvents(client).then(() => log.info("Button events loaded"))
|
||||
await loadSlashCommandsEvents(client).then(() => log.info("Slash commands loaded"))
|
||||
await loadContextMenuEvents(client).then(() => log.info("Context menu events loaded"))
|
||||
await loadModalEvents(client).then(() => log.info("Modal events loaded"))
|
||||
await loadAutocompleteEvents(client).then(() => log.info("Autocomplete events loaded"))
|
||||
await loadCronEvents().then(() => log.info("Cron events loaded"))
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import logToChannel from "~/utils/Functions/logtochannel"
|
||||
import tryCatch from "../Functions/trycatch"
|
||||
import { log } from "../Logger"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function loadModalEvents(client: Client, ft: FileType) {
|
||||
export default async function loadModalEvents(client: Client) {
|
||||
const modalPath = path.join(import.meta.dirname, "..", "..", "components", "modals")
|
||||
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft))
|
||||
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(".ts"))
|
||||
|
||||
for (const file of modalFiles) {
|
||||
const filePath = path.join(modalPath, file)
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
import { Redis } from "ioredis"
|
||||
import { RedisClient } from "bun"
|
||||
import { ExtendedClient as Client } from "~/utils/Client"
|
||||
import env from "~/utils/Env"
|
||||
import env from "./Env"
|
||||
import loadAllEvents from "./Events/loadevents"
|
||||
import { log } from "./Logger"
|
||||
|
||||
const client = new Client()
|
||||
const redis = new Redis(env.prod.REDISURI)
|
||||
|
||||
let ft: "js" | "ts"
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
||||
ft = "ts"
|
||||
} else {
|
||||
ft = "js"
|
||||
}
|
||||
const redis = new RedisClient(env.prod.REDISURI)
|
||||
|
||||
class Illegitimate {
|
||||
async start() {
|
||||
await loadAllEvents(client, ft)
|
||||
await loadAllEvents(client)
|
||||
await client.start()
|
||||
await this.databases()
|
||||
this.loadMethods()
|
||||
}
|
||||
|
||||
private async databases() {
|
||||
redis.on("ready", () => {
|
||||
redis.connect().then(() => {
|
||||
log.custom("Connected to Redis", "info", { type: "preset", color: "green" })
|
||||
}).catch(() => {
|
||||
log.error("Failed to connect to Redis")
|
||||
}).finally(() => {
|
||||
redis.close()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user