From 40599b7071107016979943a0f5cfbb33d85588f3 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 13:47:44 +0000 Subject: [PATCH] small fix: enable edit command message to edit response --- cmds/utility/avatar.js | 7 +++--- cmds/utility/cloneembed.js | 10 ++++----- cmds/utility/embmaker.js | 38 ++++++++++++++++---------------- cmds/utility/invite.js | 3 +-- cmds/utility/lookup.js | 14 ++++-------- cmds/utility/mesemb.js | 18 ++++++--------- cmds/utility/mesinfo.js | 31 ++++++++++---------------- cmds/utility/newquoteotd.js | 14 +++++++----- cmds/utility/quoteotd.js | 3 +-- cmds/utility/say.js | 8 +++---- cmds/utility/send.js | 6 +++-- cmds/utility/servav.js | 5 ++--- cmds/utility/setfootq.js | 2 +- cmds/utility/uinfo.js | 3 +-- resources/functions.js | 44 ++++++++++--------------------------- 15 files changed, 82 insertions(+), 124 deletions(-) diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index 6689c16..074b8b2 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -125,15 +125,16 @@ module.exports = class avatar extends commando.Command { } allEmb.push(emb); } + let retSent = []; if (notFound.length > 0) { - trySend(this.client, msg, notFound); + retSent.push(notFound); } for (let index = 0; index < allEmb.length; index++) { const embelement = allEmb[index]; const contelement = multipleMemMes[index]; - trySend(this.client, msg, { embed: embelement, content: contelement, split:{maxLength:2000,char: ",",append:',```',prepend:'```js' }}); + retSent.push({ embed: embelement, content: contelement, split:{maxLength:2000,char: ",",append:',```',prepend:'```js' }}); } - return ranLog(msg,'avatar',arg); + return retSent.map(r => trySend(this.client, msg, r)); }); } }; \ No newline at end of file diff --git a/cmds/utility/cloneembed.js b/cmds/utility/cloneembed.js index bd7dfe0..362b879 100644 --- a/cmds/utility/cloneembed.js +++ b/cmds/utility/cloneembed.js @@ -28,13 +28,11 @@ module.exports = class cloneembed extends commando.Command { if (!args[0]) { return trySend(this.client, msg, 'Which message??'); } - trySend(this.client, msg, {content:content,embed:theMes.embeds[0]}); - const moreEmb = theMes.embeds.slice(1); - for(const emb of moreEmb) { - trySend(this.client, msg, new MessageEmbed(emb)); + const sent = theMes.embeds.map(r => trySend(this.client, msg, {content:content,embed:r})); + if (sent) { + tryReact(msg, "a:yesLife:794788847996370945"); } - tryReact(msg, "a:yesLife:794788847996370945"); - return ranLog(msg,'clonemb',`Embed ${theMes.url} (${theMes.id}) in ${theMes.channel.name} (${theMes.channel.id}) of ${theMes.guild.name} cloned.`); + return sent; } catch (e) { return trySend(this.client, msg, "No embed found. Use ` ` if it's in another channel."); } diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index 210c2ed..cb4dfa6 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -140,7 +140,7 @@ module.exports = class embmaker extends commando.Command { autName = autVal.slice('name'.length).trim().replace(/\\(?!\\)/g,''); } if (autVal.toLowerCase().startsWith('icon')) { - if (/^http/.test(autVal.slice('icon'.length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(autVal.slice('icon'.length).trim())) { autIcon = autVal.slice('icon'.length).trim(); } else { reportMessage += "**[AUTHOR]** Invalid icon URL.\n"; @@ -148,7 +148,7 @@ module.exports = class embmaker extends commando.Command { } } if (autVal.toLowerCase().startsWith('url')) { - if (/^http/.test(autVal.slice('url'.length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(autVal.slice('url'.length).trim())) { autUrl = autVal.slice('url'.length).trim(); } else { reportMessage += "**[AUTHOR]** Invalid URL.\n"; @@ -165,7 +165,7 @@ module.exports = class embmaker extends commando.Command { } } if (value.toLowerCase().startsWith("image")) { - if (/^http/.test(value.slice("image".length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(value.slice("image".length).trim())) { embed.setImage(value.slice("image".length).trim()); } else { reportMessage += "**[IMAGE]** Invalid URL.\n"; @@ -173,7 +173,7 @@ module.exports = class embmaker extends commando.Command { } } if (value.toLowerCase().startsWith("thumbnail")) { - if (/^http/.test(value.slice("thumbnail".length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(value.slice("thumbnail".length).trim())) { embed.setThumbnail(value.slice("thumbnail".length).trim()); } else { reportMessage += "**[THUMBNAIL]** Invalid URL.\n"; @@ -181,7 +181,7 @@ module.exports = class embmaker extends commando.Command { } } if (value.toLowerCase().startsWith('url')) { - if (/^http/.test(value.slice("url".length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(value.slice("url".length).trim())) { embed.setURL(value.slice("url".length).trim()); } else { reportMessage += "**[URL]** Invalid URL.\n"; @@ -191,7 +191,7 @@ module.exports = class embmaker extends commando.Command { if (value.toLowerCase().startsWith('attachment')) { const attach = value.slice("attachments".length).trim().split(/ +/); for(const theFile of attach) { - if (/^http/.test(theFile)) { + if (/^https?:\/\/\w+\.\w\w/.test(theFile)) { newAttach.push(theFile); } else { if (theFile.toLowerCase() !== "-copy") { @@ -232,7 +232,7 @@ module.exports = class embmaker extends commando.Command { footertext = footval.slice("text".length).trim().replace(/\\(?!\\)/g,''); } if (footval.toLowerCase().startsWith('icon')) { - if (/^http/.test(footval.slice('icon'.length).trim())) { + if (/^https?:\/\/\w+\.\w\w/.test(footval.slice('icon'.length).trim())) { footericon = footval.slice('icon'.length).trim(); } else { reportMessage += "**[FOOTER]** Invalid icon URL.\n"; @@ -320,29 +320,29 @@ module.exports = class embmaker extends commando.Command { if (newAttach.length > 0) { reportMessage += "**[ATTACHMENT]** Uploading attachments....\n"; } + let sent = []; if (reportMessage.length > 0) { - trySend(this.client, msg, reportMessage); + sent.push(trySend(this.client, msg, reportMessage)); } if (editSrc) { if (channel) { - channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg)); + sent.push(channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg))); } else { channel = msg.channel; if (editSrc.author === this.client.user) { - try { - editSrc.edit({content:content,embed:embed,files:newAttach}).catch(e => errLog(e, msg, this.client)); - } catch (e) { + sent.push(editSrc.edit({content:content,embed:embed,files:newAttach}).catch(e => { + errLog(e, msg, this.client); try { - channel.send('Something\'s wrong, i can\'t edit that so here <:WhenLife:773061840351657984>'); - channel.send({content:content,embed:embed,files:newAttach}); + sent.push(channel.send('Something\'s wrong, i can\'t edit that so here <:WhenLife:773061840351657984>')); + sent.push(channel.send({content:content,embed:embed,files:newAttach})); } catch (e) { noPerm(msg); } - } + })); } else { try { - channel.send('I can\'t edit that, so here <:catstareLife:794930503076675584>'); - channel.send({content:content,embed:embed,files:newAttach}); + sent.push(channel.send('I can\'t edit that, so here <:catstareLife:794930503076675584>')); + sent.push(channel.send({content:content,embed:embed,files:newAttach})); } catch (e) { noPerm(msg); } @@ -352,10 +352,10 @@ module.exports = class embmaker extends commando.Command { if (!channel) { channel = msg.channel; } - channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg)); + sent.push(channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg))); } tryReact(msg, "a:yesLife:794788847996370945"); - return ranLog(msg,'embmaker',`${arg}\nContent: ${content}\nAttachments: ${newAttach}`); + return sent; } catch (e) { return errLog(e, msg, this.client, true, "", true); } diff --git a/cmds/utility/invite.js b/cmds/utility/invite.js index 6c1b874..379b160 100644 --- a/cmds/utility/invite.js +++ b/cmds/utility/invite.js @@ -14,7 +14,6 @@ module.exports = class invite extends commando.Command { }); } run(msg) { - trySend(this.client, msg, "Mute me after cuz it's spam\n"+conf.invite); - return ranLog(msg, "invite"); + return trySend(this.client, msg, "Mute me after cuz it's spam\n"+conf.invite); } }; \ No newline at end of file diff --git a/cmds/utility/lookup.js b/cmds/utility/lookup.js index 58e5662..715d047 100644 --- a/cmds/utility/lookup.js +++ b/cmds/utility/lookup.js @@ -12,12 +12,6 @@ module.exports = class lookup extends commando.Command { description: "Lookup something in the server using mention, ID, or RegExp." }); } - /** - * - * @param {commando.CommandoMessage} msg - * @param {*} arg - * @returns - */ async run(msg, arg) { let show; const showArg = arg.match(/(?") - } else { - try { - const mesinfo = 'Collected:```js\n'+JSON.stringify(message, null, 2).replace(/`/g,"\\`")+'```'; - const mentionJSON = message.mentions.toJSON(); - const sendMentionInfo = 'Mentions:```js\n'+JSON.stringify(mentionJSON, null, 2)+'```'; - const Attachments = 'Attachments:```js\n'+JSON.stringify(message.attachments, null, 2)+'```'; - const sendmesinfo = mesinfo+sendMentionInfo+Attachments; - const result1 = await trySend(this.client, msg, {content:sendmesinfo,split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); - return ranLog(msg,'mesinfo',`${result1}`); - } catch (e) { - noPerm(msg); - return errLog(e, msg, this.client); - } - } + const args = arg.trim().split(/ +/); + const message = await getChannelMessage(this.client, msg, args[0], args[1]); + if (!message) { + return trySend(this.client, msg, "No message with that ID <:catstareLife:794930503076675584>") } + const mesinfo = 'Collected:```js\n'+JSON.stringify(message, null, 2).replace(/`/g,"\\`")+'```'; + const mentionJSON = message.mentions.toJSON(); + const sendMentionInfo = 'Mentions:```js\n'+JSON.stringify(mentionJSON, null, 2)+'```'; + const Attachments = 'Attachments:```js\n'+JSON.stringify(message.attachments, null, 2)+'```'; + const sendmesinfo = mesinfo+sendMentionInfo+Attachments; + return trySend(this.client, msg, {content:sendmesinfo,split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); + } }; \ No newline at end of file diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index 4d5fa39..3465b7e 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -24,10 +24,10 @@ module.exports = class newquoteotd extends commando.Command { const quoteOTD = findDoc?.["settings"]?.quoteOTD; const color = colorConf.randomColors; if (!quoteOTD || !quoteOTD.channel) { - return msg.channel.send(`Quote OTD channel not set! Run \`${msg.guild.commandPrefix}quoteotd\` to set one.`); + return trySend(this.client, msg, `Quote OTD channel not set! Run \`${msg.guild.commandPrefix}quoteotd\` to set one.`); } if (!args[0]) { - return msg.channel.send('Provide ``!'); + return trySend(this.client, msg, 'Provide ``!'); } try { let emb = new MessageEmbed(); @@ -51,11 +51,13 @@ module.exports = class newquoteotd extends commando.Command { .setThumbnail(thumbnail) .setFooter(quoteOTD.footerText, quoteOTD.footerIcon) .setColor(color[Math.floor(Math.random()*color.length)]); - await trySend(this.client, quoteOTD.channel, emb); - tryReact(msg, "a:yesLife:794788847996370945"); - return ranLog(msg,'newqotd',`${msg.author.tag} (${msg.author.id}) made new QOTD \`${description}\` by ${author.tag} (${author.id})`); + const sent = trySend(this.client, quoteOTD.channel, emb); + if (sent) { + tryReact(msg, "a:yesLife:794788847996370945"); + } + return sent; } - return msg.channel.send('No message with that ID from this channel. Use `[ , message_link]` if it\'s in another channel.'); + return trySend(this.client, msg, 'No message with that ID from this channel. Use `[ , message_link]` if it\'s in another channel.'); } catch (e) { noPerm(msg); return errLog(e, msg, this.client, true, "", true); diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index a021420..d8e5f7a 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -56,10 +56,9 @@ module.exports = class quoteotd extends commando.Command { } } if (result.length > 0) { - trySend(this.client, msg, result); + return trySend(this.client, msg, result); } else { return trySend(this.client, msg, `Provide argument: \`--channel [mention, ID], --text [footer text], --icon [url footer icon]\``); } - return ranLog(msg,'qotd',result); } }; \ No newline at end of file diff --git a/cmds/utility/say.js b/cmds/utility/say.js index 7c4df27..992a876 100644 --- a/cmds/utility/say.js +++ b/cmds/utility/say.js @@ -14,19 +14,19 @@ module.exports = class say extends commando.Command { }); } run(msg, args) { - let noArgs = `<@!${msg.author.id}> what to say?`; + let noArgs = '​'; if (!args) { args = noArgs; } args = emoteMessage(this.client, args); const sendThis = {content:args, disableMentions:"all"}; - if (msg.member?.hasPermission("ADMINISTRATOR")) { + if (msg.member?.hasPermission('MENTION_EVERYONE')) { sendThis.disableMentions = "none"; } - trySend(this.client, msg, sendThis); + const sent = trySend(this.client, msg, sendThis); if (args !== noArgs && msg.channel.guild && msg.member.hasPermission("MANAGE_MESSAGES")) { tryDelete(msg); } - return ranLog(msg,'say',`Content: ${args}`); + return sent; } }; \ No newline at end of file diff --git a/cmds/utility/send.js b/cmds/utility/send.js index bb6a837..c8a8446 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -56,8 +56,10 @@ module.exports = class send extends commando.Command { } catch (e) {} }); collector.on('remove', async r => await msg.reactions.resolve(r).id.remove(r.id)); - tryReact(msg, 'yeLife:796401669188354090'); - return ranLog(msg,'send',`ID: ${send.id} url: ${send.url}\nSent to channel: ${channel.name} (${channel.id}) of ${send.guild.name}\nContent: ${args.slice(at.length)}`); + if (send) { + tryReact(msg, 'yeLife:796401669188354090'); + } + return send; } catch (e) { return errLog(e, msg, this.client); } diff --git a/cmds/utility/servav.js b/cmds/utility/servav.js index be7aa8a..be7da64 100644 --- a/cmds/utility/servav.js +++ b/cmds/utility/servav.js @@ -25,7 +25,7 @@ module.exports = class servav extends commando.Command { const server_ID = arg.split(/ +/)[0]; const doc = msg.guild?.id ?? msg.author.id; const col = database.collection(msg.guild ? "Guild" : "User"); - col.findOne({document: doc}, async (err, res) => { + col.findOne({document: doc}, (err, res) => { if (err) { errLog(err, msg, this.client); } @@ -54,8 +54,7 @@ module.exports = class servav extends commando.Command { const color = getColor(target.owner.displayColor) embed.setColor(color); } - trySend(this.client, msg, embed); - return ranLog(msg, "servav", `**${target.name}** (${target.id})`); + return trySend(this.client, msg, embed); } }); } diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index d164ecf..63e2e02 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -29,7 +29,7 @@ module.exports = class setfootq extends commando.Command { return errLog(e, msg, this.client); } const result = await trySend(this.client, msg, `Changed from \`${oldQ?.["settings"]?.defaultEmbed?.footerQuote}\` to \`${args.trim()}\``); - return ranLog(msg, "setfooterquote", result.content); + return result; }); } catch (e) { return errLog(e, msg, this.client); diff --git a/cmds/utility/uinfo.js b/cmds/utility/uinfo.js index 8cdae84..8717593 100644 --- a/cmds/utility/uinfo.js +++ b/cmds/utility/uinfo.js @@ -39,8 +39,7 @@ module.exports = class uinfo extends commando.Command { result += 'Display color:```js\n'+member.displayColor+'```'; } } - trySend(this.client, msg, result, {split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); - return ranLog(msg,'profile', msg.content); + return trySend(this.client, msg, result, {split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); } catch (e) { return trySend(this.client, msg, "404 ERROR not found~"); } diff --git a/resources/functions.js b/resources/functions.js index ac57c46..e91f707 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -63,7 +63,7 @@ async function errLog(theError, msg, client, sendTheError, errorMessage, notify) * @param {Message} msg - Message object (msg) * @param {String} MainID - Message ID | Channel ID | Channel Mention * @param {String} SecondID - Message ID - * @returns {Promise} Message object + * @returns {Promise} Message object | undefined */ async function getChannelMessage(client, msg, MainID, SecondID) { if (!MainID) { @@ -157,17 +157,8 @@ function multipleMembersFound(client, msg, arr, key, max = 4, withID) { * @returns {GuildMember[]} Member object found */ function findMemberRegEx(msg, name) { - let found = []; const re = new RegExp(name, "i"); - const list = msg.guild?.members.cache.array(); - if (list) { - for(const mem of list) { - if (re.test(mem.displayName) || re.test(mem.user.tag)) { - found.push(mem); - } - } - return found; - } + return msg.guild?.members.cache.array().filter(r => re.test(r.displayName) || re.test(r.user.tag)); } /** @@ -184,7 +175,8 @@ function noPerm(msg) { * Send message * @param {Client} client - (this.client) * @param {Message | String | Channel} msg Message object | channel_ID - * @param {MessageOptions} content - ({content:content,optionblabla}) + * @param {MessageOptions} content - ({content:content,optionblabla}) + * @param {Boolean} adCheck - Check source for Discord invite link (true) * @returns {Promise} Sent message object */ async function trySend(client, msg, content, adCheck = true) { @@ -310,19 +302,14 @@ function cleanMentionID(key) { * @returns {GuildChannel[]} Channels object found */ function findChannelRegEx(msg, name, exclude) { - let found = []; const re = new RegExp(name, "i"); - const list = msg.guild?.channels.cache.array(); - if (list) { - for(const mem of list) { - if (re.test(mem.name)) { - if (exclude?.includes(mem.type)) {} else { - found.push(mem); - } - } + return msg.guild?.channels.cache.array().filter(r => { + if (exclude?.includes(r.type)) { + return false; + } else { + return re.test(r.name); } - return found; - } + }); } /** @@ -332,17 +319,8 @@ function findChannelRegEx(msg, name, exclude) { * @returns {Role[]} Roles object found */ function findRoleRegEx(msg, name) { - let found = []; const re = new RegExp(name, "i"); - const list = msg.guild?.roles.cache.array(); - if (list) { - for(const mem of list) { - if (re.test(mem.name)) { - found.push(mem); - } - } - return found; - } + return msg.guild?.roles.cache.array().filter(r => re.test(r.name)); } /**