From c325bf5ab4961c9ffbcba0ad5cb1558236820bf4 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 22 Nov 2023 00:45:38 +0200 Subject: [PATCH] bugfix for empty messages --- structure/commands/Modmail.js | 102 +++++++++++++++++----------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/structure/commands/Modmail.js b/structure/commands/Modmail.js index 2caf450..20a6a29 100644 --- a/structure/commands/Modmail.js +++ b/structure/commands/Modmail.js @@ -1,53 +1,51 @@ -const Command = require('../Command'); - -class Modmail extends Command { - - constructor (client) { - super(client, { - name: 'modmail', - aliases: [ 'mm' ], - showUsage: true, - usage: ` ` - }); - } - - async execute (message, { args }) { - - // eslint-disable-next-line prefer-const - let [ first, second ] = args.map((a) => a); - // eslint-disable-next-line prefer-const - let { content, _caller } = message, - anon = false; - content = content.replace(`${this.client.prefix}${_caller}`, ''); - if (first.toLowerCase() === 'anon') { - anon = true; - content = content.replace(first, ''); - first = second; - } else if (second?.toLowerCase() === 'anon') { - anon = true; - content = content.replace(second, ''); - } - - const user = await this.client.resolveUser(first, true); - if (!user) return { - error: true, - msg: 'Failed to resolve user' - }; - else if (user.bot) return { - error: true, - msg: 'Cannot send modmail to a bot.' - }; - content = content.replace(first, ''); - - if (!content.length) return { - error: true, - msg: `Cannot send empty message` - }; - - return this.client.modmail.sendModmail({ message, content: content.trim(), anon, target: user }); - - } - -} - +const Command = require('../Command'); + +class Modmail extends Command { + + constructor (client) { + super(client, { + name: 'modmail', + aliases: [ 'mm' ], + showUsage: true, + usage: ` ` + }); + } + + async execute (message, { args }) { + // eslint-disable-next-line prefer-const + let [ first, second ] = args.map((a) => a); + // eslint-disable-next-line prefer-const + let { content, _caller } = message, + anon = false; + content = content.replace(`${this.client.prefix}${_caller}`, ''); + if (first.toLowerCase() === 'anon') { + anon = true; + content = content.replace(first, ''); + first = second; + } else if (second?.toLowerCase() === 'anon') { + anon = true; + content = content.replace(second, ''); + } + + const user = await this.client.resolveUser(first, true); + if (!user) return { + error: true, + msg: 'Failed to resolve user' + }; + else if (user.bot) return { + error: true, + msg: 'Cannot send modmail to a bot.' + }; + content = content.replace(first, '').trim(); + + if (!content.length) return { + error: true, + msg: `Cannot send empty message` + }; + + return this.client.modmail.sendModmail({ message, content, anon, target: user }); + } + +} + module.exports = Modmail; \ No newline at end of file