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,9 +1,9 @@
import fs from "fs"
import { ExtendedClient } from "./Client"
import env from "./Env"
import { ExtendedClient } from "./Client.js"
import env from "./Env.js"
import { ICommand } from "interfaces"
import { RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js"
import color from "./functions/colors"
import color from "./functions/colors.js"
type FileType = "js" | "ts"
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
@@ -20,7 +20,9 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
}
for (const file of commandFiles) {
const command: ICommand = require(`../commands/${file}`)
// const command: ICommand = require(`../commands/${file}`)
const { default: commandImport } = await import(`../commands/${file}`)
const command: ICommand = commandImport
if (command.dev) {
commands.push(command.data.toJSON())
}

View File

@@ -1,8 +1,8 @@
import { Client, Collection, GatewayIntentBits, Partials } from "discord.js"
import color from "./functions/colors"
import color from "./functions/colors.js"
import { ICommand, IContextMenu, IButton, IModal, IAutocomplete } from "interfaces"
import env from "./Env"
import autoDeployCommands from "./Autodeploy"
import env from "./Env.js"
import autoDeployCommands from "./Autodeploy.js"
export class ExtendedClient extends Client {
commands: Collection<string, ICommand> = new Collection()

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 => {

6
src/utils/Hypixel.ts Normal file
View File

@@ -0,0 +1,6 @@
export { skywarsLevel } from "./HypixelFunctions/skywars.js"
export { bedwarsLevel } from "./HypixelFunctions/bedwars.js"
export { hypixelLevel } from "./HypixelFunctions/main.js"
export { formatUuid } from "./HypixelFunctions/uuid.js"
export { guildLevel, scaledGEXP } from "./HypixelFunctions/guild.js"
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL } from "./HypixelFunctions/account.js"

View File

@@ -1,6 +0,0 @@
export { skywarsLevel } from "./skywars"
export { bedwarsLevel } from "./bedwars"
export { hypixelLevel } from "./hypixel"
export { formatUuid } from "./uuid"
export { guildLevel, scaledGEXP } from "./guild"
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL } from "./account"

View File

@@ -1,5 +1,5 @@
import fetch from "axios"
import env from "utils/Env"
import env from "utils/Env.js"
import { IPlayer, IPlayerData } from "interfaces"
import { IGuild, IGuildData } from "interfaces"
const apikey = env.prod.hypixelapikey

View File

@@ -1,9 +1,9 @@
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 { Redis } from "ioredis"
import env from "utils/Env"
import env from "utils/Env.js"
// import { connect } from "mongoose"
import loadAllEvents from "./Events"
import loadAllEvents from "./Events/loadevents.js"
import { Player } from "discord-player"
import { Sequelize } from "sequelize"
@@ -31,7 +31,7 @@ if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
class Illegitimate {
async start() {
await this.init()
loadAllEvents(client, ft)
await loadAllEvents(client, ft)
await player.extractors.loadDefault()
await client.start()
await this.databases()

View File

@@ -1,6 +1,6 @@
import { embedColor } from "config/options"
import { embedColor } from "config/options.js"
import { Collection, EmbedBuilder, GuildMember, Message } from "discord.js"
import { getUUID } from "utils/Hypixel"
import { getUUID } from "utils/Hypixel.js"
const tooLong = new EmbedBuilder()
.setDescription("You took too long to respond.")

View File

@@ -6,9 +6,9 @@ import {
errorLogChannel,
moderationLogChannel,
devLogChannel
} from "config/options"
} from "config/options.js"
import { Guild, MessageCreateOptions, TextChannel } from "discord.js"
import { client } from "utils/Illegitimate"
import { client } from "utils/Illegitimate.js"
const channels = {
online: onlineLogChannel,

View File

@@ -9,7 +9,7 @@ import {
guildRole,
defaultMember,
verifyTick
} from "config/roles"
} from "config/roles.js"
const roles = [
gm,
manager,