commandkit 0.1.11-dev.20250104131827 → 0.1.11-dev.20250111094526
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build.mjs +3 -0
- package/bin/development.mjs +1 -0
- package/dist/{CommandKit-8KZkBcWO.d.ts → CommandKit-DW5Fy2uM.d.ts} +28 -1
- package/dist/{CommandKit-eNQRmrvH.d.mts → CommandKit-oiAWcISu.d.mts} +28 -1
- package/dist/CommandKit.d.mts +3 -1
- package/dist/CommandKit.d.ts +3 -1
- package/dist/CommandKit.js +2 -2
- package/dist/CommandKit.js.map +1 -1
- package/dist/CommandKit.mjs +1 -1
- package/dist/async-context-B85N7tuZ.d.ts +156 -0
- package/dist/async-context-C45rxdEH.d.mts +156 -0
- package/dist/cache/CacheProvider.d.mts +9 -0
- package/dist/cache/CacheProvider.d.ts +9 -0
- package/dist/cache/CacheProvider.js +2 -0
- package/dist/cache/CacheProvider.js.map +1 -0
- package/dist/cache/CacheProvider.mjs +2 -0
- package/dist/cache/MemoryCache.d.mts +17 -0
- package/dist/cache/MemoryCache.d.ts +17 -0
- package/dist/cache/MemoryCache.js +2 -0
- package/dist/cache/MemoryCache.js.map +1 -0
- package/dist/cache/MemoryCache.mjs +2 -0
- package/dist/cache/MemoryCache.mjs.map +1 -0
- package/dist/cache/index.d.mts +26 -0
- package/dist/cache/index.d.ts +26 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/index.mjs +2 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/{chunk-J3ZMR7KK.mjs → chunk-3ENTJANI.mjs} +2 -2
- package/dist/chunk-4BV475NY.mjs +2 -0
- package/dist/chunk-4BV475NY.mjs.map +1 -0
- package/dist/{chunk-D7RDGUPK.mjs → chunk-4CG7S6RY.mjs} +2 -2
- package/dist/{chunk-UXQFRVAB.mjs → chunk-6AX5YJEO.mjs} +2 -2
- package/dist/{chunk-JFCJXIOI.mjs → chunk-6BSP7AD3.mjs} +2 -2
- package/dist/{chunk-E2KEPOOS.mjs → chunk-6IFRWFZE.mjs} +2 -2
- package/dist/{chunk-7KD7ZCH6.mjs → chunk-6TIBWNPX.mjs} +1 -1
- package/dist/chunk-6TIBWNPX.mjs.map +1 -0
- package/dist/chunk-6TIGKCSX.mjs +2 -0
- package/dist/{chunk-GS3Q7VW7.mjs → chunk-6W2KY7FK.mjs} +2 -2
- package/dist/chunk-C6WU57FQ.mjs +2 -0
- package/dist/{chunk-ZE7AC2HG.mjs.map → chunk-C6WU57FQ.mjs.map} +1 -1
- package/dist/{chunk-YSVQ45EN.mjs → chunk-DW5KRS5H.mjs} +2 -2
- package/dist/chunk-GOXZZ7GU.mjs +2 -0
- package/dist/chunk-GOXZZ7GU.mjs.map +1 -0
- package/dist/{chunk-SFWUUQXC.mjs → chunk-K43A7OIY.mjs} +2 -2
- package/dist/chunk-LTI3V2K4.mjs +2 -0
- package/dist/chunk-LTI3V2K4.mjs.map +1 -0
- package/dist/chunk-M2MFP4HH.mjs +2 -0
- package/dist/chunk-M2MFP4HH.mjs.map +1 -0
- package/dist/chunk-MVPNDXHU.mjs +2 -0
- package/dist/chunk-MVPNDXHU.mjs.map +1 -0
- package/dist/chunk-UOPZOWKS.mjs +2 -0
- package/dist/chunk-UOPZOWKS.mjs.map +1 -0
- package/dist/chunk-VRGHCTCP.mjs +2 -0
- package/dist/chunk-VRGHCTCP.mjs.map +1 -0
- package/dist/{chunk-4IWEG3WI.mjs → chunk-WNEBLBID.mjs} +2 -2
- package/dist/{chunk-4IWEG3WI.mjs.map → chunk-WNEBLBID.mjs.map} +1 -1
- package/dist/chunk-XHS5CRG6.mjs +2 -0
- package/dist/chunk-XHS5CRG6.mjs.map +1 -0
- package/dist/{chunk-I2MRY4KL.mjs → chunk-XJCWZEWC.mjs} +2 -2
- package/dist/chunk-YTD7MZPP.mjs +2 -0
- package/dist/chunk-YTD7MZPP.mjs.map +1 -0
- package/dist/{chunk-4U6VHAPY.mjs → chunk-Z4FBPRS6.mjs} +2 -2
- package/dist/components/ButtonKit.js +1 -1
- package/dist/components/ButtonKit.js.map +1 -1
- package/dist/components/ButtonKit.mjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/context/async-context.d.mts +7 -0
- package/dist/context/async-context.d.ts +7 -0
- package/dist/context/async-context.js +2 -0
- package/dist/context/async-context.js.map +1 -0
- package/dist/context/async-context.mjs +2 -0
- package/dist/context/async-context.mjs.map +1 -0
- package/dist/context/environment.d.mts +7 -0
- package/dist/context/environment.d.ts +7 -0
- package/dist/context/environment.js +2 -0
- package/dist/context/environment.js.map +1 -0
- package/dist/context/environment.mjs +2 -0
- package/dist/context/environment.mjs.map +1 -0
- package/dist/handlers/command-handler/CommandHandler.d.mts +3 -1
- package/dist/handlers/command-handler/CommandHandler.d.ts +3 -1
- package/dist/handlers/command-handler/CommandHandler.js +2 -2
- package/dist/handlers/command-handler/CommandHandler.js.map +1 -1
- package/dist/handlers/command-handler/CommandHandler.mjs +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.mts +3 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.ts +3 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js.map +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.d.mts +3 -1
- package/dist/handlers/command-handler/functions/registerCommands.d.ts +3 -1
- package/dist/handlers/command-handler/functions/registerCommands.js +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.js.map +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.mjs +1 -1
- package/dist/handlers/command-handler/typings.d.mts +3 -1
- package/dist/handlers/command-handler/typings.d.ts +3 -1
- package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs +1 -1
- package/dist/handlers/command-handler/validations/devOnly.d.mts +3 -1
- package/dist/handlers/command-handler/validations/devOnly.d.ts +3 -1
- package/dist/handlers/command-handler/validations/devOnly.mjs +1 -1
- package/dist/handlers/command-handler/validations/index.d.mts +3 -1
- package/dist/handlers/command-handler/validations/index.d.ts +3 -1
- package/dist/handlers/command-handler/validations/index.mjs +1 -1
- package/dist/handlers/command-handler/validations/permissions.d.mts +3 -1
- package/dist/handlers/command-handler/validations/permissions.d.ts +3 -1
- package/dist/handlers/command-handler/validations/permissions.mjs +1 -1
- package/dist/handlers/event-handler/EventHandler.d.mts +3 -1
- package/dist/handlers/event-handler/EventHandler.d.ts +3 -1
- package/dist/handlers/event-handler/EventHandler.js +1 -1
- package/dist/handlers/event-handler/EventHandler.js.map +1 -1
- package/dist/handlers/event-handler/EventHandler.mjs +1 -1
- package/dist/handlers/event-handler/typings.d.mts +3 -1
- package/dist/handlers/event-handler/typings.d.ts +3 -1
- package/dist/handlers/index.d.mts +3 -1
- package/dist/handlers/index.d.ts +3 -1
- package/dist/handlers/index.js +2 -2
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/index.mjs +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js.map +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.mjs +1 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +3 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/clone.mjs +1 -1
- package/dist/utils/colors.js +1 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/colors.mjs +1 -1
- package/dist/utils/error-codes.d.mts +10 -0
- package/dist/utils/error-codes.d.ts +10 -0
- package/dist/utils/error-codes.js +2 -0
- package/dist/utils/error-codes.js.map +1 -0
- package/dist/utils/error-codes.mjs +2 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/get-paths.mjs +1 -1
- package/dist/utils/resolve-file-url.mjs +1 -1
- package/dist/utils/warn-unstable.d.mts +3 -0
- package/dist/utils/warn-unstable.d.ts +3 -0
- package/dist/utils/warn-unstable.js +2 -0
- package/dist/utils/warn-unstable.js.map +1 -0
- package/dist/utils/warn-unstable.mjs +2 -0
- package/dist/utils/warn-unstable.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-FXJNQE5B.mjs +0 -2
- package/dist/chunk-FXJNQE5B.mjs.map +0 -1
- package/dist/chunk-IHC5YX2R.mjs +0 -2
- package/dist/chunk-IHC5YX2R.mjs.map +0 -1
- package/dist/chunk-YZT2CEWE.mjs +0 -2
- package/dist/chunk-ZE7AC2HG.mjs +0 -2
- /package/dist/{chunk-7KD7ZCH6.mjs.map → cache/CacheProvider.mjs.map} +0 -0
- /package/dist/{chunk-J3ZMR7KK.mjs.map → chunk-3ENTJANI.mjs.map} +0 -0
- /package/dist/{chunk-D7RDGUPK.mjs.map → chunk-4CG7S6RY.mjs.map} +0 -0
- /package/dist/{chunk-UXQFRVAB.mjs.map → chunk-6AX5YJEO.mjs.map} +0 -0
- /package/dist/{chunk-JFCJXIOI.mjs.map → chunk-6BSP7AD3.mjs.map} +0 -0
- /package/dist/{chunk-E2KEPOOS.mjs.map → chunk-6IFRWFZE.mjs.map} +0 -0
- /package/dist/{chunk-YZT2CEWE.mjs.map → chunk-6TIGKCSX.mjs.map} +0 -0
- /package/dist/{chunk-GS3Q7VW7.mjs.map → chunk-6W2KY7FK.mjs.map} +0 -0
- /package/dist/{chunk-YSVQ45EN.mjs.map → chunk-DW5KRS5H.mjs.map} +0 -0
- /package/dist/{chunk-SFWUUQXC.mjs.map → chunk-K43A7OIY.mjs.map} +0 -0
- /package/dist/{chunk-I2MRY4KL.mjs.map → chunk-XJCWZEWC.mjs.map} +0 -0
- /package/dist/{chunk-4U6VHAPY.mjs.map → chunk-Z4FBPRS6.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/handlers/command-handler/functions/registerCommands.ts","../../../../src/handlers/command-handler/utils/areSlashCommandsDifferent.ts","../../../../src/utils/colors.ts"],"sourcesContent":["import type {\n Guild,\n Client,\n ApplicationCommandData,\n GuildApplicationCommandManager,\n ApplicationCommandDataResolvable } from\n'discord.js';\nimport type { CommandFileObject, ReloadOptions } from '../../../types';\n\nimport areSlashCommandsDifferent from '../utils/areSlashCommandsDifferent';\n\nimport colors from '../../../utils/colors';\n\ntype RegisterCommandProps = {\n client: Client;\n commands: CommandFileObject[];\n devGuildIds: string[];\n reloading?: boolean;\n type?: ReloadOptions;\n};\n\n/**\n * Register client commands to Discord.\n * @param props\n */\nexport default async function registerCommands(props: RegisterCommandProps) {\n if (props.reloading) {\n if (props.client.isReady()) {\n await handleRegistration(\n props.client,\n props.commands,\n props.devGuildIds,\n props.type\n );\n } else {\n throw new Error(\n colors.red(`Cannot reload commands when client is not ready.`)\n );\n }\n } else {\n props.client.once('ready', async (c) => {\n await handleRegistration(\n c,\n props.commands,\n props.devGuildIds,\n props.type\n );\n });\n }\n}\n\nasync function handleRegistration(\nclient: Client<true>,\ncommands: CommandFileObject[],\ndevGuildIds: string[],\ntype?: ReloadOptions)\n{\n const devOnlyCommands = commands.filter((cmd) => cmd.options?.devOnly);\n const globalCommands = commands.filter((cmd) => !cmd.options?.devOnly);\n\n if (type === 'dev') {\n await registerDevCommands(client, devOnlyCommands, devGuildIds);\n } else if (type === 'global') {\n await registerGlobalCommands(client, globalCommands);\n } else {\n await registerDevCommands(client, devOnlyCommands, devGuildIds);\n await registerGlobalCommands(client, globalCommands);\n }\n}\n\nasync function registerGlobalCommands(\nclient: Client<true>,\ncommands: CommandFileObject[])\n{\n const appCommandsManager = client.application.commands;\n await appCommandsManager.fetch();\n\n for (const command of commands) {\n const targetCommand = appCommandsManager.cache.find(\n (cmd) => cmd.name === command.data.name\n );\n\n // <!-- Delete global command -->\n if (command.options?.deleted) {\n if (!targetCommand) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Command \"${command.data.name}\" is globally marked as deleted.`\n )\n );\n } else {\n await targetCommand.delete().catch((error) => {\n throw new Error(\n colors.red(\n `Failed to delete command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Deleted command \"${command.data.name}\" globally.`)\n );\n }\n\n continue;\n }\n\n // <!-- Edit global command -->\n if (targetCommand) {\n const commandsAreDifferent = areSlashCommandsDifferent(\n targetCommand,\n command.data\n );\n\n if (commandsAreDifferent) {\n await targetCommand.\n edit(command.data as Partial<ApplicationCommandData>).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to edit command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Edited command \"${command.data.name}\" globally.`)\n );\n\n continue;\n }\n }\n\n // <!-- Register global command -->\n if (targetCommand) continue;\n\n await appCommandsManager.\n create(command.data as ApplicationCommandDataResolvable).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to register command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Registered command \"${command.data.name}\" globally.`)\n );\n }\n}\n\nasync function registerDevCommands(\nclient: Client<true>,\ncommands: CommandFileObject[],\nguildIds: string[])\n{\n const devGuilds: Guild[] = [];\n\n for (const guildId of guildIds) {\n const guild =\n client.guilds.cache.get(guildId) || (await client.guilds.fetch(guildId));\n\n if (!guild) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Guild ${guildId} doesn't exist or client isn't part of the guild.`\n )\n );\n continue;\n }\n\n devGuilds.push(guild);\n }\n\n const guildCommandsManagers: GuildApplicationCommandManager[] = [];\n\n for (const guild of devGuilds) {\n const guildCommandsManager = guild.commands;\n await guildCommandsManager.fetch();\n\n guildCommandsManagers.push(guildCommandsManager);\n }\n\n for (const command of commands) {\n for (const guildCommands of guildCommandsManagers) {\n const targetCommand = guildCommands.cache.find(\n (cmd) => cmd.name === command.data.name\n );\n\n // <!-- Delete dev command -->\n if (command.options?.deleted) {\n if (!targetCommand) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Command \"${command.data.name}\" is marked as deleted in ${guildCommands.guild.name}.`\n )\n );\n } else {\n await targetCommand.delete().catch((error) => {\n throw new Error(\n colors.red(\n `Failed to delete command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Deleted command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n }\n\n continue;\n }\n\n // <!-- Edit dev command -->\n if (targetCommand) {\n const commandsAreDifferent = areSlashCommandsDifferent(\n targetCommand,\n command.data\n );\n\n if (commandsAreDifferent) {\n await targetCommand.\n edit(command.data as Partial<ApplicationCommandData>).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to edit command \"${command.data.name}\" in ${guildCommands.guild.name}.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Edited command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n\n continue;\n }\n }\n\n // <!-- Register guild command -->\n if (targetCommand) continue;\n\n await guildCommands.\n create(command.data as ApplicationCommandDataResolvable).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to register command \"${command.data.name}\" in ${guildCommands.guild.name}.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Registered command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n }\n }\n}","/**\n * Test if two slash commands are different.\n * @param appCommand - The application command.\n * @param localCommand - The local command.\n * @returns A boolean indicating whether these commands are different\n */\nexport default function areSlashCommandsDifferent(\nappCommand: any,\nlocalCommand: any)\n{\n if (!appCommand.options) appCommand.options = [];\n if (!localCommand.options) localCommand.options = [];\n\n if (!appCommand.description) appCommand.description = '';\n if (!localCommand.description) localCommand.description = '';\n\n if (\n localCommand.description !== appCommand.description ||\n localCommand.options.length !== appCommand.options.length)\n {\n return true;\n }\n}","const resetColor = '\\x1b[0m';\n\nexport default {\n reset: (text: string) => `${text}${resetColor}`,\n bright: (text: string) => `\\x1b[1m${text}${resetColor}`,\n dim: (text: string) => `\\x1b[2m${text}${resetColor}`,\n underscore: (text: string) => `\\x1b[4m${text}${resetColor}`,\n blink: (text: string) => `\\x1b[5m${text}${resetColor}`,\n reverse: (text: string) => `\\x1b[7m${text}${resetColor}`,\n hidden: (text: string) => `\\x1b[8m${text}${resetColor}`,\n\n black: (text: string) => `\\x1b[30m${text}${resetColor}`,\n red: (text: string) => `\\x1b[31m${text}${resetColor}`,\n green: (text: string) => `\\x1b[32m${text}${resetColor}`,\n yellow: (text: string) => `\\x1b[33m${text}${resetColor}`,\n blue: (text: string) => `\\x1b[34m${text}${resetColor}`,\n magenta: (text: string) => `\\x1b[35m${text}${resetColor}`,\n cyan: (text: string) => `\\x1b[36m${text}${resetColor}`,\n white: (text: string) => `\\x1b[37m${text}${resetColor}`,\n\n bgBlack: (text: string) => `\\x1b[40m${text}${resetColor}`,\n bgRed: (text: string) => `\\x1b[41m${text}${resetColor}`,\n bgGreen: (text: string) => `\\x1b[42m${text}${resetColor}`,\n bgYellow: (text: string) => `\\x1b[43m${text}${resetColor}`,\n bgBlue: (text: string) => `\\x1b[44m${text}${resetColor}`,\n bgMagenta: (text: string) => `\\x1b[45m${text}${resetColor}`,\n bgCyan: (text: string) => `\\x1b[46m${text}${resetColor}`,\n bgWhite: (text: string) => `\\x1b[47m${text}${resetColor}`\n};"],"mappings":"ouBAAA,wJCMe,SAAR,0BACP,WACA,aACA,CAOE,GANK,WAAW,UAAS,WAAW,QAAU,CAAC,GAC1C,aAAa,UAAS,aAAa,QAAU,CAAC,GAE9C,WAAW,cAAa,WAAW,YAAc,IACjD,aAAa,cAAa,aAAa,YAAc,IAG1D,aAAa,cAAgB,WAAW,aACxC,aAAa,QAAQ,SAAW,WAAW,QAAQ,OAE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I,GAC9F,CACF,EAkBF,QACF,CAGA,GAAI,eAC2B,0BAC3B,cACA,QAAQ,IACV,EAE0B,CACxB,MAAM,cACN,KAAK,QAAQ,IAAuC,EACpD,MAAO,OAAU,CACf,MAAM,IAAI,MACR,eAAO,IACL,2BAA2B,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI;AAAA,CAC9E,EACA,KACF,CACF,CAAC,EAED,QAAQ,IACN,eAAO,MACL,mBAAmB,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI,GACtE,CACF,EAEA,QACF,CAIE,gBAEJ,MAAM,cACN,OAAO,QAAQ,IAAwC,EACvD,MAAO,OAAU,CACf,MAAM,IAAI,MACR,eAAO,IACL,+BAA+B,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI;AAAA,CAClF,EACA,KACF,CACF,CAAC,EAED,QAAQ,IACN,eAAO,MACL,uBAAuB,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI,GAC1E,CACF,EACF,CAEJ,CApHe","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/handlers/command-handler/functions/registerCommands.ts","../../../../src/handlers/command-handler/utils/areSlashCommandsDifferent.ts","../../../../src/utils/colors.ts"],"sourcesContent":["import type {\n Guild,\n Client,\n ApplicationCommandData,\n GuildApplicationCommandManager,\n ApplicationCommandDataResolvable } from\n'discord.js';\nimport type { CommandFileObject, ReloadOptions } from '../../../types';\n\nimport areSlashCommandsDifferent from '../utils/areSlashCommandsDifferent';\n\nimport colors from '../../../utils/colors';\n\ntype RegisterCommandProps = {\n client: Client;\n commands: CommandFileObject[];\n devGuildIds: string[];\n reloading?: boolean;\n type?: ReloadOptions;\n};\n\n/**\n * Register client commands to Discord.\n * @param props\n */\nexport default async function registerCommands(props: RegisterCommandProps) {\n if (props.reloading) {\n if (props.client.isReady()) {\n await handleRegistration(\n props.client,\n props.commands,\n props.devGuildIds,\n props.type\n );\n } else {\n throw new Error(\n colors.red(`Cannot reload commands when client is not ready.`)\n );\n }\n } else {\n props.client.once('ready', async (c) => {\n await handleRegistration(\n c,\n props.commands,\n props.devGuildIds,\n props.type\n );\n });\n }\n}\n\nasync function handleRegistration(\nclient: Client<true>,\ncommands: CommandFileObject[],\ndevGuildIds: string[],\ntype?: ReloadOptions)\n{\n const devOnlyCommands = commands.filter((cmd) => cmd.options?.devOnly);\n const globalCommands = commands.filter((cmd) => !cmd.options?.devOnly);\n\n if (type === 'dev') {\n await registerDevCommands(client, devOnlyCommands, devGuildIds);\n } else if (type === 'global') {\n await registerGlobalCommands(client, globalCommands);\n } else {\n await registerDevCommands(client, devOnlyCommands, devGuildIds);\n await registerGlobalCommands(client, globalCommands);\n }\n}\n\nasync function registerGlobalCommands(\nclient: Client<true>,\ncommands: CommandFileObject[])\n{\n const appCommandsManager = client.application.commands;\n await appCommandsManager.fetch();\n\n for (const command of commands) {\n const targetCommand = appCommandsManager.cache.find(\n (cmd) => cmd.name === command.data.name\n );\n\n // <!-- Delete global command -->\n if (command.options?.deleted) {\n if (!targetCommand) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Command \"${command.data.name}\" is globally marked as deleted.`\n )\n );\n } else {\n await targetCommand.delete().catch((error) => {\n throw new Error(\n colors.red(\n `Failed to delete command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Deleted command \"${command.data.name}\" globally.`)\n );\n }\n\n continue;\n }\n\n // <!-- Edit global command -->\n if (targetCommand) {\n const commandsAreDifferent = areSlashCommandsDifferent(\n targetCommand,\n command.data\n );\n\n if (commandsAreDifferent) {\n await targetCommand.\n edit(command.data as Partial<ApplicationCommandData>).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to edit command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Edited command \"${command.data.name}\" globally.`)\n );\n\n continue;\n }\n }\n\n // <!-- Register global command -->\n if (targetCommand) continue;\n\n await appCommandsManager.\n create(command.data as ApplicationCommandDataResolvable).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to register command \"${command.data.name}\" globally.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(`Registered command \"${command.data.name}\" globally.`)\n );\n }\n}\n\nasync function registerDevCommands(\nclient: Client<true>,\ncommands: CommandFileObject[],\nguildIds: string[])\n{\n const devGuilds: Guild[] = [];\n\n for (const guildId of guildIds) {\n const guild =\n client.guilds.cache.get(guildId) || (await client.guilds.fetch(guildId));\n\n if (!guild) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Guild ${guildId} doesn't exist or client isn't part of the guild.`\n )\n );\n continue;\n }\n\n devGuilds.push(guild);\n }\n\n const guildCommandsManagers: GuildApplicationCommandManager[] = [];\n\n for (const guild of devGuilds) {\n const guildCommandsManager = guild.commands;\n await guildCommandsManager.fetch();\n\n guildCommandsManagers.push(guildCommandsManager);\n }\n\n for (const command of commands) {\n for (const guildCommands of guildCommandsManagers) {\n const targetCommand = guildCommands.cache.find(\n (cmd) => cmd.name === command.data.name\n );\n\n // <!-- Delete dev command -->\n if (command.options?.deleted) {\n if (!targetCommand) {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Command \"${command.data.name}\" is marked as deleted in ${guildCommands.guild.name}.`\n )\n );\n } else {\n await targetCommand.delete().catch((error) => {\n throw new Error(\n colors.red(\n `Failed to delete command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Deleted command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n }\n\n continue;\n }\n\n // <!-- Edit dev command -->\n if (targetCommand) {\n const commandsAreDifferent = areSlashCommandsDifferent(\n targetCommand,\n command.data\n );\n\n if (commandsAreDifferent) {\n await targetCommand.\n edit(command.data as Partial<ApplicationCommandData>).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to edit command \"${command.data.name}\" in ${guildCommands.guild.name}.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Edited command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n\n continue;\n }\n }\n\n // <!-- Register guild command -->\n if (targetCommand) continue;\n\n await guildCommands.\n create(command.data as ApplicationCommandDataResolvable).\n catch((error) => {\n throw new Error(\n colors.red(\n `Failed to register command \"${command.data.name}\" in ${guildCommands.guild.name}.\\n`\n ),\n error\n );\n });\n\n console.log(\n colors.green(\n `Registered command \"${command.data.name}\" in ${guildCommands.guild.name}.`\n )\n );\n }\n }\n}","/**\n * Test if two slash commands are different.\n * @param appCommand - The application command.\n * @param localCommand - The local command.\n * @returns A boolean indicating whether these commands are different\n */\nexport default function areSlashCommandsDifferent(\nappCommand: any,\nlocalCommand: any)\n{\n if (!appCommand.options) appCommand.options = [];\n if (!localCommand.options) localCommand.options = [];\n\n if (!appCommand.description) appCommand.description = '';\n if (!localCommand.description) localCommand.description = '';\n\n if (\n localCommand.description !== appCommand.description ||\n localCommand.options.length !== appCommand.options.length)\n {\n return true;\n }\n}","const resetColor = '\\x1b[0m';\n\nexport default {\n reset: (text: string) => `${text}${resetColor}`,\n bright: (text: string) => `\\x1b[1m${text}${resetColor}`,\n dim: (text: string) => `\\x1b[2m${text}${resetColor}`,\n underscore: (text: string) => `\\x1b[4m${text}${resetColor}`,\n blink: (text: string) => `\\x1b[5m${text}${resetColor}`,\n reverse: (text: string) => `\\x1b[7m${text}${resetColor}`,\n hidden: (text: string) => `\\x1b[8m${text}${resetColor}`,\n\n black: (text: string) => `\\x1b[30m${text}${resetColor}`,\n red: (text: string) => `\\x1b[31m${text}${resetColor}`,\n green: (text: string) => `\\x1b[32m${text}${resetColor}`,\n yellow: (text: string) => `\\x1b[33m${text}${resetColor}`,\n blue: (text: string) => `\\x1b[34m${text}${resetColor}`,\n magenta: (text: string) => `\\x1b[35m${text}${resetColor}`,\n cyan: (text: string) => `\\x1b[36m${text}${resetColor}`,\n white: (text: string) => `\\x1b[37m${text}${resetColor}`,\n\n bgBlack: (text: string) => `\\x1b[40m${text}${resetColor}`,\n bgRed: (text: string) => `\\x1b[41m${text}${resetColor}`,\n bgGreen: (text: string) => `\\x1b[42m${text}${resetColor}`,\n bgYellow: (text: string) => `\\x1b[43m${text}${resetColor}`,\n bgBlue: (text: string) => `\\x1b[44m${text}${resetColor}`,\n bgMagenta: (text: string) => `\\x1b[45m${text}${resetColor}`,\n bgCyan: (text: string) => `\\x1b[46m${text}${resetColor}`,\n bgWhite: (text: string) => `\\x1b[47m${text}${resetColor}`\n};"],"mappings":"ouBAAA,wJCMe,SAAR,0BACP,WACA,aACA,CAOE,GANK,WAAW,UAAS,WAAW,QAAU,CAAC,GAC1C,aAAa,UAAS,aAAa,QAAU,CAAC,GAE9C,WAAW,cAAa,WAAW,YAAc,IACjD,aAAa,cAAa,aAAa,YAAc,IAG1D,aAAa,cAAgB,WAAW,aACxC,aAAa,QAAQ,SAAW,WAAW,QAAQ,OAEjD,MAAO,EAEX,CAhBwB,8DCNxB,IAAM,WAAa,UAEZ,eAAQ,CACb,MAAO,OAAC,MAAiB,GAAG,IAAI,GAAG,UAAU,GAAtC,SACP,OAAQ,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,UACR,IAAK,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,OACL,WAAY,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,cACZ,MAAO,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,SACP,QAAS,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,WACT,OAAQ,OAAC,MAAiB,UAAU,IAAI,GAAG,UAAU,GAA7C,UAER,MAAO,OAAC,MAAiB,WAAW,IAAI,GAAG,UAAU,GAA9C,SACP,IAAK,OAAC,MAAiB,WAAW,IAAI,GAAG,UAAU,GAA9C,OACL,MAAO,OAAC,MAAiB,WAAW,IAAI,GAAG,UAAU,GAA9C,SACP,OAAQ,OAAC,MAAiB,WAAW,IAAI,GAAG,UAAU,GAA9C,UACR,KAAM,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MAAO,OAAU,CACf,MAAM,IAAI,MACR,eAAO,IACL,+BAA+B,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI;AAAA,CAClF,EACA,KACF,CACF,CAAC,EAED,QAAQ,IACN,eAAO,MACL,uBAAuB,QAAQ,KAAK,IAAI,QAAQ,cAAc,MAAM,IAAI,GAC1E,CACF,EACF,CAEJ,CApHe","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{registerCommands}from"../../../chunk-
|
|
1
|
+
import{registerCommands}from"../../../chunk-XJCWZEWC.mjs";import"../../../chunk-6AX5YJEO.mjs";import"../../../chunk-C6WU57FQ.mjs";import"../../../chunk-6TIBWNPX.mjs";export{registerCommands as default};
|
|
2
2
|
//# sourceMappingURL=registerCommands.mjs.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-
|
|
2
|
+
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-oiAWcISu.mjs';
|
|
3
3
|
import '../validation-handler/ValidationHandler.mjs';
|
|
4
|
+
import 'node:events';
|
|
5
|
+
import '../../cache/CacheProvider.mjs';
|
|
4
6
|
import '../validation-handler/typings.mjs';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-
|
|
2
|
+
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-DW5Fy2uM.js';
|
|
3
3
|
import '../validation-handler/ValidationHandler.js';
|
|
4
|
+
import 'node:events';
|
|
5
|
+
import '../../cache/CacheProvider.js';
|
|
4
6
|
import '../validation-handler/typings.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{areSlashCommandsDifferent}from"../../../chunk-
|
|
1
|
+
import{areSlashCommandsDifferent}from"../../../chunk-6AX5YJEO.mjs";import"../../../chunk-6TIBWNPX.mjs";export{areSlashCommandsDifferent as default};
|
|
2
2
|
//# sourceMappingURL=areSlashCommandsDifferent.mjs.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { B as BuiltInValidationParams } from '../../../CommandKit-
|
|
1
|
+
import { B as BuiltInValidationParams } from '../../../CommandKit-oiAWcISu.mjs';
|
|
2
2
|
import '../../validation-handler/ValidationHandler.mjs';
|
|
3
3
|
import '../../validation-handler/typings.mjs';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../../cache/CacheProvider.mjs';
|
|
5
7
|
|
|
6
8
|
declare function export_default({ interaction, targetCommand, handlerData, }: BuiltInValidationParams): true | undefined;
|
|
7
9
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { B as BuiltInValidationParams } from '../../../CommandKit-
|
|
1
|
+
import { B as BuiltInValidationParams } from '../../../CommandKit-DW5Fy2uM.js';
|
|
2
2
|
import '../../validation-handler/ValidationHandler.js';
|
|
3
3
|
import '../../validation-handler/typings.js';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../../cache/CacheProvider.js';
|
|
5
7
|
|
|
6
8
|
declare function export_default({ interaction, targetCommand, handlerData, }: BuiltInValidationParams): true | undefined;
|
|
7
9
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{devOnly_default}from"../../../chunk-
|
|
1
|
+
import{devOnly_default}from"../../../chunk-Z4FBPRS6.mjs";import"../../../chunk-6TIBWNPX.mjs";export{devOnly_default as default};
|
|
2
2
|
//# sourceMappingURL=devOnly.mjs.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import export_default from './devOnly.mjs';
|
|
2
|
-
import '../../../CommandKit-
|
|
2
|
+
import '../../../CommandKit-oiAWcISu.mjs';
|
|
3
3
|
import '../../validation-handler/ValidationHandler.mjs';
|
|
4
4
|
import '../../validation-handler/typings.mjs';
|
|
5
5
|
import 'discord.js';
|
|
6
|
+
import 'node:events';
|
|
7
|
+
import '../../../cache/CacheProvider.mjs';
|
|
6
8
|
|
|
7
9
|
declare const _default: (typeof export_default)[];
|
|
8
10
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import export_default from './devOnly.js';
|
|
2
|
-
import '../../../CommandKit-
|
|
2
|
+
import '../../../CommandKit-DW5Fy2uM.js';
|
|
3
3
|
import '../../validation-handler/ValidationHandler.js';
|
|
4
4
|
import '../../validation-handler/typings.js';
|
|
5
5
|
import 'discord.js';
|
|
6
|
+
import 'node:events';
|
|
7
|
+
import '../../../cache/CacheProvider.js';
|
|
6
8
|
|
|
7
9
|
declare const _default: (typeof export_default)[];
|
|
8
10
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validations_default}from"../../../chunk-
|
|
1
|
+
import{validations_default}from"../../../chunk-6TIGKCSX.mjs";import"../../../chunk-Z4FBPRS6.mjs";import"../../../chunk-K43A7OIY.mjs";import"../../../chunk-6TIBWNPX.mjs";export{validations_default as default};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { B as BuiltInValidationParams } from '../../../CommandKit-
|
|
1
|
+
import { B as BuiltInValidationParams } from '../../../CommandKit-oiAWcISu.mjs';
|
|
2
2
|
import '../../validation-handler/ValidationHandler.mjs';
|
|
3
3
|
import '../../validation-handler/typings.mjs';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../../cache/CacheProvider.mjs';
|
|
5
7
|
|
|
6
8
|
declare function export_default({ interaction, targetCommand, }: BuiltInValidationParams): true | undefined;
|
|
7
9
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { B as BuiltInValidationParams } from '../../../CommandKit-
|
|
1
|
+
import { B as BuiltInValidationParams } from '../../../CommandKit-DW5Fy2uM.js';
|
|
2
2
|
import '../../validation-handler/ValidationHandler.js';
|
|
3
3
|
import '../../validation-handler/typings.js';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../../cache/CacheProvider.js';
|
|
5
7
|
|
|
6
8
|
declare function export_default({ interaction, targetCommand, }: BuiltInValidationParams): true | undefined;
|
|
7
9
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{permissions_default}from"../../../chunk-
|
|
1
|
+
import{permissions_default}from"../../../chunk-K43A7OIY.mjs";import"../../../chunk-6TIBWNPX.mjs";export{permissions_default as default};
|
|
2
2
|
//# sourceMappingURL=permissions.mjs.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { r as EventHandler } from '../../CommandKit-
|
|
1
|
+
export { r as EventHandler } from '../../CommandKit-oiAWcISu.mjs';
|
|
2
2
|
import '../validation-handler/ValidationHandler.mjs';
|
|
3
3
|
import '../validation-handler/typings.mjs';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../cache/CacheProvider.mjs';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { r as EventHandler } from '../../CommandKit-
|
|
1
|
+
export { r as EventHandler } from '../../CommandKit-DW5Fy2uM.js';
|
|
2
2
|
import '../validation-handler/ValidationHandler.js';
|
|
3
3
|
import '../validation-handler/typings.js';
|
|
4
4
|
import 'discord.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../cache/CacheProvider.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var EventHandler_exports={};__export(EventHandler_exports,{EventHandler:()=>EventHandler});module.exports=__toCommonJS(EventHandler_exports);var import_path=__toESM(require("path")),import_promises=__toESM(require("fs/promises"));async function getFilePaths(directory,nesting){let filePaths=[];if(!directory)return filePaths;let files=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let file of files){let filePath=import_path.default.join(directory,file.name);file.isFile()&&filePaths.push(filePath),nesting&&file.isDirectory()&&(filePaths=[...filePaths,...await getFilePaths(filePath,!0)])}return filePaths}__name(getFilePaths,"getFilePaths");async function getFolderPaths(directory,nesting){let folderPaths=[];if(!directory)return folderPaths;let folders=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let folder of folders){let folderPath=import_path.default.join(directory,folder.name);folder.isDirectory()&&(folderPaths.push(folderPath),nesting&&(folderPaths=[...folderPaths,...await getFolderPaths(folderPath,!0)]))}return folderPaths}__name(getFolderPaths,"getFolderPaths");var import_path2=__toESM(require("path"));function toFileURL(filePath){return"file://"+import_path2.default.resolve(filePath).replace(/\\\\|\\/g,"/")}__name(toFileURL,"toFileURL");var import_rfdc=__toESM(require("rfdc")),clone=(0,import_rfdc.default)();var resetColor="\x1B[0m",colors_default={reset:text=>`${text}${resetColor}`,bright:text=>`\x1B[1m${text}${resetColor}`,dim:text=>`\x1B[2m${text}${resetColor}`,underscore:text=>`\x1B[4m${text}${resetColor}`,blink:text=>`\x1B[5m${text}${resetColor}`,reverse:text=>`\x1B[7m${text}${resetColor}`,hidden:text=>`\x1B[8m${text}${resetColor}`,black:text=>`\x1B[30m${text}${resetColor}`,red:text=>`\x1B[31m${text}${resetColor}`,green:text=>`\x1B[32m${text}${resetColor}`,yellow:text=>`\x1B[33m${text}${resetColor}`,blue:text=>`\x1B[34m${text}${resetColor}`,magenta:text=>`\x1B[35m${text}${resetColor}`,cyan:text=>`\x1B[36m${text}${resetColor}`,white:text=>`\x1B[37m${text}${resetColor}`,bgBlack:text=>`\x1B[40m${text}${resetColor}`,bgRed:text=>`\x1B[41m${text}${resetColor}`,bgGreen:text=>`\x1B[42m${text}${resetColor}`,bgYellow:text=>`\x1B[43m${text}${resetColor}`,bgBlue:text=>`\x1B[44m${text}${resetColor}`,bgMagenta:text=>`\x1B[45m${text}${resetColor}`,bgCyan:text=>`\x1B[46m${text}${resetColor}`,bgWhite:text=>`\x1B[47m${text}${resetColor}
|
|
1
|
+
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var EventHandler_exports={};__export(EventHandler_exports,{EventHandler:()=>EventHandler});module.exports=__toCommonJS(EventHandler_exports);var import_path=__toESM(require("path")),import_promises=__toESM(require("fs/promises"));async function getFilePaths(directory,nesting){let filePaths=[];if(!directory)return filePaths;let files=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let file of files){let filePath=import_path.default.join(directory,file.name);file.isFile()&&filePaths.push(filePath),nesting&&file.isDirectory()&&(filePaths=[...filePaths,...await getFilePaths(filePath,!0)])}return filePaths}__name(getFilePaths,"getFilePaths");async function getFolderPaths(directory,nesting){let folderPaths=[];if(!directory)return folderPaths;let folders=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let folder of folders){let folderPath=import_path.default.join(directory,folder.name);folder.isDirectory()&&(folderPaths.push(folderPath),nesting&&(folderPaths=[...folderPaths,...await getFolderPaths(folderPath,!0)]))}return folderPaths}__name(getFolderPaths,"getFolderPaths");var import_path2=__toESM(require("path"));function toFileURL(filePath){return"file://"+import_path2.default.resolve(filePath).replace(/\\\\|\\/g,"/")}__name(toFileURL,"toFileURL");var import_rfdc=__toESM(require("rfdc")),clone=(0,import_rfdc.default)();var resetColor="\x1B[0m",colors_default={reset:__name(text=>`${text}${resetColor}`,"reset"),bright:__name(text=>`\x1B[1m${text}${resetColor}`,"bright"),dim:__name(text=>`\x1B[2m${text}${resetColor}`,"dim"),underscore:__name(text=>`\x1B[4m${text}${resetColor}`,"underscore"),blink:__name(text=>`\x1B[5m${text}${resetColor}`,"blink"),reverse:__name(text=>`\x1B[7m${text}${resetColor}`,"reverse"),hidden:__name(text=>`\x1B[8m${text}${resetColor}`,"hidden"),black:__name(text=>`\x1B[30m${text}${resetColor}`,"black"),red:__name(text=>`\x1B[31m${text}${resetColor}`,"red"),green:__name(text=>`\x1B[32m${text}${resetColor}`,"green"),yellow:__name(text=>`\x1B[33m${text}${resetColor}`,"yellow"),blue:__name(text=>`\x1B[34m${text}${resetColor}`,"blue"),magenta:__name(text=>`\x1B[35m${text}${resetColor}`,"magenta"),cyan:__name(text=>`\x1B[36m${text}${resetColor}`,"cyan"),white:__name(text=>`\x1B[37m${text}${resetColor}`,"white"),bgBlack:__name(text=>`\x1B[40m${text}${resetColor}`,"bgBlack"),bgRed:__name(text=>`\x1B[41m${text}${resetColor}`,"bgRed"),bgGreen:__name(text=>`\x1B[42m${text}${resetColor}`,"bgGreen"),bgYellow:__name(text=>`\x1B[43m${text}${resetColor}`,"bgYellow"),bgBlue:__name(text=>`\x1B[44m${text}${resetColor}`,"bgBlue"),bgMagenta:__name(text=>`\x1B[45m${text}${resetColor}`,"bgMagenta"),bgCyan:__name(text=>`\x1B[46m${text}${resetColor}`,"bgCyan"),bgWhite:__name(text=>`\x1B[47m${text}${resetColor}`,"bgWhite")};var EventHandler=class{static{__name(this,"EventHandler")}#data;constructor({...options}){this.#data={...options,events:[]}}async init(){await this.#buildEvents(),this.#registerEvents()}async#buildEvents(){let eventFolderPaths=await getFolderPaths(this.#data.eventsPath);for(let eventFolderPath of eventFolderPaths){let eventName=eventFolderPath.replace(/\\\\|\\/g,"/").split("/").pop(),allowedExtensions=/\.(js|mjs|cjs|ts)$/i,eventFilePaths=(await getFilePaths(eventFolderPath,!0)).filter(path3=>allowedExtensions.test(path3)),eventObj={name:eventName,functions:[]};this.#data.events.push(eventObj);for(let eventFilePath of eventFilePaths){let importedFunction=(await import(`${toFileURL(eventFilePath)}?t=${Date.now()}`)).default,eventFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(eventFilePath)],eventFunction?.default&&(eventFunction=eventFunction.default);let compactFilePath=eventFilePath.split(process.cwd())[1]||eventFilePath;if(typeof eventFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Event file ${compactFilePath} does not export a function.`));continue}eventObj.functions.push(eventFunction)}}}#registerEvents(){let client=this.#data.client,handler=this.#data.commandKitInstance;for(let eventObj of this.#data.events)client.on(eventObj.name,async(...params)=>{for(let eventFunction of eventObj.functions)if(await eventFunction(...params,client,handler))break})}get events(){return this.#data.events}async reloadEvents(commandHandler){if(!this.#data.eventsPath)throw new Error(colors_default.red('Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'));this.#data.events=[],await this.#buildEvents(),this.#data.client.removeAllListeners(),this.#registerEvents(),commandHandler?.handleCommands()}};0&&(module.exports={EventHandler});
|
|
2
2
|
//# sourceMappingURL=EventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/handlers/event-handler/EventHandler.ts","../../../src/utils/get-paths.ts","../../../src/utils/resolve-file-url.ts","../../../src/utils/clone.ts","../../../src/utils/colors.ts"],"sourcesContent":["import type { EventHandlerOptions, EventHandlerData } from './typings';\nimport type { CommandHandler } from '../command-handler/CommandHandler';\nimport { getFilePaths, getFolderPaths } from '../../utils/get-paths';\nimport { toFileURL } from '../../utils/resolve-file-url';\nimport { clone } from '../../utils/clone';\nimport colors from '../../utils/colors';\n\n/**\n * A handler for client events.\n */\nexport class EventHandler {\n #data: EventHandlerData;\n\n constructor({ ...options }: EventHandlerOptions) {\n this.#data = {\n ...options,\n events: []\n };\n }\n\n async init() {\n await this.#buildEvents();\n this.#registerEvents();\n }\n\n async #buildEvents() {\n const eventFolderPaths = await getFolderPaths(this.#data.eventsPath);\n\n for (const eventFolderPath of eventFolderPaths) {\n const eventName = eventFolderPath.\n replace(/\\\\\\\\|\\\\/g, '/').\n split('/').\n pop() as string;\n\n const allowedExtensions = /\\.(js|mjs|cjs|ts)$/i;\n const eventPaths = await getFilePaths(eventFolderPath, true);\n\n const eventFilePaths = eventPaths.filter((path) =>\n allowedExtensions.test(path)\n );\n\n const eventObj = {\n name: eventName,\n functions: [] as Function[]\n };\n\n this.#data.events.push(eventObj);\n\n for (const eventFilePath of eventFilePaths) {\n const modulePath = toFileURL(eventFilePath);\n\n let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).\n default;\n let eventFunction = clone(importedFunction);\n\n // If it's CommonJS, invalidate the import cache\n if (typeof module !== 'undefined' && typeof require !== 'undefined') {\n delete require.cache[require.resolve(eventFilePath)];\n }\n\n if (eventFunction?.default) {\n eventFunction = eventFunction.default;\n }\n\n const compactFilePath =\n eventFilePath.split(process.cwd())[1] || eventFilePath;\n\n if (typeof eventFunction !== 'function') {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Event file ${compactFilePath} does not export a function.`\n )\n );\n continue;\n }\n\n eventObj.functions.push(eventFunction);\n }\n }\n }\n\n #registerEvents() {\n const client = this.#data.client;\n const handler = this.#data.commandKitInstance;\n\n for (const eventObj of this.#data.events) {\n client.on(eventObj.name, async (...params) => {\n for (const eventFunction of eventObj.functions) {\n const stopEventLoop = await eventFunction(...params, client, handler);\n\n if (stopEventLoop) {\n break;\n }\n }\n });\n }\n }\n\n get events() {\n return this.#data.events;\n }\n\n async reloadEvents(commandHandler?: CommandHandler) {\n if (!this.#data.eventsPath) {\n throw new Error(\n colors.red(\n 'Cannot reload events as \"eventsPath\" was not provided when instantiating CommandKit.'\n )\n );\n }\n\n this.#data.events = [];\n\n await this.#buildEvents();\n\n this.#data.client.removeAllListeners();\n\n this.#registerEvents();\n\n // Re-register \"interactionCreate\" event for application commands.\n commandHandler?.handleCommands();\n }\n}","import path from 'path';\nimport fs from 'fs/promises';\n\nexport async function getFilePaths(\ndirectory: string,\nnesting?: boolean)\n: Promise<string[]> {\n let filePaths: string[] = [];\n\n if (!directory) return filePaths;\n\n const files = await fs.readdir(directory, { withFileTypes: true });\n\n for (const file of files) {\n const filePath = path.join(directory, file.name);\n\n if (file.isFile()) {\n filePaths.push(filePath);\n }\n\n if (nesting && file.isDirectory()) {\n filePaths = [...filePaths, ...(await getFilePaths(filePath, true))];\n }\n }\n\n return filePaths;\n}\n\nexport async function getFolderPaths(\ndirectory: string,\nnesting?: boolean)\n: Promise<string[]> {\n let folderPaths: string[] = [];\n\n if (!directory) return folderPaths;\n\n const folders = await fs.readdir(directory, { withFileTypes: true });\n\n for (const folder of folders) {\n const folderPath = path.join(directory, folder.name);\n\n if (folder.isDirectory()) {\n folderPaths.push(folderPath);\n\n if (nesting) {\n folderPaths = [\n ...folderPaths,\n ...(await getFolderPaths(folderPath, true))];\n\n }\n }\n }\n\n return folderPaths;\n}","import path from 'path';\n\n/**\n * Convert a local file path to a file URL.\n * @param filePath - The local file's path.\n * @returns - The converted file URL.\n */\nexport function toFileURL(filePath: string) {\n const resolvedPath = path.resolve(filePath);\n return 'file://' + resolvedPath.replace(/\\\\\\\\|\\\\/g, '/');\n}","import rfdc from 'rfdc';\n\nexport const clone = rfdc();","const resetColor = '\\x1b[0m';\n\nexport default {\n reset: (text: string) => `${text}${resetColor}`,\n bright: (text: string) => `\\x1b[1m${text}${resetColor}`,\n dim: (text: string) => `\\x1b[2m${text}${resetColor}`,\n underscore: (text: string) => `\\x1b[4m${text}${resetColor}`,\n blink: (text: string) => `\\x1b[5m${text}${resetColor}`,\n reverse: (text: string) => `\\x1b[7m${text}${resetColor}`,\n hidden: (text: string) => `\\x1b[8m${text}${resetColor}`,\n\n black: (text: string) => `\\x1b[30m${text}${resetColor}`,\n red: (text: string) => `\\x1b[31m${text}${resetColor}`,\n green: (text: string) => `\\x1b[32m${text}${resetColor}`,\n yellow: (text: string) => `\\x1b[33m${text}${resetColor}`,\n blue: (text: string) => `\\x1b[34m${text}${resetColor}`,\n magenta: (text: string) => `\\x1b[35m${text}${resetColor}`,\n cyan: (text: string) => `\\x1b[36m${text}${resetColor}`,\n white: (text: string) => `\\x1b[37m${text}${resetColor}`,\n\n bgBlack: (text: string) => `\\x1b[40m${text}${resetColor}`,\n bgRed: (text: string) => `\\x1b[41m${text}${resetColor}`,\n bgGreen: (text: string) => `\\x1b[42m${text}${resetColor}`,\n bgYellow: (text: string) => `\\x1b[43m${text}${resetColor}`,\n bgBlue: (text: string) => `\\x1b[44m${text}${resetColor}`,\n bgMagenta: (text: string) => `\\x1b[45m${text}${resetColor}`,\n bgCyan: (text: string) => `\\x1b[46m${text}${resetColor}`,\n bgWhite: (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,CACF","names":["fs","path","import_path","path","rfdc","path"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/handlers/event-handler/EventHandler.ts","../../../src/utils/get-paths.ts","../../../src/utils/resolve-file-url.ts","../../../src/utils/clone.ts","../../../src/utils/colors.ts"],"sourcesContent":["import type { EventHandlerOptions, EventHandlerData } from './typings';\nimport type { CommandHandler } from '../command-handler/CommandHandler';\nimport { getFilePaths, getFolderPaths } from '../../utils/get-paths';\nimport { toFileURL } from '../../utils/resolve-file-url';\nimport { clone } from '../../utils/clone';\nimport colors from '../../utils/colors';\n\n/**\n * A handler for client events.\n */\nexport class EventHandler {\n #data: EventHandlerData;\n\n constructor({ ...options }: EventHandlerOptions) {\n this.#data = {\n ...options,\n events: []\n };\n }\n\n async init() {\n await this.#buildEvents();\n this.#registerEvents();\n }\n\n async #buildEvents() {\n const eventFolderPaths = await getFolderPaths(this.#data.eventsPath);\n\n for (const eventFolderPath of eventFolderPaths) {\n const eventName = eventFolderPath.\n replace(/\\\\\\\\|\\\\/g, '/').\n split('/').\n pop() as string;\n\n const allowedExtensions = /\\.(js|mjs|cjs|ts)$/i;\n const eventPaths = await getFilePaths(eventFolderPath, true);\n\n const eventFilePaths = eventPaths.filter((path) =>\n allowedExtensions.test(path)\n );\n\n const eventObj = {\n name: eventName,\n functions: [] as Function[]\n };\n\n this.#data.events.push(eventObj);\n\n for (const eventFilePath of eventFilePaths) {\n const modulePath = toFileURL(eventFilePath);\n\n let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).\n default;\n let eventFunction = clone(importedFunction);\n\n // If it's CommonJS, invalidate the import cache\n if (typeof module !== 'undefined' && typeof require !== 'undefined') {\n delete require.cache[require.resolve(eventFilePath)];\n }\n\n if (eventFunction?.default) {\n eventFunction = eventFunction.default;\n }\n\n const compactFilePath =\n eventFilePath.split(process.cwd())[1] || eventFilePath;\n\n if (typeof eventFunction !== 'function') {\n process.emitWarning(\n colors.yellow(\n `Ignoring: Event file ${compactFilePath} does not export a function.`\n )\n );\n continue;\n }\n\n eventObj.functions.push(eventFunction);\n }\n }\n }\n\n #registerEvents() {\n const client = this.#data.client;\n const handler = this.#data.commandKitInstance;\n\n for (const eventObj of this.#data.events) {\n client.on(eventObj.name, async (...params) => {\n for (const eventFunction of eventObj.functions) {\n const stopEventLoop = await eventFunction(...params, client, handler);\n\n if (stopEventLoop) {\n break;\n }\n }\n });\n }\n }\n\n get events() {\n return this.#data.events;\n }\n\n async reloadEvents(commandHandler?: CommandHandler) {\n if (!this.#data.eventsPath) {\n throw new Error(\n colors.red(\n 'Cannot reload events as \"eventsPath\" was not provided when instantiating CommandKit.'\n )\n );\n }\n\n this.#data.events = [];\n\n await this.#buildEvents();\n\n this.#data.client.removeAllListeners();\n\n this.#registerEvents();\n\n // Re-register \"interactionCreate\" event for application commands.\n commandHandler?.handleCommands();\n }\n}","import path from 'path';\nimport fs from 'fs/promises';\n\nexport async function getFilePaths(\ndirectory: string,\nnesting?: boolean)\n: Promise<string[]> {\n let filePaths: string[] = [];\n\n if (!directory) return filePaths;\n\n const files = await fs.readdir(directory, { withFileTypes: true });\n\n for (const file of files) {\n const filePath = path.join(directory, file.name);\n\n if (file.isFile()) {\n filePaths.push(filePath);\n }\n\n if (nesting && file.isDirectory()) {\n filePaths = [...filePaths, ...(await getFilePaths(filePath, true))];\n }\n }\n\n return filePaths;\n}\n\nexport async function getFolderPaths(\ndirectory: string,\nnesting?: boolean)\n: Promise<string[]> {\n let folderPaths: string[] = [];\n\n if (!directory) return folderPaths;\n\n const folders = await fs.readdir(directory, { withFileTypes: true });\n\n for (const folder of folders) {\n const folderPath = path.join(directory, folder.name);\n\n if (folder.isDirectory()) {\n folderPaths.push(folderPath);\n\n if (nesting) {\n folderPaths = [\n ...folderPaths,\n ...(await getFolderPaths(folderPath, true))];\n\n }\n }\n }\n\n return folderPaths;\n}","import path from 'path';\n\n/**\n * Convert a local file path to a file URL.\n * @param filePath - The local file's path.\n * @returns - The converted file URL.\n */\nexport function toFileURL(filePath: string) {\n const resolvedPath = path.resolve(filePath);\n return 'file://' + resolvedPath.replace(/\\\\\\\\|\\\\/g, '/');\n}","import rfdc from 'rfdc';\n\nexport const clone = rfdc();","const resetColor = '\\x1b[0m';\n\nexport default {\n reset: (text: string) => `${text}${resetColor}`,\n bright: (text: string) => `\\x1b[1m${text}${resetColor}`,\n dim: (text: string) => `\\x1b[2m${text}${resetColor}`,\n underscore: (text: string) => `\\x1b[4m${text}${resetColor}`,\n blink: (text: string) => `\\x1b[5m${text}${resetColor}`,\n reverse: (text: string) => `\\x1b[7m${text}${resetColor}`,\n hidden: (text: string) => `\\x1b[8m${text}${resetColor}`,\n\n black: (text: string) => `\\x1b[30m${text}${resetColor}`,\n red: (text: string) => `\\x1b[31m${text}${resetColor}`,\n green: (text: string) => `\\x1b[32m${text}${resetColor}`,\n yellow: (text: string) => `\\x1b[33m${text}${resetColor}`,\n blue: (text: string) => `\\x1b[34m${text}${resetColor}`,\n magenta: (text: string) => `\\x1b[35m${text}${resetColor}`,\n cyan: (text: string) => `\\x1b[36m${text}${resetColor}`,\n white: (text: string) => `\\x1b[37m${text}${resetColor}`,\n\n bgBlack: (text: string) => `\\x1b[40m${text}${resetColor}`,\n bgRed: (text: string) => `\\x1b[41m${text}${resetColor}`,\n bgGreen: (text: string) => `\\x1b[42m${text}${resetColor}`,\n bgYellow: (text: string) => `\\x1b[43m${text}${resetColor}`,\n bgBlue: (text: string) => `\\x1b[44m${text}${resetColor}`,\n bgMagenta: (text: string) => `\\x1b[45m${text}${resetColor}`,\n bgCyan: (text: string) => `\\x1b[46m${text}${resetColor}`,\n bgWhite: (text: string) => `\\x1b[47m${text}${resetColor}`\n};"],"mappings":"q+BAAA,6ICAA,gBAAiB,yBACjB,gBAAe,gCAEf,eAAsB,aACtB,UACA,QACoB,CAClB,IAAI,UAAsB,CAAC,EAE3B,GAAI,CAAC,UAAW,OAAO,UAEvB,IAAM,MAAQ,MAAM,gBAAAA,QAAG,QAAQ,UAAW,CAAE,cAAe,E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KAAK,gBAAgB,EAGrB,gBAAgB,eAAe,CACjC,CACF","names":["fs","path","import_path","path","rfdc","path"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EventHandler}from"../../chunk-
|
|
1
|
+
import{EventHandler}from"../../chunk-6IFRWFZE.mjs";import"../../chunk-4CG7S6RY.mjs";import"../../chunk-MNPCM4QU.mjs";import"../../chunk-C6WU57FQ.mjs";import"../../chunk-6BSP7AD3.mjs";import"../../chunk-6TIBWNPX.mjs";export{EventHandler};
|
|
2
2
|
//# sourceMappingURL=EventHandler.mjs.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-
|
|
2
|
+
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-oiAWcISu.mjs';
|
|
3
3
|
import '../validation-handler/ValidationHandler.mjs';
|
|
4
4
|
import '../validation-handler/typings.mjs';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../cache/CacheProvider.mjs';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-
|
|
2
|
+
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-DW5Fy2uM.js';
|
|
3
3
|
import '../validation-handler/ValidationHandler.js';
|
|
4
4
|
import '../validation-handler/typings.js';
|
|
5
|
+
import 'node:events';
|
|
6
|
+
import '../../cache/CacheProvider.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-
|
|
1
|
+
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-oiAWcISu.mjs';
|
|
2
2
|
export { ValidationHandler } from './validation-handler/ValidationHandler.mjs';
|
|
3
3
|
import 'discord.js';
|
|
4
|
+
import 'node:events';
|
|
5
|
+
import '../cache/CacheProvider.mjs';
|
|
4
6
|
import './validation-handler/typings.mjs';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-
|
|
1
|
+
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-DW5Fy2uM.js';
|
|
2
2
|
export { ValidationHandler } from './validation-handler/ValidationHandler.js';
|
|
3
3
|
import 'discord.js';
|
|
4
|
+
import 'node:events';
|
|
5
|
+
import '../cache/CacheProvider.js';
|
|
4
6
|
import './validation-handler/typings.js';
|
package/dist/handlers/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var handlers_exports={};__export(handlers_exports,{CommandHandler:()=>CommandHandler,EventHandler:()=>EventHandler,ValidationHandler:()=>ValidationHandler});module.exports=__toCommonJS(handlers_exports);var import_rfdc=__toESM(require("rfdc")),clone=(0,import_rfdc.default)();var resetColor="\x1B[0m",colors_default={reset:text=>`${text}${resetColor}`,bright:text=>`\x1B[1m${text}${resetColor}`,dim:text=>`\x1B[2m${text}${resetColor}`,underscore:text=>`\x1B[4m${text}${resetColor}`,blink:text=>`\x1B[5m${text}${resetColor}`,reverse:text=>`\x1B[7m${text}${resetColor}`,hidden:text=>`\x1B[8m${text}${resetColor}`,black:text=>`\x1B[30m${text}${resetColor}`,red:text=>`\x1B[31m${text}${resetColor}`,green:text=>`\x1B[32m${text}${resetColor}`,yellow:text=>`\x1B[33m${text}${resetColor}`,blue:text=>`\x1B[34m${text}${resetColor}`,magenta:text=>`\x1B[35m${text}${resetColor}`,cyan:text=>`\x1B[36m${text}${resetColor}`,white:text=>`\x1B[37m${text}${resetColor}`,bgBlack:text=>`\x1B[40m${text}${resetColor}`,bgRed:text=>`\x1B[41m${text}${resetColor}`,bgGreen:text=>`\x1B[42m${text}${resetColor}`,bgYellow:text=>`\x1B[43m${text}${resetColor}`,bgBlue:text=>`\x1B[44m${text}${resetColor}`,bgMagenta:text=>`\x1B[45m${text}${resetColor}`,bgCyan:text=>`\x1B[46m${text}${resetColor}`,bgWhite:text=>`\x1B[47m${text}${resetColor}
|
|
1
|
+
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var handlers_exports={};__export(handlers_exports,{CommandHandler:()=>CommandHandler,EventHandler:()=>EventHandler,ValidationHandler:()=>ValidationHandler});module.exports=__toCommonJS(handlers_exports);var import_rfdc=__toESM(require("rfdc")),clone=(0,import_rfdc.default)();var resetColor="\x1B[0m",colors_default={reset:__name(text=>`${text}${resetColor}`,"reset"),bright:__name(text=>`\x1B[1m${text}${resetColor}`,"bright"),dim:__name(text=>`\x1B[2m${text}${resetColor}`,"dim"),underscore:__name(text=>`\x1B[4m${text}${resetColor}`,"underscore"),blink:__name(text=>`\x1B[5m${text}${resetColor}`,"blink"),reverse:__name(text=>`\x1B[7m${text}${resetColor}`,"reverse"),hidden:__name(text=>`\x1B[8m${text}${resetColor}`,"hidden"),black:__name(text=>`\x1B[30m${text}${resetColor}`,"black"),red:__name(text=>`\x1B[31m${text}${resetColor}`,"red"),green:__name(text=>`\x1B[32m${text}${resetColor}`,"green"),yellow:__name(text=>`\x1B[33m${text}${resetColor}`,"yellow"),blue:__name(text=>`\x1B[34m${text}${resetColor}`,"blue"),magenta:__name(text=>`\x1B[35m${text}${resetColor}`,"magenta"),cyan:__name(text=>`\x1B[36m${text}${resetColor}`,"cyan"),white:__name(text=>`\x1B[37m${text}${resetColor}`,"white"),bgBlack:__name(text=>`\x1B[40m${text}${resetColor}`,"bgBlack"),bgRed:__name(text=>`\x1B[41m${text}${resetColor}`,"bgRed"),bgGreen:__name(text=>`\x1B[42m${text}${resetColor}`,"bgGreen"),bgYellow:__name(text=>`\x1B[43m${text}${resetColor}`,"bgYellow"),bgBlue:__name(text=>`\x1B[44m${text}${resetColor}`,"bgBlue"),bgMagenta:__name(text=>`\x1B[45m${text}${resetColor}`,"bgMagenta"),bgCyan:__name(text=>`\x1B[46m${text}${resetColor}`,"bgCyan"),bgWhite:__name(text=>`\x1B[47m${text}${resetColor}`,"bgWhite")};var import_path=__toESM(require("path")),import_promises=__toESM(require("fs/promises"));async function getFilePaths(directory,nesting){let filePaths=[];if(!directory)return filePaths;let files=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let file of files){let filePath=import_path.default.join(directory,file.name);file.isFile()&&filePaths.push(filePath),nesting&&file.isDirectory()&&(filePaths=[...filePaths,...await getFilePaths(filePath,!0)])}return filePaths}__name(getFilePaths,"getFilePaths");async function getFolderPaths(directory,nesting){let folderPaths=[];if(!directory)return folderPaths;let folders=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let folder of folders){let folderPath=import_path.default.join(directory,folder.name);folder.isDirectory()&&(folderPaths.push(folderPath),nesting&&(folderPaths=[...folderPaths,...await getFolderPaths(folderPath,!0)]))}return folderPaths}__name(getFolderPaths,"getFolderPaths");var import_path2=__toESM(require("path"));function toFileURL(filePath){return"file://"+import_path2.default.resolve(filePath).replace(/\\\\|\\/g,"/")}__name(toFileURL,"toFileURL");async function loadCommandsWithRest(props){if(props.reloading)if(props.client.isReady())await handleLoading(props.client,props.commands,props.devGuildIds,props.reloading,props.type);else throw new Error(colors_default.red("Cannot reload commands when client is not ready."));else props.client.once("ready",async c=>{await handleLoading(c,props.commands,props.devGuildIds,props.reloading,props.type)})}__name(loadCommandsWithRest,"loadCommandsWithRest");async function handleLoading(client,commands,devGuildIds,reloading,type){commands=commands.filter(cmd=>!cmd.options?.deleted);let devOnlyCommands=commands.filter(cmd=>cmd.options?.devOnly),globalCommands=commands.filter(cmd=>!cmd.options?.devOnly);type==="dev"?await loadDevCommands(client,devOnlyCommands,devGuildIds,reloading):type==="global"?await loadGlobalCommands(client,globalCommands,reloading):(await loadDevCommands(client,devOnlyCommands,devGuildIds,reloading),await loadGlobalCommands(client,globalCommands,reloading))}__name(handleLoading,"handleLoading");async function loadGlobalCommands(client,commands,reloading){let requestBody=commands.map(cmd=>cmd.data);await client.application.commands.set(requestBody).catch(error=>{throw new Error(colors_default.red(`Error ${reloading?"reloading":"loading"} global application commands.
|
|
2
2
|
`),error)}),console.log(colors_default.green(`${reloading?"Reloaded":"Loaded"} ${requestBody.length} global commands.`))}__name(loadGlobalCommands,"loadGlobalCommands");async function loadDevCommands(client,commands,guildIds,reloading){let requestBody=commands.map(cmd=>cmd.data);for(let guildId of guildIds){let targetGuild=client.guilds.cache.get(guildId)||await client.guilds.fetch(guildId);if(!targetGuild){process.emitWarning(`Cannot ${reloading?"reload":"load"} commands in guild "${guildId}" - guild doesn't exist or client isn't part of the guild.`);continue}await targetGuild.commands.set(requestBody).catch(error=>{throw new Error(colors_default.red(`Error ${reloading?"reloading":"loading"} developer application commands in guild "${targetGuild?.name||guildId}".
|
|
3
3
|
`),error)}),console.log(colors_default.green(`${reloading?"Reloaded":"Loaded"} ${requestBody.length} developer commands in guild "${targetGuild.name}".`))}}__name(loadDevCommands,"loadDevCommands");function areSlashCommandsDifferent(appCommand,localCommand){if(appCommand.options||(appCommand.options=[]),localCommand.options||(localCommand.options=[]),appCommand.description||(appCommand.description=""),localCommand.description||(localCommand.description=""),localCommand.description!==appCommand.description||localCommand.options.length!==appCommand.options.length)return!0}__name(areSlashCommandsDifferent,"areSlashCommandsDifferent");async function registerCommands(props){if(props.reloading)if(props.client.isReady())await handleRegistration(props.client,props.commands,props.devGuildIds,props.type);else throw new Error(colors_default.red("Cannot reload commands when client is not ready."));else props.client.once("ready",async c=>{await handleRegistration(c,props.commands,props.devGuildIds,props.type)})}__name(registerCommands,"registerCommands");async function handleRegistration(client,commands,devGuildIds,type){let devOnlyCommands=commands.filter(cmd=>cmd.options?.devOnly),globalCommands=commands.filter(cmd=>!cmd.options?.devOnly);type==="dev"?await registerDevCommands(client,devOnlyCommands,devGuildIds):type==="global"?await registerGlobalCommands(client,globalCommands):(await registerDevCommands(client,devOnlyCommands,devGuildIds),await registerGlobalCommands(client,globalCommands))}__name(handleRegistration,"handleRegistration");async function registerGlobalCommands(client,commands){let appCommandsManager=client.application.commands;await appCommandsManager.fetch();for(let command of commands){let targetCommand=appCommandsManager.cache.find(cmd=>cmd.name===command.data.name);if(command.options?.deleted){targetCommand?(await targetCommand.delete().catch(error=>{throw new Error(colors_default.red(`Failed to delete command "${command.data.name}" globally.
|
|
4
4
|
`),error)}),console.log(colors_default.green(`Deleted command "${command.data.name}" globally.`))):process.emitWarning(colors_default.yellow(`Ignoring: Command "${command.data.name}" is globally marked as deleted.`));continue}if(targetCommand&&areSlashCommandsDifferent(targetCommand,command.data)){await targetCommand.edit(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to edit command "${command.data.name}" globally.
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
`),error)}),console.log(colors_default.green(`Edited command "${command.data.name}" in ${guildCommands.guild.name}.`));continue}targetCommand||(await guildCommands.create(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to register command "${command.data.name}" in ${guildCommands.guild.name}.
|
|
8
8
|
`),error)}),console.log(colors_default.green(`Registered command "${command.data.name}" in ${guildCommands.guild.name}.`)))}}__name(registerDevCommands,"registerDevCommands");function devOnly_default({interaction,targetCommand,handlerData}){if(!interaction.isAutocomplete()&&targetCommand.options?.devOnly){if(interaction.inGuild()&&!handlerData.devGuildIds.includes(interaction.guildId))return interaction.reply({content:"\u274C This command can only be used inside development servers.",ephemeral:!0}),!0;let memberRoles=interaction.guild?.members.cache.get(interaction.user.id)?.roles.cache,hasDevRole=!1;if(memberRoles?.forEach(role=>{handlerData.devRoleIds.includes(role.id)&&(hasDevRole=!0)}),!(handlerData.devUserIds.includes(interaction.user.id)||hasDevRole))return interaction.reply({content:"\u274C This command can only be used by developers.",ephemeral:!0}),!0}}__name(devOnly_default,"default");var import_discord=require("discord.js");function permissions_default({interaction,targetCommand}){if(interaction.isAutocomplete())return;let userPermissions=interaction.memberPermissions,userPermissionsRequired=targetCommand.options?.userPermissions,missingUserPermissions=[];typeof userPermissionsRequired=="string"&&(userPermissionsRequired=[userPermissionsRequired]);let botPermissions=interaction.guild?.members.me?.permissions,botPermissionsRequired=targetCommand.options?.botPermissions,missingBotPermissions=[];if(typeof botPermissionsRequired=="string"&&(botPermissionsRequired=[botPermissionsRequired]),!userPermissionsRequired?.length&&!botPermissionsRequired?.length)return;if(userPermissions&&userPermissionsRequired)for(let permission of userPermissionsRequired)userPermissions.has(permission)||missingUserPermissions.push(permission);if(botPermissions&&botPermissionsRequired)for(let permission of botPermissionsRequired)botPermissions.has(permission)||missingBotPermissions.push(permission);if(!missingUserPermissions.length&&!missingBotPermissions.length)return;let pattern=/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;missingUserPermissions=missingUserPermissions.map(str=>str.replace(pattern,"$1$3 $2$4")),missingBotPermissions=missingBotPermissions.map(str=>str.replace(pattern,"$1$3 $2$4"));let embedDescription="",formatter=new Intl.ListFormat("en",{style:"long",type:"conjunction"}),getPermissionWord=__name(permissions=>permissions.length===1?"permission":"permissions","getPermissionWord");if(missingUserPermissions.length){let formattedPermissions=missingUserPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- You must have the ${permissionsString} ${getPermissionWord(missingUserPermissions)} to be able to run this command.
|
|
9
9
|
`}if(missingBotPermissions.length){let formattedPermissions=missingBotPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- I must have the ${permissionsString} ${getPermissionWord(missingBotPermissions)} to be able to execute this command.
|
|
10
|
-
`}let embed=new import_discord.EmbedBuilder().setTitle(":x: Missing permissions!").setDescription(embedDescription).setColor("Red");return interaction.reply({embeds:[embed],ephemeral:!0}),!0}__name(permissions_default,"default");var validations_default=[devOnly_default,permissions_default];var CommandHandler=class{static{__name(this,"CommandHandler")}#data;constructor({...options}){this.#data={...options,builtInValidations:[],commands:[]}}async init(){await this.#buildCommands(),this.#buildBuiltInValidations();let devOnlyCommands=this.#data.commands.filter(cmd=>cmd.options?.devOnly);devOnlyCommands.length&&!this.#data.devGuildIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devGuildIds" have not been set.')),devOnlyCommands.length&&!this.#data.devUserIds.length&&!this.#data.devRoleIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devUserIds" or "devRoleIds" have not been set.')),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}),this.handleCommands()}async#buildCommands(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,commandFilePaths=(await getFilePaths(this.#data.commandsPath,!0)).filter(path3=>allowedExtensions.test(path3));for(let commandFilePath of commandFilePaths){let importedObj=await import(`${toFileURL(commandFilePath)}?t=${Date.now()}`),commandObj=clone(importedObj);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(commandFilePath)];let compactFilePath=commandFilePath.split(process.cwd())[1]||commandFilePath;if(commandObj.default&&(commandObj=commandObj.default),importedObj.default?commandObj.data=importedObj.default.data:commandObj.data=importedObj.data,!commandObj.data){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data".`));continue}if(!commandObj.data.name){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data.name".`));continue}if(!commandObj.run){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run".`));continue}if(typeof commandObj.run!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run" as a function.`));continue}commandObj.filePath=commandFilePath;let commandCategory=commandFilePath.split(this.#data.commandsPath)[1]?.replace(/\\\\|\\/g,"/").split("/")[1]||null;commandCategory&&allowedExtensions.test(commandCategory)?commandObj.category=null:commandObj.category=commandCategory,this.#data.commands.push(commandObj)}}#buildBuiltInValidations(){for(let builtInValidationFunction of validations_default)this.#data.builtInValidations.push(builtInValidationFunction)}handleCommands(){this.#data.client.on("interactionCreate",async interaction=>{if(!interaction.isChatInputCommand()&&!interaction.isContextMenuCommand()&&!interaction.isAutocomplete())return;let isAutocomplete=interaction.isAutocomplete(),targetCommand=this.#data.commands.find(cmd=>cmd.data.name===interaction.commandName);if(!targetCommand)return;let{data,options,run,autocomplete,...rest}=targetCommand;return isAutocomplete&&!autocomplete?void 0:__name(async()=>{let commandObj={data:targetCommand.data,options:targetCommand.options,...rest};if(this.#data.validationHandler){let canRun2=!0;for(let validationFunction of this.#data.validationHandler.validations)if(await validationFunction({interaction,commandObj,client:this.#data.client,handler:this.#data.commandkitInstance})){canRun2=!1;break}if(!canRun2)return}let canRun=!0;if(!this.#data.skipBuiltInValidations){for(let validation of this.#data.builtInValidations)if(validation({targetCommand,interaction,handlerData:this.#data})){canRun=!1;break}}if(!canRun)return;let command=targetCommand[isAutocomplete?"autocomplete":"run"],context={interaction,client:this.#data.client,handler:this.#data.commandkitInstance};return await command(context)},"executor")()})}get commands(){return this.#data.commands}async reloadCommands(type){if(!this.#data.commandsPath)throw new Error(colors_default.red('Cannot reload commands as "commandsPath" was not provided when instantiating CommandKit.'));this.#data.commands=[],await this.#buildCommands(),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type})}};var EventHandler=class{static{__name(this,"EventHandler")}#data;constructor({...options}){this.#data={...options,events:[]}}async init(){await this.#buildEvents(),this.#registerEvents()}async#buildEvents(){let eventFolderPaths=await getFolderPaths(this.#data.eventsPath);for(let eventFolderPath of eventFolderPaths){let eventName=eventFolderPath.replace(/\\\\|\\/g,"/").split("/").pop(),allowedExtensions=/\.(js|mjs|cjs|ts)$/i,eventFilePaths=(await getFilePaths(eventFolderPath,!0)).filter(path3=>allowedExtensions.test(path3)),eventObj={name:eventName,functions:[]};this.#data.events.push(eventObj);for(let eventFilePath of eventFilePaths){let importedFunction=(await import(`${toFileURL(eventFilePath)}?t=${Date.now()}`)).default,eventFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(eventFilePath)],eventFunction?.default&&(eventFunction=eventFunction.default);let compactFilePath=eventFilePath.split(process.cwd())[1]||eventFilePath;if(typeof eventFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Event file ${compactFilePath} does not export a function.`));continue}eventObj.functions.push(eventFunction)}}}#registerEvents(){let client=this.#data.client,handler=this.#data.commandKitInstance;for(let eventObj of this.#data.events)client.on(eventObj.name,async(...params)=>{for(let eventFunction of eventObj.functions)if(await eventFunction(...params,client,handler))break})}get events(){return this.#data.events}async reloadEvents(commandHandler){if(!this.#data.eventsPath)throw new Error(colors_default.red('Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'));this.#data.events=[],await this.#buildEvents(),this.#data.client.removeAllListeners(),this.#registerEvents(),commandHandler?.handleCommands()}};var ValidationHandler=class{static{__name(this,"ValidationHandler")}#data;constructor({...options}){this.#data={...options,validations:[]}}async init(){this.#data.validations=await this.#buildValidations()}async#buildValidations(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,validationFilePaths=(await getFilePaths(this.#data.validationsPath,!0)).filter(path3=>allowedExtensions.test(path3)),validationFunctions=[];for(let validationFilePath of validationFilePaths){let importedFunction=(await import(`${toFileURL(validationFilePath)}?t=${Date.now()}`)).default,validationFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(validationFilePath)],validationFunction?.default&&(validationFunction=validationFunction.default);let compactFilePath=validationFilePath.split(process.cwd())[1]||validationFilePath;if(typeof validationFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Validation file ${compactFilePath} does not export a function.`));continue}validationFunctions.push(validationFunction)}return validationFunctions}get validations(){return this.#data.validations}async reloadValidations(){if(!this.#data.validationsPath)throw new Error(colors_default.red('Cannot reload validations as "validationsPath" was not provided when instantiating CommandKit.'));let newValidations=await this.#buildValidations();this.#data.validations=newValidations}};0&&(module.exports={CommandHandler,EventHandler,ValidationHandler});
|
|
10
|
+
`}let embed=new import_discord.EmbedBuilder().setTitle(":x: Missing permissions!").setDescription(embedDescription).setColor("Red");return interaction.reply({embeds:[embed],ephemeral:!0}),!0}__name(permissions_default,"default");var validations_default=[devOnly_default,permissions_default];var import_node_async_hooks=require("async_hooks");var CommandKitErrorCodes={GuildOnlyException:Symbol("kGuildOnlyException"),DMOnlyException:Symbol("kDMOnlyException"),CacheHit:Symbol("kCacheHit")};function isCommandKitError(error){if(!(error instanceof Error))return!1;let code=Reflect.get(error,"code");for(let key in CommandKitErrorCodes)if(CommandKitErrorCodes[key]===code)return!0;return!1}__name(isCommandKitError,"isCommandKitError");var context=new import_node_async_hooks.AsyncLocalStorage;function makeContextAwareFunction(env,fn,finalizer){return __name((...args)=>context.run(env,async()=>{try{let result=await fn(...args);return env.isCapturingResult()&&result!=null&&env.setResult(result),result}catch(e){if(isCommandKitError(e)){let code=Reflect.get(e,"code"),interaction=env.variables.get("interaction");if(!interaction)return;switch(code){case CommandKitErrorCodes.CacheHit:{let data=Reflect.get(e,"data");env.variables.set("cacheHit",!0),interaction.isCommand()&&(interaction.deferred?await interaction.editReply(data):interaction.isRepliable()&&await interaction.reply(data));return}case CommandKitErrorCodes.GuildOnlyException:{interaction.isRepliable()&&await interaction.reply({content:"This command is only available in guilds.",ephemeral:!0});return}case CommandKitErrorCodes.DMOnlyException:{interaction.isRepliable()&&await interaction.reply({content:"This command is only available in DMs.",ephemeral:!0});return}}return}env.setExecutionError(e)}finally{if(typeof finalizer=="function")try{await finalizer(...args)}catch{}}}),"_fn")}__name(makeContextAwareFunction,"makeContextAwareFunction");function getContext(){return context.getStore()}__name(getContext,"getContext");function useEnvironment(){let ctx=context.getStore();if(!ctx)throw new Error("No commandkit environment found. Please make sure you are inside commandkit handler.");return ctx}__name(useEnvironment,"useEnvironment");var import_node_crypto=require("crypto");var CommandKitEnvironment=class{constructor(commandkit){this.commandkit=commandkit}static{__name(this,"CommandKitEnvironment")}#data={executionError:null,type:null,variables:new Map,deferredFunctions:new Map,marker:"",markStart:0,markEnd:0,captureResult:!1,result:null};captureResult(){this.#data.captureResult=!0}isCapturingResult(){return this.#data.captureResult}setResult(result){this.#data.result=result}getResult(){return this.#data.result}getExecutionError(){return this.#data.executionError}setExecutionError(error){if(this.#data.executionError)throw new Error("Execution error already set.");this.#data.executionError=error}getType(){let type=this.#data.type;if(!type)throw new Error("Environment type not set.");return type}setType(type){this.#data.type=type}get variables(){return this.#data.variables}registerDeferredFunction(fn){let id=(0,import_node_crypto.randomUUID)();return this.#data.deferredFunctions.set(id,fn),id}clearDeferredFunction(id){this.#data.deferredFunctions.delete(id)}async runDeferredFunctions(){for(let[id,fn]of this.#data.deferredFunctions)try{await fn(this)}catch(e){this.commandkit.emit("unhandledDeferredFunctionRejection",e)}finally{this.clearDeferredFunction(id)}}clearAllDeferredFunctions(){this.#data.deferredFunctions.clear()}markStart(marker){this.#data.marker=marker,this.#data.markStart=performance.now()}markEnd(){this.#data.markEnd||(this.#data.markEnd=performance.now())}getMarker(){return this.#data.marker}getExecutionTime(){return Math.abs(this.#data.markEnd-this.#data.markStart)}};function after(fn){let env=getContext();if(!env)throw new Error("after must be called inside commandkit handler.");return env.registerDeferredFunction(fn)}__name(after,"after");var CommandHandler=class{static{__name(this,"CommandHandler")}#data;constructor({...options}){this.#data={...options,builtInValidations:[],commands:[]}}async init(){await this.#buildCommands(),this.#buildBuiltInValidations();let devOnlyCommands=this.#data.commands.filter(cmd=>cmd.options?.devOnly);devOnlyCommands.length&&!this.#data.devGuildIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devGuildIds" have not been set.')),devOnlyCommands.length&&!this.#data.devUserIds.length&&!this.#data.devRoleIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devUserIds" or "devRoleIds" have not been set.')),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}),this.handleCommands()}async#buildCommands(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,commandFilePaths=(await getFilePaths(this.#data.commandsPath,!0)).filter(path3=>allowedExtensions.test(path3));for(let commandFilePath of commandFilePaths){let importedObj=await import(`${toFileURL(commandFilePath)}?t=${Date.now()}`),commandObj=clone(importedObj);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(commandFilePath)];let compactFilePath=commandFilePath.split(process.cwd())[1]||commandFilePath;if(commandObj.default&&(commandObj=commandObj.default),importedObj.default?commandObj.data=importedObj.default.data:commandObj.data=importedObj.data,!commandObj.data){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data".`));continue}if(!commandObj.data.name){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data.name".`));continue}if(!commandObj.run){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run".`));continue}if(typeof commandObj.run!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run" as a function.`));continue}commandObj.filePath=commandFilePath;let commandCategory=commandFilePath.split(this.#data.commandsPath)[1]?.replace(/\\\\|\\/g,"/").split("/")[1]||null;commandCategory&&allowedExtensions.test(commandCategory)?commandObj.category=null:commandObj.category=commandCategory,this.#data.commands.push(commandObj)}}#buildBuiltInValidations(){for(let builtInValidationFunction of validations_default)this.#data.builtInValidations.push(builtInValidationFunction)}async#commandFinalizer(){let env=useEnvironment();await env.runDeferredFunctions(),env.clearAllDeferredFunctions()}async#interactionHandler(interaction){if(!interaction.isChatInputCommand()&&!interaction.isContextMenuCommand()&&!interaction.isAutocomplete())return;let isAutocomplete=interaction.isAutocomplete(),targetCommand=this.#data.commands.find(cmd=>cmd.data.name===interaction.commandName);if(!targetCommand)return;let env=useEnvironment();env.variables.set("interaction",interaction);let{data,options,run,autocomplete,...rest}=targetCommand;return isAutocomplete&&!autocomplete?void 0:__name(async()=>{let commandObj={data:targetCommand.data,options:targetCommand.options,...rest};if(this.#data.validationHandler){let canRun2=!0;for(let validationFunction of this.#data.validationHandler.validations)if(await validationFunction({interaction,commandObj,client:this.#data.client,handler:this.#data.commandkitInstance})){canRun2=!1;break}if(!canRun2)return}let canRun=!0;if(!this.#data.skipBuiltInValidations){for(let validation of this.#data.builtInValidations)if(validation({targetCommand,interaction,handlerData:this.#data})){canRun=!1;break}}if(!canRun)return;let command=targetCommand[isAutocomplete?"autocomplete":"run"],context2={interaction,client:this.#data.client,handler:this.#data.commandkitInstance};if(!this.#data.commandkitInstance.isDebuggingCommands())return command(context2);after(env2=>{let error=env2.getExecutionError(),marker=env2.getMarker(),time=env2.getExecutionTime().toFixed(2),cachedMarker=!!env2.variables.get("cacheHit")?" (cached)":"";if(error){console.error(colors_default.red(`[${marker} - ${time}]${cachedMarker} Error executing command: ${error}`));return}console.log(colors_default.green(`[${marker} - ${time}]${cachedMarker} Command executed successfully`))});try{return env.markStart(interaction.commandName),await command(context2)}finally{env.markEnd()}},"executor")()}handleCommands(){this.#data.client.on("interactionCreate",interaction=>{let env=new CommandKitEnvironment(this.#data.commandkitInstance);return env.setType("COMMAND_HANDLER"),makeContextAwareFunction(env,this.#interactionHandler.bind(this),this.#commandFinalizer.bind(this))(interaction)})}get commands(){return this.#data.commands}async reloadCommands(type){if(!this.#data.commandsPath)throw new Error(colors_default.red('Cannot reload commands as "commandsPath" was not provided when instantiating CommandKit.'));this.#data.commands=[],await this.#buildCommands(),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type})}};var EventHandler=class{static{__name(this,"EventHandler")}#data;constructor({...options}){this.#data={...options,events:[]}}async init(){await this.#buildEvents(),this.#registerEvents()}async#buildEvents(){let eventFolderPaths=await getFolderPaths(this.#data.eventsPath);for(let eventFolderPath of eventFolderPaths){let eventName=eventFolderPath.replace(/\\\\|\\/g,"/").split("/").pop(),allowedExtensions=/\.(js|mjs|cjs|ts)$/i,eventFilePaths=(await getFilePaths(eventFolderPath,!0)).filter(path3=>allowedExtensions.test(path3)),eventObj={name:eventName,functions:[]};this.#data.events.push(eventObj);for(let eventFilePath of eventFilePaths){let importedFunction=(await import(`${toFileURL(eventFilePath)}?t=${Date.now()}`)).default,eventFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(eventFilePath)],eventFunction?.default&&(eventFunction=eventFunction.default);let compactFilePath=eventFilePath.split(process.cwd())[1]||eventFilePath;if(typeof eventFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Event file ${compactFilePath} does not export a function.`));continue}eventObj.functions.push(eventFunction)}}}#registerEvents(){let client=this.#data.client,handler=this.#data.commandKitInstance;for(let eventObj of this.#data.events)client.on(eventObj.name,async(...params)=>{for(let eventFunction of eventObj.functions)if(await eventFunction(...params,client,handler))break})}get events(){return this.#data.events}async reloadEvents(commandHandler){if(!this.#data.eventsPath)throw new Error(colors_default.red('Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'));this.#data.events=[],await this.#buildEvents(),this.#data.client.removeAllListeners(),this.#registerEvents(),commandHandler?.handleCommands()}};var ValidationHandler=class{static{__name(this,"ValidationHandler")}#data;constructor({...options}){this.#data={...options,validations:[]}}async init(){this.#data.validations=await this.#buildValidations()}async#buildValidations(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,validationFilePaths=(await getFilePaths(this.#data.validationsPath,!0)).filter(path3=>allowedExtensions.test(path3)),validationFunctions=[];for(let validationFilePath of validationFilePaths){let importedFunction=(await import(`${toFileURL(validationFilePath)}?t=${Date.now()}`)).default,validationFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(validationFilePath)],validationFunction?.default&&(validationFunction=validationFunction.default);let compactFilePath=validationFilePath.split(process.cwd())[1]||validationFilePath;if(typeof validationFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Validation file ${compactFilePath} does not export a function.`));continue}validationFunctions.push(validationFunction)}return validationFunctions}get validations(){return this.#data.validations}async reloadValidations(){if(!this.#data.validationsPath)throw new Error(colors_default.red('Cannot reload validations as "validationsPath" was not provided when instantiating CommandKit.'));let newValidations=await this.#buildValidations();this.#data.validations=newValidations}};0&&(module.exports={CommandHandler,EventHandler,ValidationHandler});
|
|
11
11
|
//# sourceMappingURL=index.js.map
|