discommand
Advanced tools
+287
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __accessCheck = (obj, member, msg) => { | ||
| if (!member.has(obj)) | ||
| throw TypeError("Cannot " + msg); | ||
| }; | ||
| var __privateGet = (obj, member, getter) => { | ||
| __accessCheck(obj, member, "read from private field"); | ||
| return getter ? getter.call(obj) : member.get(obj); | ||
| }; | ||
| var __privateAdd = (obj, member, value) => { | ||
| if (member.has(obj)) | ||
| throw TypeError("Cannot add the same private member more than once"); | ||
| member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| }; | ||
| var __privateSet = (obj, member, value, setter) => { | ||
| __accessCheck(obj, member, "write to private field"); | ||
| setter ? setter.call(obj, value) : member.set(obj, value); | ||
| return value; | ||
| }; | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| Base: () => Base, | ||
| BaseHandler: () => BaseHandler, | ||
| BasePlugin: () => BasePlugin, | ||
| Command: () => Command, | ||
| DiscommandClient: () => DiscommandClient, | ||
| DiscommandHandler: () => DiscommandHandler, | ||
| Listener: () => Listener, | ||
| version: () => version | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| // src/discommandHandler.ts | ||
| var import_discord2 = require("discord.js"); | ||
| // src/bases/base.ts | ||
| var Base = class { | ||
| constructor(name) { | ||
| this.name = name; | ||
| } | ||
| }; | ||
| // src/bases/baseHandler.ts | ||
| var import_discord = require("discord.js"); | ||
| // src/listener.ts | ||
| var Listener = class extends Base { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.once = false; | ||
| } | ||
| }; | ||
| // src/bases/baseHandler.ts | ||
| var BaseHandler = class { | ||
| constructor(client, loader, guildID) { | ||
| this.client = client; | ||
| this.loader = loader; | ||
| this.guildID = guildID; | ||
| this.modules = new import_discord.Collection(); | ||
| this.client.on(import_discord.Events.InteractionCreate, async (interaction) => { | ||
| if (interaction.isChatInputCommand()) { | ||
| const command = this.modules.get(interaction.commandName); | ||
| if (!command) | ||
| return; | ||
| try { | ||
| await command.execute(interaction); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| } else if (interaction.isAutocomplete()) { | ||
| const command = this.modules.get(interaction.commandName); | ||
| if (!command) | ||
| return; | ||
| try { | ||
| await command.autocompleteExecute(interaction); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| register(modules) { | ||
| this.modules.set(modules.name, modules); | ||
| if (modules instanceof Listener) { | ||
| if (modules.once) { | ||
| this.client.once(modules.name, (...args) => { | ||
| modules.execute(...args); | ||
| }); | ||
| } else { | ||
| this.client.on(modules.name, (...args) => { | ||
| modules.execute(...args); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| deregister(moduleName, fileDir) { | ||
| this.modules.delete(moduleName); | ||
| if (fileDir) | ||
| delete require.cache[require.resolve(fileDir)]; | ||
| } | ||
| moduleType(module2) { | ||
| if (module2 instanceof Listener) { | ||
| return "Listener"; | ||
| } else { | ||
| switch (module2.data.type) { | ||
| case import_discord.ApplicationCommandType.ChatInput: | ||
| return "ChatInputCommand"; | ||
| case import_discord.ApplicationCommandType.User: | ||
| return "UserContextMenu"; | ||
| case import_discord.ApplicationCommandType.Message: | ||
| return "MessageContextMenu"; | ||
| case void 0: | ||
| return "ChatInputCommand"; | ||
| } | ||
| } | ||
| } | ||
| async load(modules) { | ||
| for (const module2 of modules) { | ||
| if (module2 instanceof Listener) { | ||
| this.register(module2); | ||
| console.log( | ||
| `[discommand]${this.guildID ? ` guild ${this.guildID}` : ""} ${this.moduleType(module2)} ${module2.name} is loaded.` | ||
| ); | ||
| } | ||
| } | ||
| this.client.once(import_discord.Events.ClientReady, async () => { | ||
| for (const module2 of modules) { | ||
| if (module2 instanceof Listener) { | ||
| return; | ||
| } | ||
| this.register(module2); | ||
| console.log( | ||
| `[discommand]${this.guildID ? ` guild ${this.guildID}` : ""} ${this.moduleType(module2)} ${module2.name} is loaded.` | ||
| ); | ||
| await this.client.application.commands.create( | ||
| module2.toJSON(), | ||
| module2.guildID || this.guildID | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
| deload(options) { | ||
| options.forEach((option) => { | ||
| const { module: module2, fileDir } = option; | ||
| this.deregister(module2.name, fileDir); | ||
| console.log( | ||
| `[discommand] ${this.moduleType(option.module)} ${module2.name} is deloaded.` | ||
| ); | ||
| }); | ||
| } | ||
| reload(options) { | ||
| options.forEach((option) => { | ||
| const { module: module2, fileDir } = option; | ||
| this.deregister(module2.name, fileDir); | ||
| this.loader.loadModule(fileDir).then((modules) => modules.forEach((module3) => this.register(module3))); | ||
| console.log( | ||
| `[discommand] ${this.moduleType(option.module)} ${module2.name} is reloaded.` | ||
| ); | ||
| }); | ||
| } | ||
| }; | ||
| // src/bases/basePlugin.ts | ||
| var BasePlugin = class { | ||
| start(client) { | ||
| return this; | ||
| } | ||
| }; | ||
| // src/discommandHandler.ts | ||
| var import_loader = require("@discommand/loader"); | ||
| var DiscommandHandler = class extends BaseHandler { | ||
| constructor(client, options) { | ||
| super(client, options.loader || new import_loader.ModuleLoader(), options.guildID); | ||
| this.client = client; | ||
| this.options = options; | ||
| this.modules = new import_discord2.Collection(); | ||
| } | ||
| loadAll() { | ||
| this.loader.loadModule(this.options.directory).then((modules) => this.load(modules)); | ||
| } | ||
| deloadAll() { | ||
| this.deload(this.loader.deloadModule(this.options.directory)); | ||
| } | ||
| reloadAll() { | ||
| this.reload(this.loader.reloadModule(this.options.directory)); | ||
| } | ||
| }; | ||
| // src/command.ts | ||
| var _guildID; | ||
| var Command = class extends Base { | ||
| constructor(data, guildID) { | ||
| super(data.name); | ||
| this.data = data; | ||
| __privateAdd(this, _guildID, void 0); | ||
| __privateSet(this, _guildID, guildID); | ||
| } | ||
| get guildID() { | ||
| return __privateGet(this, _guildID); | ||
| } | ||
| autocompleteExecute(interaction) { | ||
| return; | ||
| } | ||
| toJSON() { | ||
| return { ...this.data }; | ||
| } | ||
| }; | ||
| _guildID = new WeakMap(); | ||
| // src/discommandClient.ts | ||
| var import_discord3 = require("discord.js"); | ||
| var DiscommandClient = class extends import_discord3.Client { | ||
| constructor(clientOptions, discommandOptions) { | ||
| super(clientOptions); | ||
| this.discommandOptions = discommandOptions; | ||
| this.commandHandler = new DiscommandHandler(this, { | ||
| directory: discommandOptions.directory.command, | ||
| guildID: discommandOptions.guildID, | ||
| loader: discommandOptions.loader | ||
| }); | ||
| if (discommandOptions.directory.listener) { | ||
| this.listenerHandler = new DiscommandHandler(this, { | ||
| directory: discommandOptions.directory.listener, | ||
| loader: discommandOptions.loader | ||
| }); | ||
| } | ||
| } | ||
| loadAll() { | ||
| this.commandHandler.loadAll(); | ||
| if (this.listenerHandler) { | ||
| this.listenerHandler.loadAll(); | ||
| } | ||
| } | ||
| deloadAll() { | ||
| this.commandHandler.deloadAll(); | ||
| if (this.listenerHandler) { | ||
| this.listenerHandler.deloadAll(); | ||
| } | ||
| } | ||
| reloadAll() { | ||
| this.commandHandler.reloadAll(); | ||
| if (this.listenerHandler) { | ||
| this.listenerHandler.reloadAll(); | ||
| } | ||
| } | ||
| async login(token) { | ||
| this.loadAll(); | ||
| if (this.discommandOptions.plugins) | ||
| this.discommandOptions.plugins.forEach((plugin) => plugin.start(this)); | ||
| return super.login(token); | ||
| } | ||
| }; | ||
| // package.json | ||
| var version = "13.2.6"; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Base, | ||
| BaseHandler, | ||
| BasePlugin, | ||
| Command, | ||
| DiscommandClient, | ||
| DiscommandHandler, | ||
| Listener, | ||
| version | ||
| }); |
| import { Client, Collection, ClientOptions, ApplicationCommandData, Snowflake, CommandInteraction, AutocompleteInteraction } from 'discord.js'; | ||
| import { BaseModuleLoader, DeloadOptions, ReloadOptions } from '@discommand/loader'; | ||
| declare abstract class Base { | ||
| readonly name: string; | ||
| protected constructor(name: string); | ||
| abstract execute(...options: unknown[]): unknown; | ||
| } | ||
| declare abstract class BaseHandler { | ||
| readonly client: Client; | ||
| loader: BaseModuleLoader; | ||
| readonly guildID?: string | undefined; | ||
| readonly modules: Collection<string, ModuleType>; | ||
| protected constructor(client: Client, loader: BaseModuleLoader, guildID?: string | undefined); | ||
| private register; | ||
| private deregister; | ||
| private moduleType; | ||
| load(modules: ModuleType[]): Promise<void>; | ||
| deload(options: DeloadOptions<ModuleType>[]): void; | ||
| reload(options: ReloadOptions<ModuleType>[]): void; | ||
| } | ||
| declare class DiscommandClient extends Client { | ||
| readonly discommandOptions: DiscommandClientOptions; | ||
| commandHandler: DiscommandHandler; | ||
| listenerHandler?: DiscommandHandler; | ||
| constructor(clientOptions: ClientOptions, discommandOptions: DiscommandClientOptions); | ||
| loadAll(): void; | ||
| deloadAll(): void; | ||
| reloadAll(): void; | ||
| login(token?: string): Promise<string>; | ||
| } | ||
| declare abstract class BasePlugin { | ||
| start(client: DiscommandClient): this; | ||
| } | ||
| declare abstract class Command extends Base { | ||
| #private; | ||
| readonly data: ApplicationCommandData; | ||
| get guildID(): string | undefined; | ||
| protected constructor(data: ApplicationCommandData, guildID?: Snowflake); | ||
| abstract execute(interaction: CommandInteraction): unknown; | ||
| autocompleteExecute(interaction: AutocompleteInteraction): unknown; | ||
| toJSON(): ApplicationCommandData; | ||
| } | ||
| declare abstract class Listener extends Base { | ||
| once: boolean; | ||
| } | ||
| interface directory { | ||
| command: string; | ||
| listener?: string; | ||
| } | ||
| interface DiscommandHandlerOptions { | ||
| directory: string; | ||
| guildID?: Snowflake; | ||
| loader?: BaseModuleLoader; | ||
| } | ||
| interface DiscommandClientOptions { | ||
| directory: directory; | ||
| guildID?: Snowflake; | ||
| plugins?: Array<BasePlugin>; | ||
| loader?: BaseModuleLoader; | ||
| } | ||
| type ModuleType = Command | Listener; | ||
| declare module 'discord.js' { | ||
| interface Client { | ||
| commandHandler: DiscommandHandler; | ||
| listenerHandler?: DiscommandHandler; | ||
| loadAll(): void; | ||
| deloadAll(): void; | ||
| reloadAll(): void; | ||
| } | ||
| } | ||
| declare class DiscommandHandler extends BaseHandler { | ||
| client: Client; | ||
| readonly options: DiscommandHandlerOptions; | ||
| modules: Collection<string, ModuleType>; | ||
| constructor(client: Client, options: DiscommandHandlerOptions); | ||
| loadAll(): void; | ||
| deloadAll(): void; | ||
| reloadAll(): void; | ||
| } | ||
| var version = "13.2.6"; | ||
| export { Base, BaseHandler, BasePlugin, Command, DiscommandClient, type DiscommandClientOptions, DiscommandHandler, type DiscommandHandlerOptions, Listener, type ModuleType, type directory, version }; |
+3
-3
| import { Client, Collection, ClientOptions, ApplicationCommandData, Snowflake, CommandInteraction, AutocompleteInteraction } from 'discord.js'; | ||
| import { DeloadOptions, ReloadOptions, BaseModuleLoader } from '@discommand/loader'; | ||
| import { BaseModuleLoader, DeloadOptions, ReloadOptions } from '@discommand/loader'; | ||
@@ -12,5 +12,6 @@ declare abstract class Base { | ||
| readonly client: Client; | ||
| loader: BaseModuleLoader; | ||
| readonly guildID?: string | undefined; | ||
| readonly modules: Collection<string, ModuleType>; | ||
| protected constructor(client: Client, guildID?: string | undefined); | ||
| protected constructor(client: Client, loader: BaseModuleLoader, guildID?: string | undefined); | ||
| private register; | ||
@@ -83,3 +84,2 @@ private deregister; | ||
| modules: Collection<string, ModuleType>; | ||
| loader: BaseModuleLoader; | ||
| constructor(client: Client, options: DiscommandHandlerOptions); | ||
@@ -86,0 +86,0 @@ loadAll(): void; |
+9
-12
@@ -30,3 +30,3 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| // src/Bases/base.ts | ||
| // src/bases/base.ts | ||
| var Base = class { | ||
@@ -38,3 +38,3 @@ constructor(name) { | ||
| // src/Bases/baseHandler.ts | ||
| // src/bases/baseHandler.ts | ||
| import { | ||
@@ -54,9 +54,7 @@ Collection, | ||
| // src/Bases/baseHandler.ts | ||
| import { | ||
| ModuleLoader | ||
| } from "@discommand/loader"; | ||
| // src/bases/baseHandler.ts | ||
| var BaseHandler = class { | ||
| constructor(client, guildID) { | ||
| constructor(client, loader, guildID) { | ||
| this.client = client; | ||
| this.loader = loader; | ||
| this.guildID = guildID; | ||
@@ -159,3 +157,3 @@ this.modules = new Collection(); | ||
| this.deregister(module.name, fileDir); | ||
| new ModuleLoader().loadModule(fileDir).then((modules) => modules.forEach((module2) => this.register(module2))); | ||
| this.loader.loadModule(fileDir).then((modules) => modules.forEach((module2) => this.register(module2))); | ||
| console.log( | ||
@@ -168,3 +166,3 @@ `[discommand] ${this.moduleType(option.module)} ${module.name} is reloaded.` | ||
| // src/Bases/basePlugin.ts | ||
| // src/bases/basePlugin.ts | ||
| var BasePlugin = class { | ||
@@ -177,10 +175,9 @@ start(client) { | ||
| // src/discommandHandler.ts | ||
| import { ModuleLoader as ModuleLoader2 } from "@discommand/loader"; | ||
| import { ModuleLoader } from "@discommand/loader"; | ||
| var DiscommandHandler = class extends BaseHandler { | ||
| constructor(client, options) { | ||
| super(client, options.guildID); | ||
| super(client, options.loader || new ModuleLoader(), options.guildID); | ||
| this.client = client; | ||
| this.options = options; | ||
| this.modules = new Collection2(); | ||
| this.loader = options.loader || new ModuleLoader2(); | ||
| } | ||
@@ -187,0 +184,0 @@ loadAll() { |
+0
-0
@@ -0,0 +0,0 @@ MIT License |
+11
-5
| { | ||
| "name": "discommand", | ||
| "version": "13.2.6", | ||
| "version": "13.2.7", | ||
| "type": "module", | ||
@@ -10,4 +10,10 @@ "description": "easy discord.js command handler.", | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js" | ||
| "import": { | ||
| "types": "./dist/index.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
@@ -22,6 +28,6 @@ }, | ||
| }, | ||
| "author": "Migan178 <migan9857@gmail.com>", | ||
| "author": "Migan178 <me@migan.co.kr>", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "@discommand/loader": "^0.1.0", | ||
| "@discommand/loader": "^0.1.1", | ||
| "@types/node": "^20.11.5", | ||
@@ -28,0 +34,0 @@ "@typescript-eslint/eslint-plugin": "^6.19.0", |
+0
-0
@@ -0,0 +0,0 @@ # discommand |
26112
75.93%7
40%612
80.53%