From db21dcb9b48e1cef68c4cd72f3d0a71e1fb8015e Mon Sep 17 00:00:00 2001 From: Neko Life Date: Tue, 18 May 2021 22:48:46 +0000 Subject: [PATCH] accept json arg, reportMessage --- cmds/utility/embmaker.js | 83 ++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index 73b7d15..dcce955 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -2,7 +2,7 @@ const commando = require("@iceprod/discord.js-commando"); const { MessageEmbed } = require("discord.js"); -const { ranLog, errLog, getChannelMessage, noPerm, tryReact } = require("../../resources/functions"); +const { ranLog, errLog, getChannelMessage, noPerm, tryReact, findChannelRegEx, trySend } = require("../../resources/functions"); const getColor = require("../../resources/getColor"); module.exports = class embmaker extends commando.Command { @@ -18,15 +18,24 @@ module.exports = class embmaker extends commando.Command { hidden:false }); } + /** + * + * @param {commando.CommandoMessage} msg + * @param {*} arg + * @returns + */ async run(msg, arg) { const args = arg.trim().split(/(? 0) { editSrc = await getChannelMessage(this.client, msg, editArg[0], editArg[1]); if (editSrc) { const editEmb = editSrc.embeds[0]; @@ -54,17 +63,23 @@ module.exports = class embmaker extends commando.Command { footericon = editEmb.footer.iconURL; } } + } else { + reportMessage += "**[EDIT]** No editable embed found.\n"; } + } else { + reportMessage += "**[EDIT]** Unknown message.\n"; } + } else { + reportMessage += "**[EDIT]** No argument provided.\n"; } } if (value.toLowerCase().startsWith('quote')) { const quoteargs = value.slice('quote'.length).toLowerCase().trim().split(/ +/); - if (quoteargs) { + if (quoteargs[0].length > 0) { await getChannelMessage(this.client, msg, quoteargs[0], quoteargs[1]) .then(quoteThis => { if (quoteThis) { - const author = quoteThis.guild.member(quoteThis.author); + const author = quoteThis.member; autName = author ? author.displayName : quoteThis.author.username; autIcon = quoteThis.author.displayAvatarURL({size:4096,dynamic:true}); autUrl = quoteThis.url; @@ -78,14 +93,16 @@ module.exports = class embmaker extends commando.Command { if (quoteThis.attachments) { for(const attach of quoteThis.attachments) { attach.map(g => { - if (/^http/.test(g.proxyURL)) { - newAttach.push(g.proxyURL); - } + newAttach.push(g.proxyURL); }); } } + } else { + reportMessage += "**[QUOTE]** Unknown message.\n"; } }); + } else { + reportMessage += "**[QUOTE]** No argument provided.\n"; } } if (value.toLowerCase().startsWith('remove')) { @@ -126,6 +143,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(autVal.slice('icon'.length).trim())) { autIcon = autVal.slice('icon'.length).trim(); } else { + reportMessage += "**[AUTHOR]** Invalid icon URL.\n"; autIcon = null; } } @@ -133,6 +151,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(autVal.slice('url'.length).trim())) { autUrl = autVal.slice('url'.length).trim(); } else { + reportMessage += "**[AUTHOR]** Invalid URL.\n"; autUrl = null; } } @@ -149,6 +168,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(value.slice("image".length).trim())) { embed.setImage(value.slice("image".length).trim()); } else { + reportMessage += "**[IMAGE]** Invalid URL.\n"; embed.setImage(null); } } @@ -156,6 +176,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(value.slice("thumbnail".length).trim())) { embed.setThumbnail(value.slice("thumbnail".length).trim()); } else { + reportMessage += "**[THUMBNAIL]** Invalid URL.\n"; embed.setThumbnail(null); } } @@ -163,6 +184,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(value.slice("url".length).trim())) { embed.setURL(value.slice("url".length).trim()); } else { + reportMessage += "**[URL]** Invalid URL.\n"; embed.setURL(null); } } @@ -171,22 +193,26 @@ module.exports = class embmaker extends commando.Command { for(const theFile of attach) { if (/^http/.test(theFile)) { newAttach.push(theFile); + } else { + if (theFile.toLowerCase() !== "-copy") { + reportMessage += "**[ATTACHMENT]** Invalid URL.\n"; + } } - if (theFile === '-copy' && editSrc) { - if (editSrc.attachments) { + if (theFile.toLowerCase() === '-copy' && editSrc) { + if (editSrc.attachments[0].length > 0) { for(const attach of editSrc.attachments) { attach.map(g => { - if (/^http/.test(g.proxyURL)) { - newAttach.push(g.proxyURL); - } + newAttach.push(g.proxyURL); }); } + } else { + reportMessage += "**[ATTACHMENT]** No attachment to copy.\n"; } } } } if (value.toLowerCase().startsWith("timestamp")) { - if(!/[a-zA-Z]/.test(value.slice("timestamp".length).trim())) { + if(!/\D/.test(value.slice("timestamp".length).trim())) { embed.setTimestamp(parseInt(value.slice("timestamp".length).trim(), 10)); } else { if (value.slice("timestamp".length).trim().toLowerCase() === 'now') { @@ -195,6 +221,9 @@ module.exports = class embmaker extends commando.Command { embed.setTimestamp(value.slice("timestamp".length).trim()); } } + if (!embed.timestamp) { + reportMessage += "**[TIMESTAMP]** Invalid format.\n"; + } } if (value.toLowerCase().startsWith('footer')) { const footerData = value.trim().split(/( \-)+/); @@ -206,6 +235,7 @@ module.exports = class embmaker extends commando.Command { if (/^http/.test(footval.slice('icon'.length).trim())) { footericon = footval.slice('icon'.length).trim(); } else { + reportMessage += "**[FOOTER]** Invalid icon URL.\n"; footericon = null; } } @@ -243,12 +273,20 @@ module.exports = class embmaker extends commando.Command { let ID = value.slice('channel'.length).trim(); if (ID.toLowerCase() === 'here') { channel = msg.channel; - } - if (ID.startsWith('<#') && ID.endsWith('>')) { - ID = ID.slice(2, -1); - } - if (!/\D/.test(ID)) { - channel = this.client.channels.cache.get(ID); + } else { + if (/^\d{17,19}$/.test(ID)) { + channel = msg.guild.channels.cache.get(ID); + if (!channel) { + if (this.client.owners.includes(msg.author.id)) { + channel = this.client.channels.cache.get(ID); + } + } + } else { + channel = findChannelRegEx(msg, ID, ["category", "voice"])[0]; + } + if (!channel) { + reportMessage += "**[CHANNEL]** Unknown channel.\n"; + } } } } @@ -280,7 +318,10 @@ module.exports = class embmaker extends commando.Command { embed = null; } if (newAttach.length > 0) { - console.log("Uploading attachments..."); + reportMessage += "**[ATTACHMENT]** Uploading attachments....\n"; + } + if (reportMessage.length > 0) { + trySend(this.client, msg, reportMessage); } if (editSrc) { if (channel) {