Moved to esm

Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
2024-08-23 17:59:00 +02:00
parent 31b88396ea
commit 3f7f23d4b3
123 changed files with 575 additions and 510 deletions

View File

@@ -1,20 +1,22 @@
import { ExtendedClient as Client } from "utils/Client"
import { embedColor } from "config/options"
import { ExtendedClient as Client } from "utils/Client.js"
import { embedColor } from "config/options.js"
import { IAutocomplete } from "interfaces"
import { Events } from "discord.js"
import color from "utils/functions/colors"
import color from "utils/functions/colors.js"
import path from "path"
import fs from "fs"
import logToChannel from "utils/functions/logtochannel"
import logToChannel from "utils/functions/logtochannel.js"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default function loadAutocompleteEvents(client: Client, ft: FileType) {
export default async function loadAutocompleteEvents(client: Client, ft: FileType) {
const autocompletePath = path.join(__dirname, "..", "..", "components", "autocomplete")
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft))
for (const file of autocompleteFiles) {
const filePath = path.join(autocompletePath, file)
const autocomplete: IAutocomplete = require(filePath)
const { default: autocompleteImport } = await import("file://" + filePath)
const autocomplete: IAutocomplete = autocompleteImport
if ("name" in autocomplete && "execute" in autocomplete) {
client.autocomplete.set(autocomplete.name, autocomplete)
@@ -26,7 +28,6 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) {
)
)
}
delete require.cache[require.resolve(filePath)]
}
client.on(Events.InteractionCreate, async interaction => {

View File

@@ -1,20 +1,22 @@
import { ExtendedClient as Client } from "utils/Client"
import color from "utils/functions/colors"
import { embedColor } from "config/options"
import { ExtendedClient as Client } from "utils/Client.js"
import color from "utils/functions/colors.js"
import { embedColor } from "config/options.js"
import { IButton } from "interfaces"
import { Events } from "discord.js"
import path from "path"
import fs from "fs"
import logToChannel from "utils/functions/logtochannel"
import logToChannel from "utils/functions/logtochannel.js"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default function loadButtonEvents(client: Client, ft: FileType) {
export default async function loadButtonEvents(client: Client, ft: FileType) {
const btnPath = path.join(__dirname, "..", "..", "components", "buttons")
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(ft))
for (const file of btnFiles) {
const filePath = path.join(btnPath, file)
const btn: IButton = require(filePath)
const { default: btnImport } = await import("file://" + filePath)
const btn: IButton = btnImport
if ("name" in btn && "execute" in btn) {
client.buttons.set(btn.name, btn)
@@ -26,7 +28,6 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
)
)
}
delete require.cache[require.resolve(filePath)]
}
client.on(Events.InteractionCreate, async interaction => {

View File

@@ -1,20 +1,22 @@
import { ExtendedClient as Client } from "utils/Client"
import color from "utils/functions/colors"
import { embedColor } from "config/options"
import { ExtendedClient as Client } from "utils/Client.js"
import color from "utils/functions/colors.js"
import { embedColor } from "config/options.js"
import { ICommand } from "interfaces"
import { Events } from "discord.js"
import path from "path"
import fs from "fs"
import logToChannel from "utils/functions/logtochannel"
import logToChannel from "utils/functions/logtochannel.js"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
export default async function loadSlashCommandsEvents(client: Client, ft: FileType) {
const cmdPath = path.join(__dirname, "..", "..", "commands")
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(ft))
for (const file of cmdFiles) {
const filePath = path.join(cmdPath, file)
const cmd: ICommand = require(filePath)
const { default: cmdImport } = await import("file://" + filePath)
const cmd: ICommand = cmdImport
if ("data" in cmd && "execute" in cmd) {
client.commands.set(cmd.data.name, cmd)
@@ -26,7 +28,6 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
)
)
}
delete require.cache[require.resolve(filePath)]
}
//! command handler

View File

@@ -1,20 +1,22 @@
import { ExtendedClient as Client } from "utils/Client"
import color from "utils/functions/colors"
import { ExtendedClient as Client } from "utils/Client.js"
import color from "utils/functions/colors.js"
import { IContextMenu } from "interfaces"
import { embedColor } from "config/options"
import { embedColor } from "config/options.js"
import { Events } from "discord.js"
import path from "path"
import fs from "fs"
import logToChannel from "utils/functions/logtochannel"
import logToChannel from "utils/functions/logtochannel.js"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default function loadContextMenuEvents(client: Client, ft: FileType) {
export default async function loadContextMenuEvents(client: Client, ft: FileType) {
const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu")
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft))
for (const file of contextMenuFiles) {
const filePath = path.join(contextMenuPath, file)
const cmd: IContextMenu = require(filePath)
const { default: cmdImport } = await import("file://" + filePath)
const cmd: IContextMenu = cmdImport
if ("data" in cmd && "execute" in cmd) {
client.contextmenus.set(cmd.data.name, cmd)
@@ -26,7 +28,6 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
)
)
}
delete require.cache[require.resolve(filePath)]
}
//! context menu command handler

