From 9676addad879e741a38e7531ee3c4d5f703fc859 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 23 Mar 2022 14:39:31 +0200 Subject: [PATCH] misc fixes --- structure/Client.js | 18 +++++++++++++++++- structure/commands/CannedReply.js | 5 ++++- structure/commands/Id.js | 19 ++++--------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/structure/Client.js b/structure/Client.js index cd94014..9a6c83b 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -75,7 +75,7 @@ class ModmailClient extends Client { ready () { return new Promise((resolve) => { - if (this._ready) resolve(); + if (this._ready) return resolve(); this.once('ready', resolve); }); @@ -165,6 +165,22 @@ class ModmailClient extends Client { } + getUserFromChannel (channel) { + + const chCache = this.cache.channels; + const result = Object.entries(chCache).find(([ , val ]) => { + return val === channel.id; + }); + + if (!result) return { + error: true, + msg: `This doesn't seem to be a valid modmail channel. Cache might be out of sync. **[MISSING TARGET]**` + }; + + return result; + + } + } module.exports = ModmailClient; \ No newline at end of file diff --git a/structure/commands/CannedReply.js b/structure/commands/CannedReply.js index 9c56316..4b22caa 100644 --- a/structure/commands/CannedReply.js +++ b/structure/commands/CannedReply.js @@ -19,12 +19,13 @@ class CannedReply extends Command { anon = false; content = content.replace(`${this.client.prefix}${_caller}`, ''); const op = args.shift().toLowerCase(); + if (op === 'anon') { anon = true; content = content.replace(first, ''); } else if ([ 'create', 'delete' ].includes(op)) { return this.createCanned(op, args, message); - } else if ([ 'list' ].includes(first.toLowerCase(op))) { + } else if ([ 'list' ].includes(first.toLowerCase())) { const list = Object.entries(this.client.modmail.replies); let str = ''; @@ -39,7 +40,9 @@ class CannedReply extends Command { } if (str.length) return channel.send(str); return '**__None__**'; + } + return this.client.modmail.sendCannedResponse({ message, responseName: content.trim(), anon }); } diff --git a/structure/commands/Id.js b/structure/commands/Id.js index e21bce6..915914e 100644 --- a/structure/commands/Id.js +++ b/structure/commands/Id.js @@ -12,22 +12,11 @@ class ModmailID extends Command { async execute (message, { args }) { let channel = null; - if (args?.length) { - const [ ch ] = args; - channel = await this.client.resolveChannel(ch); - } else { - ({ channel } = message); - } + if (args?.length) channel = await this.client.resolveChannel(args[0]); + else ({ channel } = message); - const chCache = this.client.cache.channels; - const result = Object.entries(chCache).find(([ , val ]) => { - return val === channel.id; - }); - - if (!result) return { - error: true, - msg: `This doesn't seem to be a valid modmail channel. Cache might be out of sync. **[MISSING TARGET]**` - }; + const result = this.client.getUserFromChannel(channel); + if (result.error) return result; const [ userId ] = result; return userId;