diff --git a/example/modules/Commands/Avatar.js b/example/modules/Commands/Avatar.js index 0c9ab8e9..05f16bfc 100644 --- a/example/modules/Commands/Avatar.js +++ b/example/modules/Commands/Avatar.js @@ -5,7 +5,6 @@ import { ContextMenuCommandBuilder } from "reciple"; * @type {import("reciple").RecipleModuleData} */ export default { - versions: '^9', commands: [ new ContextMenuCommandBuilder() .setName('Avatar') diff --git a/example/modules/Commands/Ping.js b/example/modules/Commands/Ping.js index ba2c03b1..c9b04a57 100644 --- a/example/modules/Commands/Ping.js +++ b/example/modules/Commands/Ping.js @@ -5,7 +5,6 @@ import { MessageCommandBuilder } from 'reciple'; * @type {import('reciple').RecipleModuleData} */ export default { - versions: ['^9'], commands: [ new MessageCommandBuilder() .setName('ping') diff --git a/example/modules/Commands/Say.js b/example/modules/Commands/Say.js index 376e39f6..a394a506 100644 --- a/example/modules/Commands/Say.js +++ b/example/modules/Commands/Say.js @@ -6,7 +6,6 @@ import { SlashCommandBuilder } from 'reciple'; * @type {import('reciple').RecipleModuleData} */ export default { - versions: ['^9'], commands: [ new SlashCommandBuilder() .setName('say') diff --git a/example/modules/Examples/AddCommandHalts.js b/example/modules/Examples/AddCommandHalts.js deleted file mode 100644 index 2ab3023f..00000000 --- a/example/modules/Examples/AddCommandHalts.js +++ /dev/null @@ -1,115 +0,0 @@ -/** - * This module adds halt function to every loaded command - */ - -// @ts-check -import { inlineCode, time } from "discord.js"; -import { CommandHaltReason, CommandPermissionsPrecondition, CommandPermissionsPreconditionTriggerDataType, CommandType } from "reciple"; - - -/** - * @satisfies {import("reciple").RecipleModuleData} - */ -export default { - versions: '^9', - commands: [], - onStart() { - return true; - }, - onLoad({ client }) { - client.modules.once('loadedModules', async () => { - const commands = [...client.commands.contextMenuCommands.values(), ...client.commands.messageCommands.values(), ...client.commands.slashCommands.values()]; - await this.addHaltToCommands(commands); - }); - }, - /** - * - * @param {import("reciple").AnyCommandBuilder[]} commands - */ - async addHaltToCommands(commands) { - for (const command of commands) { - const orginalHalt = command.halt; - const newHalt = async haltData => { - const handled = orginalHalt ? await orginalHalt(haltData) : false; - if (handled) return true; - - return this.handleCommandHalt(haltData); - }; - - command.setHalt(newHalt); - } - }, - /** - * - * @param {import("reciple").AnyCommandHaltData} haltData - * @returns {Promise} - */ - async handleCommandHalt(haltData) { - const createResponse = haltData.commandType === CommandType.MessageCommand - ? - /** - * @param {import("discord.js").BaseMessageOptions & { ephemeral: boolean }} options - */ - options => haltData.executeData.message.reply(options) - : haltData.executeData.interaction.deferred - ? - /** - * @param {import("discord.js").BaseMessageOptions} options - */ - options => haltData.executeData.interaction.editReply(options) - : haltData.executeData.interaction.replied - ? - /** - * @param {import("discord.js").BaseMessageOptions} options - */ - options => haltData.executeData.interaction.followUp(options) - : - /** - * @param {import("discord.js").BaseMessageOptions} options - */ - options => haltData.executeData.interaction.reply(options); - /** - * @type {import("discord.js").BaseMessageOptions & { ephemeral: boolean }} - */ - let replyOptions = { ephemeral: true }; - - switch (haltData.reason) { - case CommandHaltReason.Error: - replyOptions.content = 'An error occured while executing this command'; - await createResponse(replyOptions); - return true; - case CommandHaltReason.Cooldown: - replyOptions.content = `You can use this command again ${time(haltData.cooldown.endsAt, 'R')}`; - await createResponse(replyOptions); - return true; - case CommandHaltReason.InvalidArguments: - const invalidArgs = haltData.invalidOptions.map(a => inlineCode(a.name)); - replyOptions.content = `Invalid value given to option(s) ${invalidArgs.join(' ')}`; - createResponse(replyOptions); - return true; - case CommandHaltReason.MissingArguments: - const missingArgs = haltData.missingOptions.map(a => inlineCode(a.name)); - replyOptions.content = `Missing required argument(s) ${missingArgs.join(' ')}`; - createResponse(replyOptions); - return true; - case CommandHaltReason.PreconditionTrigger: - if (CommandPermissionsPrecondition.isPermissionsPreconditionData(haltData.data)) { - preconditionSwitch: switch (haltData.data.data?.type) { - case CommandPermissionsPreconditionTriggerDataType.BotNotAllowed: return true; - case CommandPermissionsPreconditionTriggerDataType.ClientNotEnoughPermissions: - replyOptions.content = `Bot requires ${haltData.data.data.requiredPermissions.toArray().map(p => inlineCode(p)).join(' ')} permission(s) to execute this command`; - break preconditionSwitch; - case CommandPermissionsPreconditionTriggerDataType.MemberNotEnoughPermissions: - replyOptions.content = `You doesn't have ${haltData.data.data.requiredPermissions.toArray().map(p => inlineCode(p)).join(' ')} permission(s) to execute this command`; - break preconditionSwitch; - case CommandPermissionsPreconditionTriggerDataType.NoDmPermission: return true; - } - - createResponse(replyOptions); - return true; - } - } - - return true; - } -}; diff --git a/example/modules/Examples/CustomLogger.js b/example/modules/Examples/CustomLogger.js index f559435a..f5adcc9b 100644 --- a/example/modules/Examples/CustomLogger.js +++ b/example/modules/Examples/CustomLogger.js @@ -7,7 +7,6 @@ * @satisfies {import("reciple").RecipleModuleData} */ export default { - versions: '^9', /** * @type {import("reciple").Logger|undefined} */ @@ -16,16 +15,16 @@ export default { * @param {import("reciple").RecipleModuleStartData} param0 */ onStart({ client }) { - this.logger = client.logger.clone({ name: 'My Logger' }); + this.logger = client.logger?.clone({ name: 'My Logger' }); return true; }, /** * @param {import("reciple").RecipleModuleLoadData} param0 */ onLoad({ client }) { - this.logger.log(`A log message`); // Logger#info is synonymous to Logger#log - this.logger.warning(`A warning message`); // Logger#warn is synonymous to Logger#warning - this.logger.error(`An error message`); // Logger#err is synonymous to Logger#error - this.logger.debug(`A debug message`); // Debug messages are shown when debug mode is enabled + this.logger?.log(`A log message`); // Logger#info is synonymous to Logger#log + this.logger?.warning(`A warning message`); // Logger#warn is synonymous to Logger#warning + this.logger?.error(`An error message`); // Logger#err is synonymous to Logger#error + this.logger?.debug(`A debug message`); // Debug messages are shown when debug mode is enabled } };