View File

@@ -2,14 +2,16 @@ import { CronJob } from "cron"
import path from "path"
import fs from "fs"
import { ICron } from "interfaces"
const __dirname = import.meta.dirname
export default function loadCronEvents() {
export default async function loadCronEvents() {
const cronPath = path.join(__dirname, "..", "..", "events", "cron")
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js"))
for (const file of cronFiles) {
const filePath = path.join(cronPath, file)
const cron: ICron = require(filePath)
const { default: cronImport } = await import("file://" + filePath)
const cron: ICron = cronImport
const time =
cron.time.seconds + " " +
@@ -20,6 +22,5 @@ export default function loadCronEvents() {
cron.time.dayOfWeek
new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start()
delete require.cache[require.resolve(filePath)]
}
}

View File

@@ -1,20 +1,21 @@
import { ExtendedClient as Client } from "utils/Client"
import { ExtendedClient as Client } from "utils/Client.js"
import { IEvent } from "interfaces"
import path from "path"
import fs from "fs"
const __dirname = import.meta.dirname
export default function loadEvents(client: Client) {
export default async function loadEvents(client: Client) {
const serverDir = path.join(__dirname, "..", "..", "events", "server")
const eventDirs = fs.readdirSync(serverDir)
for (const eventDir of eventDirs) {
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir))
for (const eventFile of eventFiles) {
const eventPath = path.join(serverDir, eventDir, eventFile)
const event: IEvent = require(eventPath)
const { default: eventImport } = await import("file://" + eventPath)
const event: IEvent = eventImport
if (!event.disabled) {
client.on(event.event, event.execute)
}
delete require.cache[require.resolve(eventPath)]
}
}
}

View File

@@ -1,18 +0,0 @@
import { ExtendedClient as Client } from "../Client"
import loadAutocompleteEvents from "./autocomplete"
import loadButtonEvents from "./button"
import loadSlashCommandsEvents from "./command"
import loadContextMenuEvents from "./contextmenu"
import loadCronEvents from "./cron"
import loadEvents from "./events"
import loadModalEvents from "./modal"
export default function loadAllEvents(client: Client, ft: "js" | "ts") {
loadEvents(client)
loadButtonEvents(client, ft)
loadSlashCommandsEvents(client, ft)
loadContextMenuEvents(client, ft)
loadModalEvents(client, ft)
loadAutocompleteEvents(client, ft)
loadCronEvents()
}

View File

@@ -0,0 +1,18 @@
import { ExtendedClient as Client } from "../Client.js"
import loadAutocompleteEvents from "./autocomplete.js"
import loadButtonEvents from "./button.js"
import loadSlashCommandsEvents from "./command.js"
import loadContextMenuEvents from "./contextmenu.js"
import loadCronEvents from "./cron.js"
import loadEvents from "./events.js"
import loadModalEvents from "./modal.js"
export default async function loadAllEvents(client: Client, ft: "js" | "ts") {
await loadEvents(client)
await loadButtonEvents(client, ft)
await loadSlashCommandsEvents(client, ft)
await loadContextMenuEvents(client, ft)
await loadModalEvents(client, ft)
await loadAutocompleteEvents(client, ft)
await loadCronEvents()
}

View File

@@ -1,20 +1,22 @@
import { ExtendedClient as Client } from "utils/Client"
import color from "utils/functions/colors"
import { embedColor } from "config/options"
import { ExtendedClient as Client } from "utils/Client.js"
import color from "utils/functions/colors.js"
import { embedColor } from "config/options.js"
import { IModal } from "interfaces"
import { Events } from "discord.js"
import path from "path"
import fs from "fs"
import logToChannel from "utils/functions/logtochannel"
import logToChannel from "utils/functions/logtochannel.js"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default function loadModalEvents(client: Client, ft: FileType) {
export default async function loadModalEvents(client: Client, ft: FileType) {
const modalPath = path.join(__dirname, "..", "..", "components", "modals")
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft))
for (const file of modalFiles) {
const filePath = path.join(modalPath, file)
const modal: IModal = require(filePath)
const { default: modalImport } = await import("file://" + filePath)
const modal: IModal = modalImport
if ("name" in modal && "execute" in modal) {
client.modals.set(modal.name, modal)
@@ -26,7 +28,6 @@ export default function loadModalEvents(client: Client, ft: FileType) {
)
)
}
delete require.cache[require.resolve(filePath)]
}
client.on(Events.InteractionCreate, async interaction => {