diff --git a/src/struct/NaticoClient.ts b/src/struct/NaticoClient.ts index eefa7fb..64963fe 100644 --- a/src/struct/NaticoClient.ts +++ b/src/struct/NaticoClient.ts @@ -1,14 +1,14 @@ import { BotConfig, botId, EventEmitter, startBot } from "../../deps.ts"; import { Events } from "../util/Interfaces.ts"; -import { ClientUtil } from "../util/ClientUtil.ts"; +import { NaticoClientUtil } from "../util/ClientUtil.ts"; export class NaticoClient extends EventEmitter { events: Events = {}; - util!: ClientUtil; + util!: NaticoClientUtil; id = botId; constructor(public config?: NaticoClientOptions) { super(); this.events = {}; - if (this.config?.util) this.util = new ClientUtil(this); + if (this.config?.util) this.util = new NaticoClientUtil(this); } /** * diff --git a/src/struct/commands/Command.ts b/src/struct/commands/Command.ts index 185b45c..e792ccb 100644 --- a/src/struct/commands/Command.ts +++ b/src/struct/commands/Command.ts @@ -16,7 +16,8 @@ export class NaticoCommand extends NaticoModule { enabled: boolean | undefined; superUserOnly: boolean | undefined; options?: ArgOptions[]; - permissions: PermissionStrings[] | undefined; + clientPermissions: PermissionStrings[] | undefined; + UserPermissions: PermissionStrings[] | undefined; constructor( id: string, @@ -25,14 +26,13 @@ export class NaticoCommand extends NaticoModule { aliases, examples, description, - enabled = true, slash, - required, category, ownerOnly, superUserOnly, options, - permissions, + clientPermissions, + UserPermissions, }: { options?: ArgOptions[]; @@ -40,27 +40,24 @@ export class NaticoCommand extends NaticoModule { aliases?: string[]; examples?: string[]; description?: string; - enabled?: boolean; slash?: boolean; - required?: boolean; category?: string; ownerOnly?: boolean; superUserOnly?: boolean; - permissions?: PermissionStrings[]; + clientPermissions?: PermissionStrings[]; + UserPermissions?: PermissionStrings[]; } ) { super(id); this.options = options; this.superUserOnly = superUserOnly; - this.enabled = enabled; this.slash = slash; this.description = description; - this.required = required; this.ownerOnly = ownerOnly; this.name = name?.toLowerCase() || id.toLowerCase(); this.examples = examples || [`${name}`]; - this.permissions = permissions; - + this.clientPermissions = clientPermissions; + this.UserPermissions = UserPermissions; this.id = id; this.aliases = aliases || [this.id]; diff --git a/src/struct/commands/CommandHandler.ts b/src/struct/commands/CommandHandler.ts index 7e53787..a01fb05 100644 --- a/src/struct/commands/CommandHandler.ts +++ b/src/struct/commands/CommandHandler.ts @@ -6,6 +6,7 @@ import { EditGlobalApplicationCommand, hasGuildPermissions, upsertSlashCommands, + botId, } from "../../../deps.ts"; import { NaticoClient } from "../NaticoClient.ts"; import { ArgumentGenerator } from "./ArgumentGenerator.ts"; @@ -14,6 +15,7 @@ import { NaticoCommand } from "./Command.ts"; import { NaticoSubCommand } from "./SubCommand.ts"; import { NaticoHandler } from "../NaticoHandler.ts"; import { ConvertedOptions, prefixFn, ArgOptions } from "../../util/Interfaces.ts"; +import { CommandHandlerEvents } from "../../util/Constants.ts"; export class NaticoCommandHandler extends NaticoHandler { modules: Collection; cooldowns: Set; @@ -110,51 +112,43 @@ export class NaticoCommandHandler extends NaticoHandler { } const authorId = message.authorId.toString(); if (!this.superusers.includes(authorId)) { - if (!command.enabled) { - if (!this.superusers.includes(authorId)) { - this.emit("disabled", message, command, args); - return true; - } - } - if (this.cooldowns.has(authorId)) { if (!this.IgnoreCD.includes(authorId)) { - this.emit("cooldownBlocked", message, command, args); + this.emit(CommandHandlerEvents.COOLDOWN, message, command, args); return true; } } if (this.guildonly) { if (!message.guildId) { - this.emit("guildOnly", message, command, args); + this.emit(CommandHandlerEvents.GUILDONLY, message, command, args); return true; } } - if (command.required) { - if (!args) { - this.emit("required", message, command); + if (command.UserPermissions) { + if (!hasGuildPermissions(message!.guildId, message.authorId, command.UserPermissions)) { + this.emit(CommandHandlerEvents.USERPERMISSIONS, message, command, args); return true; } } - - if (command.permissions) { - if (!hasGuildPermissions(message!.guildId, message.authorId, command.permissions)) { - this.emit("userPermissions", message, command, args); + if (command.clientPermissions) { + if (!hasGuildPermissions(message!.guildId, botId, command.clientPermissions)) { + this.emit(CommandHandlerEvents.CLIENTPERMISSIONS, message, command, args); return true; } } } if (command.ownerOnly) { if (!this.owners.includes(authorId)) { - this.emit("ownerOnly", message, command, args); + this.emit(CommandHandlerEvents.OWNERONLY, message, command, args); return true; } } if (command.superUserOnly) { if (!this.superusers.includes(authorId)) { - this.emit("superUserOnly", message, command, args); + this.emit(CommandHandlerEvents.SUPERUSERRONLY, message, command, args); return true; } } @@ -192,7 +186,8 @@ export class NaticoCommandHandler extends NaticoHandler { return false; }); if (mod) { - return this.runCommand(mod, message, args.split(" ").slice(1).join(" ")); + this.runCommand(mod, message, args.split(" ").slice(1).join(" ")); + return; } } } @@ -205,11 +200,11 @@ export class NaticoCommandHandler extends NaticoHandler { this.emit("commandStarted", message, command, data); - sub + const res = sub ? //@ts-ignore - await command[sub](message, data) : await command.exec(message, data); - this.emit("commandEnded", message, command, data); + this.emit("commandEnded", message, command, data, res); /** * Adding the user to a set and deleting them later! */ diff --git a/src/struct/commands/SubCommand.ts b/src/struct/commands/SubCommand.ts index 941e56d..5e98a36 100644 --- a/src/struct/commands/SubCommand.ts +++ b/src/struct/commands/SubCommand.ts @@ -22,7 +22,8 @@ export class NaticoSubCommand extends NaticoCommand { * The main command */ subOf, - permissions, + clientPermissions, + UserPermissions, }: { options?: ArgOptions[]; subOf: string; @@ -36,7 +37,8 @@ export class NaticoSubCommand extends NaticoCommand { category?: string; ownerOnly?: boolean; superUserOnly?: boolean; - permissions?: PermissionStrings[]; + clientPermissions?: PermissionStrings[]; + UserPermissions?: PermissionStrings[]; } ) { super(id, { @@ -51,7 +53,8 @@ export class NaticoSubCommand extends NaticoCommand { ownerOnly, superUserOnly, options, - permissions, + clientPermissions, + UserPermissions, }); this.subOf = subOf; } diff --git a/src/util/ClientUtil.ts b/src/util/ClientUtil.ts index e8d3c2d..449de86 100644 --- a/src/util/ClientUtil.ts +++ b/src/util/ClientUtil.ts @@ -1,7 +1,7 @@ import { NaticoEmbed } from "./Embed.ts"; import { NaticoClient } from "../struct/NaticoClient.ts"; -export class ClientUtil { +export class NaticoClientUtil { client: NaticoClient; constructor(client: NaticoClient) { this.client = client; diff --git a/src/util/Constants.ts b/src/util/Constants.ts new file mode 100644 index 0000000..ce0abda --- /dev/null +++ b/src/util/Constants.ts @@ -0,0 +1,11 @@ +export enum CommandHandlerEvents { + COOLDOWN = "cooldownBlocked", + GUILDONLY = "guildOnly", + USERPERMISSIONS = "userPermissions", + CLIENTPERMISSIONS = "clientPermissions", + OWNERONLY = "owerOnly", + SUPERUSERRONLY = "superUserOnly", + COMMANDSTARTED = "commandStarted", + COMMANDENDED = "commandEnded", + COMMANDERROR = "commandError", +} diff --git a/src/util/Interfaces.ts b/src/util/Interfaces.ts index ee5c466..06f477c 100644 --- a/src/util/Interfaces.ts +++ b/src/util/Interfaces.ts @@ -9,13 +9,10 @@ export interface prefixFn { (message: DiscordenoMessage): string | string[] | Promise; } export interface ArgOptions extends ApplicationCommandOption { - match?: matches; + match?: Matches; customType?: customType; } -export type customType = ( - message: DiscordenoMessage, - content: string, -) => any | Promise; +export type customType = (message: DiscordenoMessage, content: string) => any | Promise; export enum Matches { rest,