commandkit
Advanced tools
Comparing version
import 'discord.js'; | ||
export { C as CommandKit } from './CommandKit-ltSQg1YI.js'; | ||
export { C as CommandKit } from './CommandKit-5A-bV3Vk.js'; | ||
import './handlers/validation-handler/ValidationHandler.js'; | ||
import './handlers/validation-handler/typings.js'; |
@@ -1,4 +0,4 @@ | ||
export { p as CommandHandler, o as hCommandContext } from '../../CommandKit-ltSQg1YI.js'; | ||
export { p as CommandHandler, o as hCommandContext } from '../../CommandKit-5A-bV3Vk.js'; | ||
import '../validation-handler/ValidationHandler.js'; | ||
import '../validation-handler/typings.js'; | ||
import 'discord.js'; |
import { Client } from 'discord.js'; | ||
import { d as CommandFileObject, R as ReloadOptions } from '../../../CommandKit-ltSQg1YI.js'; | ||
import { d as CommandFileObject, R as ReloadOptions } from '../../../CommandKit-5A-bV3Vk.js'; | ||
import '../../validation-handler/ValidationHandler.js'; | ||
@@ -4,0 +4,0 @@ import '../../validation-handler/typings.js'; |
import { Client } from 'discord.js'; | ||
import { d as CommandFileObject, R as ReloadOptions } from '../../../CommandKit-ltSQg1YI.js'; | ||
import { d as CommandFileObject, R as ReloadOptions } from '../../../CommandKit-5A-bV3Vk.js'; | ||
import '../../validation-handler/ValidationHandler.js'; | ||
@@ -4,0 +4,0 @@ import '../../validation-handler/typings.js'; |
import 'discord.js'; | ||
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-ltSQg1YI.js'; | ||
export { n as BuiltInValidation, B as BuiltInValidationParams, l as CommandHandlerData, k as CommandHandlerOptions, m as CommandKitInteraction } from '../../CommandKit-5A-bV3Vk.js'; | ||
import '../validation-handler/ValidationHandler.js'; | ||
import '../validation-handler/typings.js'; |
@@ -1,2 +0,2 @@ | ||
import { B as BuiltInValidationParams } from '../../../CommandKit-ltSQg1YI.js'; | ||
import { B as BuiltInValidationParams } from '../../../CommandKit-5A-bV3Vk.js'; | ||
import '../../validation-handler/ValidationHandler.js'; | ||
@@ -3,0 +3,0 @@ import '../../validation-handler/typings.js'; |
import export_default from './devOnly.js'; | ||
import '../../../CommandKit-ltSQg1YI.js'; | ||
import '../../../CommandKit-5A-bV3Vk.js'; | ||
import '../../validation-handler/ValidationHandler.js'; | ||
@@ -4,0 +4,0 @@ import '../../validation-handler/typings.js'; |
@@ -1,2 +0,2 @@ | ||
import { B as BuiltInValidationParams } from '../../../CommandKit-ltSQg1YI.js'; | ||
import { B as BuiltInValidationParams } from '../../../CommandKit-5A-bV3Vk.js'; | ||
import '../../validation-handler/ValidationHandler.js'; | ||
@@ -3,0 +3,0 @@ import '../../validation-handler/typings.js'; |
@@ -1,4 +0,4 @@ | ||
export { r as EventHandler } from '../../CommandKit-ltSQg1YI.js'; | ||
export { r as EventHandler } from '../../CommandKit-5A-bV3Vk.js'; | ||
import '../validation-handler/ValidationHandler.js'; | ||
import '../validation-handler/typings.js'; | ||
import 'discord.js'; |
import 'discord.js'; | ||
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-ltSQg1YI.js'; | ||
export { q as EventHandlerData, E as EventHandlerOptions } from '../../CommandKit-5A-bV3Vk.js'; | ||
import '../validation-handler/ValidationHandler.js'; | ||
import '../validation-handler/typings.js'; |
@@ -1,4 +0,4 @@ | ||
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-ltSQg1YI.js'; | ||
export { p as CommandHandler, r as EventHandler, o as hCommandContext } from '../CommandKit-5A-bV3Vk.js'; | ||
export { ValidationHandler } from './validation-handler/ValidationHandler.js'; | ||
import 'discord.js'; | ||
import './validation-handler/typings.js'; |
@@ -1,2 +0,2 @@ | ||
export { A as AutocompleteProps, c as CommandContext, h as CommandData, d as CommandFileObject, C as CommandKit, b as CommandKitData, a as CommandKitOptions, i as CommandObject, g as CommandOptions, e as CommandProps, f as ContextMenuCommandProps, M as MessageContextMenuCommandProps, R as ReloadOptions, j as ReloadType, S as SlashCommandProps, U as UserContextMenuCommandProps, V as ValidationProps } from './CommandKit-ltSQg1YI.js'; | ||
export { A as AutocompleteProps, c as CommandContext, h as CommandData, d as CommandFileObject, C as CommandKit, b as CommandKitData, a as CommandKitOptions, i as CommandObject, g as CommandOptions, e as CommandProps, f as ContextMenuCommandProps, M as MessageContextMenuCommandProps, R as ReloadOptions, j as ReloadType, S as SlashCommandProps, U as UserContextMenuCommandProps, V as ValidationProps } from './CommandKit-5A-bV3Vk.js'; | ||
export { ButtonKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd } from './components/ButtonKit.js'; | ||
@@ -3,0 +3,0 @@ export { CommandKitConfig, defineConfig, getConfig } from './config.js'; |
@@ -10,3 +10,3 @@ "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 src_exports={};__export(src_exports,{ButtonKit:()=>ButtonKit,CommandKit:()=>CommandKit,defineConfig:()=>defineConfig,getConfig:()=>getConfig,version:()=>version});module.exports=__toCommonJS(src_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}`};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. | ||
`}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. | ||
`}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}};var CommandKit=class _CommandKit{static{__name(this,"CommandKit")}#data;static _instance=null;constructor(options){if(!options.client)throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));if(options.validationsPath&&!options.commandsPath)throw new Error(colors_default.red('"commandsPath" is required when "validationsPath" is set.'));this.#data=options,_CommandKit._instance=this,this.#init()}get client(){return this.#data.client}get commandHandler(){return this.#data.commandHandler}async#init(){if(this.#data.eventsPath){let eventHandler=new EventHandler({client:this.#data.client,eventsPath:this.#data.eventsPath,commandKitInstance:this});await eventHandler.init(),this.#data.eventHandler=eventHandler}if(this.#data.validationsPath){let validationHandler=new ValidationHandler({validationsPath:this.#data.validationsPath});await validationHandler.init(),this.#data.validationHandler=validationHandler}if(this.#data.commandsPath){let commandHandler=new CommandHandler({client:this.#data.client,commandsPath:this.#data.commandsPath,devGuildIds:this.#data.devGuildIds||[],devUserIds:this.#data.devUserIds||[],devRoleIds:this.#data.devRoleIds||[],validationHandler:this.#data.validationHandler,skipBuiltInValidations:this.#data.skipBuiltInValidations||!1,commandkitInstance:this,bulkRegister:this.#data.bulkRegister||!1});await commandHandler.init(),this.#data.commandHandler=commandHandler}}async reloadCommands(type){this.#data.commandHandler&&await this.#data.commandHandler.reloadCommands(type)}async reloadEvents(){this.#data.eventHandler&&await this.#data.eventHandler.reloadEvents(this.#data.commandHandler)}async reloadValidations(){this.#data.validationHandler&&await this.#data.validationHandler.reloadValidations()}get commands(){return this.#data.commandHandler?this.#data.commandHandler.commands.map(cmd=>{let{run,autocomplete,...command}=cmd;return command}):[]}get commandsPath(){return this.#data.commandsPath}get eventsPath(){return this.#data.eventsPath}get validationsPath(){return this.#data.validationsPath}get devUserIds(){return this.#data.devUserIds||[]}get devGuildIds(){return this.#data.devGuildIds||[]}get devRoleIds(){return this.#data.devRoleIds||[]}};var import_discord2=require("discord.js");var ButtonKit=class extends import_discord2.ButtonBuilder{static{__name(this,"ButtonKit")}#onClickHandler=null;#onEndHandler=null;#contextData=null;#collector=null;onClick(handler,data){if(this.data.style===import_discord2.ButtonStyle.Link)throw new TypeError('Cannot setup "onClick" handler on link buttons.');if(!handler)throw new TypeError('Cannot setup "onClick" without a handler function parameter.');return this.#destroyCollector(),this.#onClickHandler=handler,data&&(this.#contextData=data),this.#setupInteractionCollector(),this}onEnd(handler){if(!handler)throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');return this.#onEndHandler=handler,this}#setupInteractionCollector(){if(!this.#contextData||!this.#onClickHandler)return;let message=this.#contextData.message;if(!message)throw new TypeError('Cannot setup "onClick" handler without a message in the context data.');if("customId"in this.data&&!this.data.customId)throw new TypeError('Cannot setup "onClick" handler on a button without a custom id.');let data={time:864e5,autoReset:!0,...this.#contextData},collector=this.#collector=message.createMessageComponentCollector({filter:interaction=>interaction.customId===this.data.custom_id&&interaction.message.id===message.id,componentType:import_discord2.ComponentType.Button,...data});this.#collector.on("collect",interaction=>{let handler=this.#onClickHandler;return handler?this.#collector?(data.autoReset&&this.#collector.resetTimer(),handler(interaction)):collector.stop("destroyed"):this.#destroyCollector()}),this.#collector.on("end",()=>{this.#destroyCollector(),this.#onEndHandler?.()})}dispose(){return this.#destroyCollector(),this.#onEndHandler?.(),this}#destroyCollector(){this.#collector?.stop("end"),this.#collector?.removeAllListeners(),this.#collector=null,this.#contextData=null,this.#onClickHandler=null}};var globalConfig={envExtra:!0,outDir:"dist",watch:!0,clearRestartLogs:!0,minify:!1,sourcemap:!1,nodeOptions:[],antiCrash:!0,requirePolyfill:!0};function getConfig(){return globalConfig}__name(getConfig,"getConfig");var requiredProps=["src","main"];function defineConfig(config){for(let prop of requiredProps)if(!config[prop])throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);return globalConfig={...globalConfig,...config},globalConfig}__name(defineConfig,"defineConfig");var version="0.1.11-dev.20241214184659";0&&(module.exports={ButtonKit,CommandKit,defineConfig,getConfig,version}); | ||
`}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}};var CommandKit=class _CommandKit{static{__name(this,"CommandKit")}#data;static _instance=null;constructor(options){if(!options.client)throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));if(options.validationsPath&&!options.commandsPath)throw new Error(colors_default.red('"commandsPath" is required when "validationsPath" is set.'));this.#data=options,_CommandKit._instance=this,this.#init()}get client(){return this.#data.client}get commandHandler(){return this.#data.commandHandler}async#init(){if(this.#data.eventsPath){let eventHandler=new EventHandler({client:this.#data.client,eventsPath:this.#data.eventsPath,commandKitInstance:this});await eventHandler.init(),this.#data.eventHandler=eventHandler}if(this.#data.validationsPath){let validationHandler=new ValidationHandler({validationsPath:this.#data.validationsPath});await validationHandler.init(),this.#data.validationHandler=validationHandler}if(this.#data.commandsPath){let commandHandler=new CommandHandler({client:this.#data.client,commandsPath:this.#data.commandsPath,devGuildIds:this.#data.devGuildIds||[],devUserIds:this.#data.devUserIds||[],devRoleIds:this.#data.devRoleIds||[],validationHandler:this.#data.validationHandler,skipBuiltInValidations:this.#data.skipBuiltInValidations||!1,commandkitInstance:this,bulkRegister:this.#data.bulkRegister||!1});await commandHandler.init(),this.#data.commandHandler=commandHandler}}async reloadCommands(type){this.#data.commandHandler&&await this.#data.commandHandler.reloadCommands(type)}async reloadEvents(){this.#data.eventHandler&&await this.#data.eventHandler.reloadEvents(this.#data.commandHandler)}async reloadValidations(){this.#data.validationHandler&&await this.#data.validationHandler.reloadValidations()}get commands(){return this.#data.commandHandler?this.#data.commandHandler.commands.map(cmd=>{let{run,autocomplete,...command}=cmd;return command}):[]}get commandsPath(){return this.#data.commandsPath}get eventsPath(){return this.#data.eventsPath}get validationsPath(){return this.#data.validationsPath}get devUserIds(){return this.#data.devUserIds||[]}get devGuildIds(){return this.#data.devGuildIds||[]}get devRoleIds(){return this.#data.devRoleIds||[]}};var import_discord2=require("discord.js");var ButtonKit=class extends import_discord2.ButtonBuilder{static{__name(this,"ButtonKit")}#onClickHandler=null;#onEndHandler=null;#contextData=null;#collector=null;onClick(handler,data){if(this.data.style===import_discord2.ButtonStyle.Link)throw new TypeError('Cannot setup "onClick" handler on link buttons.');if(!handler)throw new TypeError('Cannot setup "onClick" without a handler function parameter.');return this.#destroyCollector(),this.#onClickHandler=handler,data&&(this.#contextData=data),this.#setupInteractionCollector(),this}onEnd(handler){if(!handler)throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');return this.#onEndHandler=handler,this}#setupInteractionCollector(){if(!this.#contextData||!this.#onClickHandler)return;let message=this.#contextData.message;if(!message)throw new TypeError('Cannot setup "onClick" handler without a message in the context data.');if("customId"in this.data&&!this.data.customId)throw new TypeError('Cannot setup "onClick" handler on a button without a custom id.');let data={time:864e5,autoReset:!0,...this.#contextData},collector=this.#collector=message.createMessageComponentCollector({filter:interaction=>interaction.customId===this.data.custom_id&&interaction.message.id===message.id,componentType:import_discord2.ComponentType.Button,...data});this.#collector.on("collect",interaction=>{let handler=this.#onClickHandler;return handler?this.#collector?(data.autoReset&&this.#collector.resetTimer(),handler(interaction)):collector.stop("destroyed"):this.#destroyCollector()}),this.#collector.on("end",()=>{this.#destroyCollector(),this.#onEndHandler?.()})}dispose(){return this.#destroyCollector(),this.#onEndHandler?.(),this}#destroyCollector(){this.#collector?.stop("end"),this.#collector?.removeAllListeners(),this.#collector=null,this.#contextData=null,this.#onClickHandler=null}};var globalConfig={envExtra:!0,outDir:"dist",watch:!0,clearRestartLogs:!0,minify:!1,sourcemap:!1,nodeOptions:[],antiCrash:!0,requirePolyfill:!0};function getConfig(){return globalConfig}__name(getConfig,"getConfig");var requiredProps=["src","main"];function defineConfig(config){for(let prop of requiredProps)if(!config[prop])throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);return globalConfig={...globalConfig,...config},globalConfig}__name(defineConfig,"defineConfig");var version="0.1.11-dev.20241214191224";0&&(module.exports={ButtonKit,CommandKit,defineConfig,getConfig,version}); | ||
//# sourceMappingURL=index.js.map |
import 'discord.js'; | ||
export { A as AutocompleteProps, c as CommandContext, h as CommandData, d as CommandFileObject, b as CommandKitData, a as CommandKitOptions, i as CommandObject, g as CommandOptions, e as CommandProps, f as ContextMenuCommandProps, M as MessageContextMenuCommandProps, R as ReloadOptions, j as ReloadType, S as SlashCommandProps, U as UserContextMenuCommandProps, V as ValidationProps } from './CommandKit-ltSQg1YI.js'; | ||
export { A as AutocompleteProps, c as CommandContext, h as CommandData, d as CommandFileObject, b as CommandKitData, a as CommandKitOptions, i as CommandObject, g as CommandOptions, e as CommandProps, f as ContextMenuCommandProps, M as MessageContextMenuCommandProps, R as ReloadOptions, j as ReloadType, S as SlashCommandProps, U as UserContextMenuCommandProps, V as ValidationProps } from './CommandKit-5A-bV3Vk.js'; | ||
import './handlers/validation-handler/ValidationHandler.js'; | ||
import './handlers/validation-handler/typings.js'; |
{ | ||
"name": "commandkit", | ||
"description": "Beginner friendly command & event handler for Discord.js", | ||
"version": "0.1.11-dev.20241214184659", | ||
"version": "0.1.11-dev.20241214191224", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "main": "./dist/index.js", | ||
}, | ||
"homepage": "https://commandkit.js.org", | ||
"homepage": "https://commandkit.dev", | ||
"keywords": [ | ||
@@ -41,0 +41,0 @@ "discord.js", |
@@ -27,3 +27,3 @@ <div align="center"> | ||
You can find the full documentation [here](https://commandkit.js.org). | ||
You can find the full documentation [here](https://commandkit.dev). | ||
@@ -66,3 +66,3 @@ ## Installation | ||
This is a simple overview of how to set up this library with all the options. You can read more in the [full documentation](https://commandkit.js.org) | ||
This is a simple overview of how to set up this library with all the options. You can read more in the [full documentation](https://commandkit.dev) | ||
@@ -69,0 +69,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
611134
0