From 30f0dd849312885295c5578be54e0a1f40431aa8 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 19 Jul 2022 00:35:46 +0300 Subject: [PATCH] Silent mode --- src/structure/client/ModerationManager.js | 28 +++++++++---------- .../client/wrappers/InteractionWrapper.js | 4 +++ .../client/wrappers/InvokerWrapper.js | 4 +++ .../client/wrappers/MessageWrapper.js | 9 ++++-- .../components/observers/CommandHandler.js | 3 +- .../settings/administration/Silent.js | 2 +- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/structure/client/ModerationManager.js b/src/structure/client/ModerationManager.js index 4c23b64..fe614f7 100644 --- a/src/structure/client/ModerationManager.js +++ b/src/structure/client/ModerationManager.js @@ -184,21 +184,21 @@ class ModerationManager { })}`; data.escalation ? string += str : string = `${str}\n${string}`; //eslint-disable-line } + for (const [, data] of Object.entries(fails)) { + const { dictionary, targetType } = data.infraction; + const str = `${Emojis.failure} ${invoker.format('INFRACTION_FAIL', { + infraction: dictionary.present, + targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`, + target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '), + reason: data.formatted ? data.reason : invoker.format(data.reason) + })}`; + (!data.escalation && !success) //eslint-disable-line + ? string = `${str}\n${string}` + : string += str; + } } - - for (const [, data] of Object.entries(fails)) { - const { dictionary, targetType } = data.infraction; - const str = `${Emojis.failure} ${invoker.format('INFRACTION_FAIL', { - infraction: dictionary.present, - targetType: `${targetType.toLowerCase()}${data.targets.length === 1 ? '' : 's'}`, - target: data.targets.map((t) => `**${Util.escapeMarkdown(t)}**`).join(' '), - reason: data.formatted ? data.reason : invoker.format(data.reason) - })}`; - (!data.escalation && !success) //eslint-disable-line - ? string = `${str}\n${string}` - : string += str; - } - + + if(silent) await invoker.deleteReply(); // if (success && silent) { //Delete message if silent. // try { // await interaction.delete(); diff --git a/src/structure/client/wrappers/InteractionWrapper.js b/src/structure/client/wrappers/InteractionWrapper.js index a07fcdf..f122889 100644 --- a/src/structure/client/wrappers/InteractionWrapper.js +++ b/src/structure/client/wrappers/InteractionWrapper.js @@ -105,6 +105,10 @@ class InteractionWrapper { return this.interaction.deferUpdate(...args); } + deleteReply() { + return this.interaction.deleteReply(); + } + update(...args) { return this.interaction.update(...args); } diff --git a/src/structure/client/wrappers/InvokerWrapper.js b/src/structure/client/wrappers/InvokerWrapper.js index 6a3ad50..825bf77 100644 --- a/src/structure/client/wrappers/InvokerWrapper.js +++ b/src/structure/client/wrappers/InvokerWrapper.js @@ -92,6 +92,10 @@ class InvokerWrapper { return this.target.deferReply(options); } + deleteReply() { + return this.target.deleteReply(); + } + async promptMessage(str, opts = {}) { if (str instanceof Object) { diff --git a/src/structure/client/wrappers/MessageWrapper.js b/src/structure/client/wrappers/MessageWrapper.js index d70a16a..238a9a6 100644 --- a/src/structure/client/wrappers/MessageWrapper.js +++ b/src/structure/client/wrappers/MessageWrapper.js @@ -75,7 +75,7 @@ class MessageWrapper { } async reply(options) { - if (this._reply) throw new Error('Message has already been replied to!'); + if (this._reply) throw new Error('Message has already been replied to'); if (options.failIfNotExists === undefined) options.failIfNotExists = false; // Creates a non-reply message if the referenced message was deleted if(!options.allowedMentions) options.allowedMentions = { repliedUser: false }; // Disables the mention in the inline reply @@ -85,10 +85,15 @@ class MessageWrapper { } async editReply(options) { - if (!this._reply) throw new Error('Message has not been replied to!'); + if (!this._reply) throw new Error('Message not replied to'); return this._reply.edit(options); } + async deleteReply() { + if (this._reply) return this._reply.delete(); + throw new Error('Message not replied to'); + } + awaitReactions(...opts) { return this.message.awaitReactions(...opts); } diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 2cef7ba..2207d79 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -162,7 +162,8 @@ class CommandHandler extends Observer { return; } - if (response instanceof Message) return; + // Ignore null responses specifically, should still warn for undefined responses + if (response instanceof Message || response === null) return; if (response) { if (response instanceof MessageEmbed) return invoker.reply({ embeds: [response] }); diff --git a/src/structure/components/settings/administration/Silent.js b/src/structure/components/settings/administration/Silent.js index 87bb9cd..889bdb3 100644 --- a/src/structure/components/settings/administration/Silent.js +++ b/src/structure/components/settings/administration/Silent.js @@ -33,7 +33,7 @@ class SilentSetting extends Setting { setting[opt.name] = opt.value; } - return { index: 'SETTING_SUCCESS' }; + return { index: 'SETTING_SUCCESS_ALT' }; }