From f8070f107136f6993337038e1761242113fe5487 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 17 May 2021 10:47:53 +0000 Subject: [PATCH 01/37] better embmaker --- cmds/utility/embmaker.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index d405391..73b7d15 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -263,14 +263,15 @@ module.exports = class embmaker extends commando.Command { if (autName || autIcon && embed.author !== null) { embed.setAuthor(autName,autIcon,autUrl); } - if (!footertext && footericon || !footertext && embed.timestamp) { - footertext = '​'; - } if (footertext || footericon && embed.footer !== null) { embed.setFooter(footertext,footericon); } - if (embed.length === 0 && (embed.thumbnail === null || embed.thumbnail.url === null) && embed.author === null && (embed.image === null || embed.image.url === null) && embed.timestamp === null) { - embed.setDescription('​'); + if (embed.length === 0 && (embed.thumbnail === null || embed.thumbnail.url === null) && embed.author === null && (embed.image === null || embed.image.url === null)) { + if (embed.timestamp) { + embed.setFooter('​'); + } else { + embed.setDescription("_ _"); + } } if (embed.color === 16777215) { embed.setColor(16777214); From 03d97d34fe786d9e341c82a807dd7a8c55c90453 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Tue, 18 May 2021 22:45:55 +0000 Subject: [PATCH 02/37] findChannel added arg: exclude --- resources/functions.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/resources/functions.js b/resources/functions.js index 4bc976a..c8edfb3 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -172,8 +172,8 @@ function multipleMembersFound(client, msg, arr, key, max = 4, withID) { /** * Get member object with RegExp - * @param {Message} msg - * @param {String} name + * @param {Message} msg Message object of the guild being searched + * @param {String} name Keyword * @returns {GuildMember[]} Member object found */ function findMemberRegEx(msg, name) { @@ -290,7 +290,7 @@ async function defaultImageEmbed(client, msg, author, image, title, footerText) .setColor(msg.guild ? getColor(author?.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) .setFooter(footerQuote); } catch (e) { - return errLog(e, msg, client, false, "", false); + return errLog(e, msg, client); } return emb; } @@ -316,18 +316,21 @@ function cleanMentionID(key) { /** * Get channel object wit RegExp - * @param {Message} msg - * @param {String} name + * @param {Message} msg Message object of the guild being searched + * @param {String} name Keyword + * @param {ChannelType[]} exclude Exclude channel type * @returns {GuildChannel[]} Channels object found */ -function findChannelRegEx(msg, name) { +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)) { - found.push(mem); + if (exclude?.includes(mem.type)) {} else { + found.push(mem); + } } } return found; @@ -336,8 +339,8 @@ function findChannelRegEx(msg, name) { /** * Get role object with RegExp - * @param {Message} msg - * @param {String} name + * @param {Message} msg Message object of the guild being searched + * @param {String} name Keyword * @returns {Role[]} Roles object found */ function findRoleRegEx(msg, name) { From 316c87c5d5ed78f4ae71b83faa03775217e665ab Mon Sep 17 00:00:00 2001 From: Neko Life Date: Tue, 18 May 2021 22:48:07 +0000 Subject: [PATCH 03/37] function update --- cmds/utility/send.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmds/utility/send.js b/cmds/utility/send.js index f96dc5a..f3f49b4 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -19,15 +19,20 @@ module.exports = class send extends commando.Command { return trySend(this.client, msg, 'Where?!?'); } const search = cleanMentionID(comarg[0]), - channel = findChannelRegEx(msg, search)[0], sendTheMes = args.slice(comarg[0].length).trim(); + let channel; + if (/^\d{17,19}$/.test(search)) { + channel = msg.guild.channels.cache.get(search); + } if (!channel) { - return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); - } else { - if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES")) { - return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>"); + channel = findChannelRegEx(msg, search, ["category", "voice"])[0]; + if (!channel) { + return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); } } + if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES")) { + return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>"); + } try { if (sendTheMes.length === 0) { return trySend(this.client, channel, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`); From db21dcb9b48e1cef68c4cd72f3d0a71e1fb8015e Mon Sep 17 00:00:00 2001 From: Neko Life Date: Tue, 18 May 2021 22:48:46 +0000 Subject: [PATCH 04/37] 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) { From 8b5d5c8955f99ea55361f0e802cefa1d8275339c Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:29:53 +0000 Subject: [PATCH 05/37] Fixed in DM usage --- cmds/experiment/mydatabase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/experiment/mydatabase.js b/cmds/experiment/mydatabase.js index dbf55bf..1cf742f 100644 --- a/cmds/experiment/mydatabase.js +++ b/cmds/experiment/mydatabase.js @@ -16,7 +16,7 @@ module.exports = class mydatabase extends commando.Command { }); } async run(msg) { - if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD")) { + if (msg.guild ? !msg.member.hasPermission("MANAGE_GUILD") : false) { return trySend(this.client, msg, "No"); } const data = msg.guild ? "Guild" : "User"; From e11b7d0fb606d0ce126e1152789cdc246cc5a78c Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:34:18 +0000 Subject: [PATCH 06/37] tidy up and rename --- cmds/utility/clonemb.js | 50 ----------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 cmds/utility/clonemb.js diff --git a/cmds/utility/clonemb.js b/cmds/utility/clonemb.js deleted file mode 100644 index f568989..0000000 --- a/cmds/utility/clonemb.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -const commando = require("@iceprod/discord.js-commando"); -const { MessageEmbed } = require("discord.js"); -const { getChannelMessage, errLog, ranLog, trySend, tryReact } = require("../../resources/functions"); - -module.exports = class clonemb extends commando.Command { - constructor(client) { - super(client, { - name: "clonemb", - aliases: ["cloneemb","cloneembed", "clonembed"], - memberName: "clonemb", - group: "utility", - description: "Clone an Embed." - }); - } - async run(msg, cargs) { - const args = cargs.trim().split(/ +/); - const {defaultErrorLogChannel} = require("../../config.json"); - try { - const theMes = await getChannelMessage(this.client,msg,args[0],args[1]); - let content; - if (theMes.content) { - content = theMes.content; - } - if (!theMes.embeds || (theMes.embeds).length === 0) { - return trySend(this.client, msg, 'No embed found.'); - } - if (!args[0]) { - return trySend(this.client, msg, 'Which embed??'); - } - 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)); - } - 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.`); - } catch (e) { - return errLog( - e, - msg, - this.client, - false, - "No embed found. Use ` ` if it's in another channel.", - true - ); - } - } -}; \ No newline at end of file From 7cdd34f8c5e81c80de408c3fa95c8e9c4f36c970 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:35:26 +0000 Subject: [PATCH 07/37] tidy up and rename --- cmds/utility/cloneembed.js | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cmds/utility/cloneembed.js diff --git a/cmds/utility/cloneembed.js b/cmds/utility/cloneembed.js new file mode 100644 index 0000000..bd7dfe0 --- /dev/null +++ b/cmds/utility/cloneembed.js @@ -0,0 +1,42 @@ +'use strict'; + +const commando = require("@iceprod/discord.js-commando"); +const { MessageEmbed } = require("discord.js"); +const { getChannelMessage, errLog, ranLog, trySend, tryReact } = require("../../resources/functions"); + +module.exports = class cloneembed extends commando.Command { + constructor(client) { + super(client, { + name: "clone-embed", + aliases: ["clone-emb","clon-emb", "clon-embed"], + memberName: "clonemb", + group: "utility", + description: "Clone an Embed." + }); + } + async run(msg, cargs) { + const args = cargs.trim().split(/ +/); + try { + const theMes = await getChannelMessage(this.client,msg,args[0],args[1]); + let content; + if (theMes.content) { + content = theMes.content; + } + if (!theMes.embeds || (theMes.embeds).length === 0) { + return trySend(this.client, msg, 'ypu don\'t know what an embed is? <:cathmmLife:772716381874946068>'); + } + 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)); + } + 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.`); + } catch (e) { + return trySend(this.client, msg, "No embed found. Use ` ` if it's in another channel."); + } + } +}; \ No newline at end of file From 4602ecfc4f179de1e19c5544e41e6cba2eedc5b0 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:35:54 +0000 Subject: [PATCH 08/37] Removed old codes --- cmds/utility/avatar.js | 45 +----------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index c1f44f2..c6aa093 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -136,47 +136,4 @@ module.exports = class avatar extends commando.Command { return ranLog(msg,'avatar',arg); }); } -}; - -// Old codes - /*args = args.split(/ +/); - try { - let member; - let avUrl; - let avatar = new MessageEmbed(); - if (args[0]) { - member = await getUser(this.client, args[0]); - } - if (!args[0]) { - avUrl = msg.author.displayAvatarURL({size:4096,dynamic:true}); - avatar - .setColor(msg.member.displayColor) - .setTitle(msg.member.displayName); - } else - if (member) { - avUrl = member.displayAvatarURL({size:4096,dynamic:true}); - try { - avatar.setColor(msg.guild.member(member).displayColor); - } catch (e) {errLog(e)} - try { - avatar - .setTitle(msg.guild.member(member).displayName); - } catch (e) { - errLog(e); - avatar - .setTitle(member.username); - } - } - if (!avUrl) { - return msg.channel.send('Who is that? I dunno them!'); - } - avatar - //.setAuthor(msg.author.username, msg.author.displayAvatarURL({size:4096, dynamic:true})) - .setImage(avUrl) - .setFooter(footerQuote); - msg.channel.send(avatar); - return ranLog(msg,'avatar', `${member ? `Avatar of ${member.tag} (${member.id}): ` : `Self avatar: `} ${avUrl}`); - } catch (e) { - await msg.channel.send('Who is that? I dunno them!'); - return errLog(e); - }*/ \ No newline at end of file +}; \ No newline at end of file From f16d7693d4b6540268d894caab5710109f485766 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:36:53 +0000 Subject: [PATCH 09/37] one line refactor --- cmds/utility/embmaker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index dcce955..210c2ed 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, findChannelRegEx, trySend } = require("../../resources/functions"); +const { ranLog, errLog, getChannelMessage, noPerm, tryReact, findChannelRegEx, trySend, cleanMentionID } = require("../../resources/functions"); const getColor = require("../../resources/getColor"); module.exports = class embmaker extends commando.Command { @@ -270,7 +270,7 @@ module.exports = class embmaker extends commando.Command { content = value.slice('content'.length).trim().replace(/\\(?!\\)/g,''); } if (value.toLowerCase().startsWith('channel')) { - let ID = value.slice('channel'.length).trim(); + let ID = cleanMentionID(value.slice('channel'.length).trim()); if (ID.toLowerCase() === 'here') { channel = msg.channel; } else { From bfff9e56104b7d68a8eef6e3a08d89c191a303bd Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:38:37 +0000 Subject: [PATCH 10/37] Use guild prefix --- cmds/utility/newquoteotd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index 62e0dca..4d5fa39 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -24,7 +24,7 @@ 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 \`${this.client.commandPrefix}quoteotd\` to set one.`); + return msg.channel.send(`Quote OTD channel not set! Run \`${msg.guild.commandPrefix}quoteotd\` to set one.`); } if (!args[0]) { return msg.channel.send('Provide ``!'); From cc02562a38fc8a43c1f779127ec75045fc82979b Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:39:14 +0000 Subject: [PATCH 11/37] Use regex --- cmds/utility/uinfo.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmds/utility/uinfo.js b/cmds/utility/uinfo.js index 02b5834..73658a6 100644 --- a/cmds/utility/uinfo.js +++ b/cmds/utility/uinfo.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { getUser, errLog, ranLog, trySend } = require("../../resources/functions"); +const { ranLog, trySend, cleanMentionID, findMemberRegEx } = require("../../resources/functions"); module.exports = class uinfo extends commando.Command { constructor(client) { @@ -12,12 +12,17 @@ module.exports = class uinfo extends commando.Command { description: "\"Detailed\" Profile." }); } - async run(msg, arg ) { - const args = arg.trim().split(/ +/); + async run(msg, arg) { try { - let profile; - if (args[0]) { - profile = await getUser(this.client, msg, args[0]); + let profile, + hmm; + if (arg.length > 0) { + hmm = cleanMentionID(arg); + if (/^\d{17,19}$/.test(hmm)) { + profile = this.client.users.cache.get(hmm); + } else { + profile = findMemberRegEx(msg, hmm)[0].user; + } } else { profile = msg.author; } @@ -35,7 +40,7 @@ module.exports = class uinfo extends commando.Command { trySend(this.client, msg, result, {split:{maxLength:2000,char: ", " || ",\n" || ". " || ".\n" || "," || ".",append:',```',prepend:'```js\n'}}); return ranLog(msg,'profile', msg.content); } catch (e) { - return errLog(e, msg, this.client, false, 'Gimme the right ID!', true); + return trySend(this.client, msg, "Ya lookin for ya lover? 404 not found."); } } }; \ No newline at end of file From 94808a55d73b2d22c729a1bc76e48418639b4a1b Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:40:31 +0000 Subject: [PATCH 12/37] Requires the right perms --- cmds/utility/send.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds/utility/send.js b/cmds/utility/send.js index f3f49b4..246d6f7 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -30,12 +30,12 @@ module.exports = class send extends commando.Command { return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); } } - if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES")) { + if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES") || !channel.permissionsFor(msg.author).has("VIEW_CHANNEL")) { return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>"); } try { if (sendTheMes.length === 0) { - return trySend(this.client, channel, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`); + return trySend(this.client, channel, `<@!${msg.author.id}>, If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`); } const sendThis = {content:sendTheMes, disableMentions:"all"}; if (msg.member?.hasPermission("MENTION_EVERYONE")) { From 0b0fcf916b7563301c50f3dd577ec212e76d751a Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:41:47 +0000 Subject: [PATCH 13/37] Removed getUser, no double error message logged --- resources/functions.js | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/resources/functions.js b/resources/functions.js index c8edfb3..88259e0 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -45,7 +45,7 @@ async function errLog(theError, msg, client, sendTheError, errorMessage, notify) if (msg && msg.guild && msg.guild.id === "823815890285756447") { logThis = ""; } - const sendAt = await client.channels.cache.get(defaultErrorLogChannel); + const sendAt = client.channels.cache.get(defaultErrorLogChannel); sendAt.send(logThis + inLogChannel.trim(),{split:true}); } catch (errmes) { errLog(errmes, msg); @@ -81,31 +81,10 @@ async function getChannelMessage(client, msg, MainID, SecondID) { const meschannel = client.channels.cache.get(MainID); return await meschannel.messages.fetch(SecondID); } catch (theError) { - return errLog(theError, msg, client); + return } } - return await msg.channel.messages.fetch(MainID).catch(e => {return errLog(e, msg, client)}); -} - -/** - * Get user object - * @param {Client} client - This client (this.client) - * @param {String} MainID - User ID | User Mention - * @returns {Promise} User object - * @example const user = getUser(this.client, args[0]); - */ -async function getUser(client, msg, MainID) { - if (MainID.startsWith('<') && MainID.endsWith('>')) { - MainID = MainID.slice(2, -1); - } - if (MainID.startsWith('!')) { - MainID = (MainID.slice(1)); - } - try { - return await client.users.fetch(MainID); - } catch (theError) { - return errLog(theError, msg, client); - } + return await msg.channel.messages.fetch(MainID).catch(e => {return}); } function execCB(error, stdout, stderr) { @@ -117,7 +96,7 @@ function execCB(error, stdout, stderr) { console.log('stderr:\n'+stderr); } -async function ranLog(msg, cmd, addition) { +async function ranLog(msg, cmd, addition) { return /* let errLogPath; if (msg.guild) { errLogPath = `../Guilds/${msg.guild.id}/Log/`; @@ -126,7 +105,7 @@ async function ranLog(msg, cmd, addition) { } let add = '\n'+addition; const b = new Date().toUTCString(); - return //console.log(inLog); + return //console.log(inLog); */ } /** @@ -441,7 +420,6 @@ module.exports = { cleanMentionID, multipleMembersFound, multipleRolesFound, multipleChannelsFound, findMemberRegEx, findChannelRegEx, findRoleRegEx, - getUser, getChannelMessage, errLog, execCB, ranLog, noPerm, trySend, tryDelete, tryReact, From 4140f5c49b9e0471e4277421f2e3de60a9be6b11 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 13:42:26 +0000 Subject: [PATCH 14/37] Working structures --- resources/structures.js | 102 +++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/resources/structures.js b/resources/structures.js index b9f1b9b..ae422d4 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -1,70 +1,64 @@ 'use strict'; -const { Structures } = require("discord.js"); +const { Structures, User } = require("discord.js"), +{ database } = require("../database/mongo"); -class Settings { - constructor(client, type, id) { - this.client = client; - this.type = type; - this.id = id; - } - - get(setting) { - collection(this.type).findOne({ id: this.id })[setting]; - } -} - -Structures.extend("Guild", Guild => { - return class GuildSettings extends Guild { +Structures.extend("Guild", g => { + return class Guild extends g { constructor(client, data) { super(client, data); - this.settings = new Settings(client, "Guild", this.id); + database.collection("Guild").findOne({document: this.id}).then(r => { + this.infractions = r?.moderation?.infractions; + this.moderation = r?.moderation?.settings; + this.defaultEmbed = r?.settings?.defaultEmbed; + }).catch(() => {}); } - embed = { - footer: { - text: undefined, - icon: undefined - }, - timestamp: false - }; - moderation = { - mute: { - role: undefined, - duration: { - date: undefined, - string: undefined - }, - log: undefined, - publicLog: undefined - }, - ban: { - duration: { - date: undefined, - string: undefined - }, - log: undefined, - publicLog: undefined - }, - kick: { - log: undefined, - publicLog: undefined + /** + * Get user infractions + * @param {User} get - User object + * @returns {Array} Infractions object + */ + async getInfractions(get) { + let found; + if (this.infractions.length > 0) { + found = []; + this.infractions.map(r => { + if (r) { + for (const inf of r) { + if (inf?.by) { + if (inf.by.includes(get)) { + found.push(inf); + } + } + } + } + }); } + return found; + } + async setDefaultEmbed(set) { + await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e}); + this.defaultEmbed = set; + return true; + } + async setModerationSettings(set) { + await database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}).catch(e => {throw e}); + this.moderation = set; + return true; } } }); -Structures.extend("User", User => { - return class Settings extends User { +Structures.extend("User", u => { + return class User extends u { constructor(client, data) { super(client, data); - this.settings = new Settings(client, User, this.id); + database.collection("User").findOne({document: this.id}).then(r => this.defaultEmbed = r?.settings?.defaultEmbed).catch(() => {}); + } + async setDefaultEmbed(set) { + await database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e}); + this.defaultEmbed = set; + return true; } - embed = { - footer: { - text: undefined, - icon: undefined - }, - timestamp: false - }; } }); \ No newline at end of file From b7b5d0dc5db3e7a7170b78daa06f50d0e8c945e0 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 17:26:11 +0000 Subject: [PATCH 15/37] Definitely working structures --- resources/structures.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/resources/structures.js b/resources/structures.js index ae422d4..3502ef9 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -15,26 +15,29 @@ Structures.extend("Guild", g => { } /** * Get user infractions - * @param {User} get - User object - * @returns {Array} Infractions object + * @param {String} get - User ID + * @returns {Promise} Infractions object */ async getInfractions(get) { - let found; - if (this.infractions.length > 0) { - found = []; - this.infractions.map(r => { - if (r) { - for (const inf of r) { - if (inf?.by) { - if (inf.by.includes(get)) { - found.push(inf); - } + try { + const r = await database.collection("Guild").findOne({ document: this.id }); + this.infractions = r?.moderation?.infractions; + let found = []; + if (this.infractions.length > 0) { + for (const inf of this.infractions) { + let added = false; + for (const user of inf.by) { + if (user.id === get) { + found.push(inf); + break; } } } - }); - } - return found; + if (found.length > 0) { + return found; + } + } + } catch (e) { } } async setDefaultEmbed(set) { await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e}); From 30839822c7dc69f722564789e56b97621253add5 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 17:27:54 +0000 Subject: [PATCH 16/37] Forgot a tiny thing --- resources/structures.js | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/structures.js b/resources/structures.js index 3502ef9..a70e273 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -25,7 +25,6 @@ Structures.extend("Guild", g => { let found = []; if (this.infractions.length > 0) { for (const inf of this.infractions) { - let added = false; for (const user of inf.by) { if (user.id === get) { found.push(inf); From 0a437fc5abf20439c639588f1b42fbb2a584b1c5 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:43:49 +0000 Subject: [PATCH 17/37] add: debug.js --- Main.js | 18 ++++++++++++------ resources/debug.js | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 resources/debug.js diff --git a/Main.js b/Main.js index 7d46e18..a0c8951 100644 --- a/Main.js +++ b/Main.js @@ -1,5 +1,7 @@ 'use strict'; +require("./database/mongo"); +require("./resources/structures"); const Commando = require('@iceprod/discord.js-commando'); const client = new Commando.Client({ owner: ['820696421912412191', '750335181285490760'], @@ -10,7 +12,7 @@ let configFile = require('./config.json'); const { errLog, trySend } = require('./resources/functions'); const { join } = require('path'); const { chatAnswer } = require("./resources/shaChat"); -require("./database/mongo"); +const { timestampAt } = require("./resources/debug"); client.registry .registerGroups([ @@ -32,8 +34,6 @@ client.setProvider( const guildLog = "840154722434154496"; -let shaGuild; - client.on('ready', async () => { //shaGuild = client.guilds.cache.map(g => g); //console.log(`Member in ${shaGuild.length} guilds.`); @@ -41,6 +41,12 @@ client.on('ready', async () => { }); client.on("message", async msg => { + if (msg.guild?.dbLoaded === false && !msg.author.bot) { + await msg.guild.dbLoad(); + } + if (msg.author.dbLoaded === false && !msg.author.bot) { + await msg.author.dbLoad(); + } if (msg.channel.id === "837178237322919966" && !msg.author.bot && !msg.content.toLowerCase().startsWith(client.commandPrefix+"chat")) { chatAnswer(client, msg); } @@ -55,12 +61,12 @@ client.on("guildMemberRemove", memberLeave => { }); client.on("guildCreate", newShaGuild => { - shaGuild = client.guilds.cache.map(g => g); + const shaGuild = client.guilds.cache.map(g => g); trySend(client, guildLog, `Joined **${newShaGuild.name}** (${newShaGuild.id}) <:awamazedLife:795227334339985418> I'm in ${shaGuild.length} servers now.`); }); client.on("guildDelete", leaveShaGuild => { - shaGuild = client.guilds.cache.map(g => g); + const shaGuild = client.guilds.cache.map(g => g); trySend(client, guildLog, `Left **${leaveShaGuild.name}** (${leaveShaGuild.id}) <:WhenLife:773061840351657984> I'm in ${shaGuild.length} servers now.`); }); @@ -72,6 +78,6 @@ process.on("uncaughtException", e => errLog(e, null, client)); process.on("unhandledRejection", e => errLog(e, null, client)); process.on("warning", e => errLog(e, null, client)); -// client.on("debug", (...args) => console.log(...args)); +//client.on("debug", (...args) => console.log(...args, timestampAt())); client.login(configFile.token); \ No newline at end of file diff --git a/resources/debug.js b/resources/debug.js new file mode 100644 index 0000000..5e3dd86 --- /dev/null +++ b/resources/debug.js @@ -0,0 +1,12 @@ +'use strict'; + +function timestampAt() { + const date = new Date(), + string = date.toLocaleTimeString("UTC", {"day": "numeric", "month": "2-digit", "year": "2-digit", "hour12": true}), + ampm = string.slice(string.length - 3), + miliseconds = date.getUTCMilliseconds(), + result = string.slice(0, -3) + "." + miliseconds + ampm; + return "At: " + result; +}; + +module.exports = { timestampAt } \ No newline at end of file From 36e63e566d8b1f4116915e65895f48f552216325 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:44:08 +0000 Subject: [PATCH 18/37] update unused packages --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index d73dc77..35429db 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,8 @@ "fs-extra": "^9.1.0", "lodash": "^4.17.21", "mongodb": "^3.6.6", - "nightmare": "^3.0.2", "node": "^15.12.0", "node-fetch": "^2.6.1", - "pup": "^0.0.2", "puppeteer": "^9.0.0", "sqlite": "^4.0.21", "sqlite3": "^5.0.2", From 6440b2ace228414ddf39e5925e8324a10b9654ad Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:48:12 +0000 Subject: [PATCH 19/37] fix: regex with coma --- cmds/utility/avatar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index c6aa093..305769c 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -2,7 +2,7 @@ const commando = require("@iceprod/discord.js-commando"); const { MessageEmbed } = require("discord.js"); -const { ranLog, errLog, trySend, findMemberRegEx, multipleMembersFound, cleanMentionID } = require("../../resources/functions"); +const { ranLog, errLog, trySend, findMemberRegEx, multipleMembersFound, cleanMentionID, tryReact } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const { randomColors } = require("../../config.json"); @@ -24,7 +24,7 @@ module.exports = class avatar extends commando.Command { errLog(docErr, msg, this.client); } const footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote; - const args = arg.trim().split(/(? 1) { - trySend(this.client, msg, "Manage messages permission required to show two or more avatar at once!"); + tryReact(msg, "cathmmLife:772716381874946068"); } } for (const ops of option) { From a2984d02c00cdc982d6d7e3f220023fe5533f945 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:48:24 +0000 Subject: [PATCH 20/37] add: debug.js --- resources/functions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/functions.js b/resources/functions.js index 88259e0..2f76ba9 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -3,6 +3,7 @@ const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js'); const { defaultErrorLogChannel } = require("../config.json"); const { database } = require("../database/mongo"); +const { timestampAt } = require('./debug'); const getColor = require('./getColor'); /** @@ -46,7 +47,7 @@ async function errLog(theError, msg, client, sendTheError, errorMessage, notify) logThis = ""; } const sendAt = client.channels.cache.get(defaultErrorLogChannel); - sendAt.send(logThis + inLogChannel.trim(),{split:true}); + sendAt.send(logThis + inLogChannel.trim() + timestampAt(),{split:true}); } catch (errmes) { errLog(errmes, msg); } From 8dd4dcff52951cee3a27ba87d27e4c2867d77887 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:49:16 +0000 Subject: [PATCH 21/37] little change, use double dash argument --- cmds/utility/lookup.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmds/utility/lookup.js b/cmds/utility/lookup.js index e5324f0..d42ea63 100644 --- a/cmds/utility/lookup.js +++ b/cmds/utility/lookup.js @@ -34,13 +34,12 @@ module.exports = class lookup extends commando.Command { const args = arg.split(/ +/); let [fetchedMember, fetchedRoles, fetchedChannels, memMes] = [[], [], [], ""]; const lowCaseArg0 = args[0].toLowerCase(); - if (lowCaseArg0 === "role") { + if (lowCaseArg0 === "--role") { if (args[1]) { - const cleanRoleID = cleanMentionID(arg.slice("role".length).trim()); - if (!/\D/.test(cleanRoleID)) { + const cleanRoleID = cleanMentionID(arg.slice("--role".length).trim()); + if (/^\d{17,19}$/.test(cleanRoleID)) { fetchedRoles.push(msg.guild.roles.cache.get(cleanRoleID)); - } - if (/\D/.test(cleanRoleID) || fetchedRoles[0] == null) { + } else { fetchedRoles = findRoleRegEx(msg, cleanRoleID); } if (fetchedRoles.length > 1) { @@ -53,13 +52,12 @@ module.exports = class lookup extends commando.Command { } } } else { - if (lowCaseArg0 === "channel") { + if (lowCaseArg0 === "--channel") { if (args[1]) { - const cleanChannelID = cleanMentionID(arg.slice("channel".length).trim()); - if (!/\D/.test(cleanChannelID)) { + const cleanChannelID = cleanMentionID(arg.slice("--channel".length).trim()); + if (/^\d{17,19}$/.test(cleanChannelID)) { fetchedChannels.push(msg.guild.roles.cache.get(cleanChannelID)); - } - if (/\D/.test(cleanChannelID) || fetchedChannels[0] == null) { + } else { fetchedChannels = findChannelRegEx(msg, cleanChannelID); } if (fetchedChannels.length > 1) { @@ -72,10 +70,13 @@ module.exports = class lookup extends commando.Command { } } } else { - if (!/\D/.test(arg)) { - fetchedMember.push(msg.guild.member(arg)); + if (arg.toLowerCase().startsWith("--member")) { + arg = arg.slice("--members".length).trim(); } - if (/\D/.test(arg) || fetchedMember[0] === null) { + arg = cleanMentionID(arg); + if (/^\d{17,19}$/.test(arg)) { + fetchedMember.push(msg.guild.member(arg)); + } else { fetchedMember = findMemberRegEx(msg, arg); } if (fetchedMember.length > 1) { From 51b70ea2f7827f88165cd94638fe52169c678e11 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:50:43 +0000 Subject: [PATCH 22/37] fix: split option no char --- cmds/utility/mesemb.js | 2 +- cmds/utility/mesinfo.js | 4 ++-- cmds/utility/uinfo.js | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmds/utility/mesemb.js b/cmds/utility/mesemb.js index 85d370a..6874f79 100644 --- a/cmds/utility/mesemb.js +++ b/cmds/utility/mesemb.js @@ -18,7 +18,7 @@ module.exports = class mesemb extends commando.Command { const message = await getChannelMessage(this.client,msg,args[0],args[1]); console.log(message.embeds); const mesemb = '```js\n'+JSON.stringify(message.embeds, null, 2)+'```'; - const result = await trySend(this.client, msg, {content:'Collected:'+mesemb,split:{maxLength:2000,char: ", " || ",\n" || ". " || ".\n" || "," || ".",append:',```',prepend:'```js\n'}}); + const result = await trySend(this.client, msg, {content:'Collected:'+mesemb,split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); return ranLog(msg,'mesemb',result.content); } catch (e) { noPerm(msg); diff --git a/cmds/utility/mesinfo.js b/cmds/utility/mesinfo.js index 306a828..fd6514b 100644 --- a/cmds/utility/mesinfo.js +++ b/cmds/utility/mesinfo.js @@ -26,11 +26,11 @@ module.exports = class mesinfo extends commando.Command { 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: ", " || ",\n" || ". " || ".\n" || "," || ".",append:',```',prepend:'```js\n'}}); + 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, false, "", false, defaultErrorLogChannel); + return errLog(e, msg, this.client); } } } diff --git a/cmds/utility/uinfo.js b/cmds/utility/uinfo.js index 73658a6..8cdae84 100644 --- a/cmds/utility/uinfo.js +++ b/cmds/utility/uinfo.js @@ -14,12 +14,14 @@ module.exports = class uinfo extends commando.Command { } async run(msg, arg) { try { - let profile, - hmm; + let profile; if (arg.length > 0) { - hmm = cleanMentionID(arg); + const hmm = cleanMentionID(arg); if (/^\d{17,19}$/.test(hmm)) { profile = this.client.users.cache.get(hmm); + if (!profile) { + profile = await this.client.users.fetch(hmm); + } } else { profile = findMemberRegEx(msg, hmm)[0].user; } @@ -27,20 +29,20 @@ module.exports = class uinfo extends commando.Command { profile = msg.author; } const member = msg.guild.member(profile); - let result = 'User: '+profile.tag+'```js\n'; + let result = ""; if (profile) { - result = result+JSON.stringify(profile, null, 2)+'```'; + result += 'User: '+profile.tag+'```js\n' + JSON.stringify(profile, null, 2)+'```'; } if (member) { - result = result+'As member: '+member.displayName+'```js\n'+JSON.stringify(member, null, 2)+'```'; + result += 'As member: '+member.displayName+'```js\n'+JSON.stringify(member, null, 2)+'```'; if ((member.displayColor)) { - result = result+'Display color:```js\n'+member.displayColor+'```'; + result += 'Display color:```js\n'+member.displayColor+'```'; } } - trySend(this.client, msg, result, {split:{maxLength:2000,char: ", " || ",\n" || ". " || ".\n" || "," || ".",append:',```',prepend:'```js\n'}}); + trySend(this.client, msg, result, {split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); return ranLog(msg,'profile', msg.content); } catch (e) { - return trySend(this.client, msg, "Ya lookin for ya lover? 404 not found."); + return trySend(this.client, msg, "404 ERROR not found~"); } } }; \ No newline at end of file From 3f02eb70d09320285df6675a9fc3ecdb2c55ec8f Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:51:25 +0000 Subject: [PATCH 23/37] use: setOnInsert --- cmds/utility/quoteotd.js | 6 +++--- cmds/utility/setfootq.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index d693518..a021420 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -36,13 +36,13 @@ module.exports = class quoteotd extends commando.Command { if (!this.client.channels.cache.get(data)) { return trySend(this.client, msg, 'Invalid/unknown channel provided! Try mentioning a channel or use `ChannelID`'); } else { - col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.channel": data}}, { upsert: true }); + col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.channel": data}, $setOnInsert: { document: msg.guild.id }}, { upsert: true }); result = result+`Channel set to \`${this.client.channels.cache.get(data).name}\`\n`; } } if (startW.startsWith('text')) { data = arr.slice('text'.length).trim(); - col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.footerText": data}}, { upsert: true }); + col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.footerText": data}, $setOnInsert: { document: msg.guild.id }}, { upsert: true }); result = result+`Footer text set to \`${data}\`\n`; } if (startW.startsWith('icon')) { @@ -50,7 +50,7 @@ module.exports = class quoteotd extends commando.Command { if (!/^http/.test(data)) { return trySend(this.client, msg, 'Invalid icon url provided!'); } else { - col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.footerIcon": data}}, { upsert: true }); + col.updateOne({document: msg.guild.id}, {$set: {"settings.quoteOTD.footerIcon": data}, $setOnInsert: { document: msg.guild.id }}, { upsert: true }); result = result+`Footer icon set!\n`; } } diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index f9ce8f6..e427c40 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -17,14 +17,14 @@ module.exports = class setfootq extends commando.Command { } async run(msg, args) { try { - if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD" && !this.client.owners.includes(msg.author))) { + if (msg.guild ? !msg.guild.member(msg.author).hasPermission("MANAGE_GUILD") : false && !this.client.owners.includes(msg.author.id)) { return trySend(this.client, msg, 'No lol'); } const data = msg.guild ? "Guild" : "User"; const col = database.collection(data); const doc = msg.guild?.id ?? msg.author.id; const oldQ = await col.findOne({document: doc}); - col.updateOne({document: doc}, {$set: {"settings.defaultEmbed.footerQuote": args.trim()}}, { upsert: true }, async (e) => { + col.updateOne({document: doc}, {$set: {"settings.defaultEmbed.footerQuote": args.trim()}, $setOnInsert: { document: msg.guild?.id ?? msg.author.id }}, { upsert: true }, async (e) => { if (e) { return errLog(e, msg, this.client); } From 986ac3e8d633a824b58b47a0939e0d03ffe94a3a Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:52:52 +0000 Subject: [PATCH 24/37] add: emoteMessage.js --- cmds/utility/say.js | 2 ++ cmds/utility/send.js | 10 ++++++++-- resources/emoteMessage.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 resources/emoteMessage.js diff --git a/cmds/utility/say.js b/cmds/utility/say.js index 6ea45da..7c4df27 100644 --- a/cmds/utility/say.js +++ b/cmds/utility/say.js @@ -1,6 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); +const emoteMessage = require("../../resources/emoteMessage"); const { ranLog, trySend, tryDelete } = require("../../resources/functions"); module.exports = class say extends commando.Command { @@ -17,6 +18,7 @@ module.exports = class say extends commando.Command { if (!args) { args = noArgs; } + args = emoteMessage(this.client, args); const sendThis = {content:args, disableMentions:"all"}; if (msg.member?.hasPermission("ADMINISTRATOR")) { sendThis.disableMentions = "none"; diff --git a/cmds/utility/send.js b/cmds/utility/send.js index 246d6f7..3365477 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -1,5 +1,6 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); +const emoteMessage = require("../../resources/emoteMessage"); const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); module.exports = class send extends commando.Command { @@ -19,7 +20,7 @@ module.exports = class send extends commando.Command { return trySend(this.client, msg, 'Where?!?'); } const search = cleanMentionID(comarg[0]), - sendTheMes = args.slice(comarg[0].length).trim(); + sendTheMes = emoteMessage(this.client, args.slice(comarg[0].length).trim()); let channel; if (/^\d{17,19}$/.test(search)) { channel = msg.guild.channels.cache.get(search); @@ -27,7 +28,12 @@ module.exports = class send extends commando.Command { if (!channel) { channel = findChannelRegEx(msg, search, ["category", "voice"])[0]; if (!channel) { - return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); + if (this.client.owners.includes(msg.author.id)) { + channel = this.client.channels.cache.get(search); + } + if (!channel) { + return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); + } } } if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES") || !channel.permissionsFor(msg.author).has("VIEW_CHANNEL")) { diff --git a/resources/emoteMessage.js b/resources/emoteMessage.js new file mode 100644 index 0000000..37e101a --- /dev/null +++ b/resources/emoteMessage.js @@ -0,0 +1,28 @@ +'use strict'; + +module.exports = function emoteMessage(client, content) { + const emotes = content.match(/(?)/g); + if (emotes.length > 0) { + let theEmotes = []; + for (const emoteName of emotes) { + let findThis = emoteName.slice(1, -1); + const findEmote = client.emojis.cache.array(); + let found; + for (const emote of findEmote) { + if (emote.name.toLowerCase() === findThis.toLowerCase()) { + found = emote; + break; + } + } + theEmotes.push(found); + } + if (theEmotes.length > 0) { + for (let index = 0; index < emotes.length; index++) { + if (theEmotes[index]) { + content = content.replace(emotes[index], `<${theEmotes[index].animated ? "a" : ""}:${theEmotes[index].name}:${theEmotes[index].id}>`); + } + } + } + } + return content; +} \ No newline at end of file From 4281c713cbf20ea59c632c69dc216159f6f3a3b1 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 22:53:44 +0000 Subject: [PATCH 25/37] Improvement: load when present --- resources/structures.js | 56 +++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/resources/structures.js b/resources/structures.js index a70e273..d89d0d9 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -1,17 +1,24 @@ 'use strict'; -const { Structures, User } = require("discord.js"), +const { Structures } = require("discord.js"), { database } = require("../database/mongo"); +const { errLog } = require("./functions"); Structures.extend("Guild", g => { return class Guild extends g { constructor(client, data) { super(client, data); - database.collection("Guild").findOne({document: this.id}).then(r => { + this.dbLoaded = false; + } + async dbLoad() { + const ret = await database.collection("Guild").findOne({document: this.id}).then((r, j) => { + if (j) return errLog(j, null, this.client); this.infractions = r?.moderation?.infractions; this.moderation = r?.moderation?.settings; this.defaultEmbed = r?.settings?.defaultEmbed; - }).catch(() => {}); + return this.dbLoaded = true; + }); + return ret; } /** * Get user infractions @@ -38,15 +45,21 @@ Structures.extend("Guild", g => { } } catch (e) { } } - async setDefaultEmbed(set) { - await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e}); - this.defaultEmbed = set; - return true; + setDefaultEmbed(set) { + const ret = database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => { + if (e) return errLog(e, null, this.client); + this.defaultEmbed = set; + return true; + }); + return ret; } - async setModerationSettings(set) { - await database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}).catch(e => {throw e}); - this.moderation = set; - return true; + setModerationSettings(set) { + const ret = database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}, (e) => { + if (e) return errLog(e, null, this.client); + this.moderation = set; + return true; + }); + return ret; } } }); @@ -55,12 +68,23 @@ Structures.extend("User", u => { return class User extends u { constructor(client, data) { super(client, data); - database.collection("User").findOne({document: this.id}).then(r => this.defaultEmbed = r?.settings?.defaultEmbed).catch(() => {}); + this.dbLoaded = false; } - async setDefaultEmbed(set) { - await database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e}); - this.defaultEmbed = set; - return true; + async dbLoad() { + const ret = await database.collection("User").findOne({document: this.id}).then((r, j) => { + if (j) return errLog(j, null, this.client); + this.defaultEmbed = r?.settings?.defaultEmbed; + return this.dbLoaded = true; + }); + return ret; + } + setDefaultEmbed(set) { + const ret = database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => { + if (e) return errLog(e, null, this.client); + this.defaultEmbed = set; + return true; + }); + return ret; } } }); \ No newline at end of file From 63cfd01076374adc8f9bca95c67c2a392bf085c8 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 23:06:03 +0000 Subject: [PATCH 26/37] Fix: small bug --- resources/emoteMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/emoteMessage.js b/resources/emoteMessage.js index 37e101a..093eab9 100644 --- a/resources/emoteMessage.js +++ b/resources/emoteMessage.js @@ -2,7 +2,7 @@ module.exports = function emoteMessage(client, content) { const emotes = content.match(/(?)/g); - if (emotes.length > 0) { + if (emotes?.length > 0) { let theEmotes = []; for (const emoteName of emotes) { let findThis = emoteName.slice(1, -1); From 5091dce3b584a5309f9f1a711ba9782389f7d9b2 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 23:07:24 +0000 Subject: [PATCH 27/37] Owners are users. Not ID hm --- cmds/utility/send.js | 2 +- cmds/utility/servav.js | 2 +- cmds/utility/setfootq.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmds/utility/send.js b/cmds/utility/send.js index 3365477..ed67185 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -28,7 +28,7 @@ module.exports = class send extends commando.Command { if (!channel) { channel = findChannelRegEx(msg, search, ["category", "voice"])[0]; if (!channel) { - if (this.client.owners.includes(msg.author.id)) { + if (this.client.owners.includes(msg.author)) { channel = this.client.channels.cache.get(search); } if (!channel) { diff --git a/cmds/utility/servav.js b/cmds/utility/servav.js index e432121..be7aa8a 100644 --- a/cmds/utility/servav.js +++ b/cmds/utility/servav.js @@ -31,7 +31,7 @@ module.exports = class servav extends commando.Command { } const footerQuote = res?.["settings"]?.defaultEmbed?.footerQuote; let icon, target; - if (server_ID && this.client.owners.includes(msg.author.id)) { + if (server_ID && this.client.owners.includes(msg.author)) { if (!/\D/.test(server_ID)) { target = this.client.guilds.cache.get(server_ID); } else { diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index e427c40..d164ecf 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -17,7 +17,7 @@ module.exports = class setfootq extends commando.Command { } async run(msg, args) { try { - if (msg.guild ? !msg.guild.member(msg.author).hasPermission("MANAGE_GUILD") : false && !this.client.owners.includes(msg.author.id)) { + if (msg.guild ? !msg.guild.member(msg.author).hasPermission("MANAGE_GUILD") : false && !this.client.owners.includes(msg.author)) { return trySend(this.client, msg, 'No lol'); } const data = msg.guild ? "Guild" : "User"; From d747c3bed67b96468591c71af4cdc24ec34ac678 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Thu, 27 May 2021 23:17:35 +0000 Subject: [PATCH 28/37] less sensitive rule for detection --- resources/emoteMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/emoteMessage.js b/resources/emoteMessage.js index 093eab9..2c761c4 100644 --- a/resources/emoteMessage.js +++ b/resources/emoteMessage.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function emoteMessage(client, content) { - const emotes = content.match(/(?)/g); + const emotes = content.match(/:\w{1,32}:(?!\d{17,19}>)/g); if (emotes?.length > 0) { let theEmotes = []; for (const emoteName of emotes) { From 11a0fcb78de9d217237446d71b9f567066332dcd Mon Sep 17 00:00:00 2001 From: Neko Life Date: Fri, 28 May 2021 23:38:54 +0000 Subject: [PATCH 29/37] backup --- .gitignore | 1 + Main.js | 4 +-- cmds/moderation/mute.js | 44 ++++++++++++++++++++++++++++----- cmds/moderation/src/duration.js | 2 ++ cmds/utility/send.js | 3 +-- resources/functions.js | 24 ++++++++++++------ resources/scheduler/unmute.js | 5 ++++ resources/shaChat.js | 4 +-- resources/structures.js | 14 +++++++++++ 9 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 cmds/moderation/src/duration.js create mode 100644 resources/scheduler/unmute.js diff --git a/.gitignore b/.gitignore index bbe3211..11e51e6 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ build/Release node_modules/ jspm_packages/ exp/ +cmds/experiment/ # Snowpack dependency directory (https://snowpack.dev/) web_modules/ diff --git a/Main.js b/Main.js index a0c8951..6317c62 100644 --- a/Main.js +++ b/Main.js @@ -52,7 +52,7 @@ client.on("message", async msg => { } if (!msg.guild) { - //console.log(`(${msg.channel.recipient.id}) ${msg.channel.recipient.tag}: (${msg.author.id}) ${msg.author.tag}: ${msg.content}`); + console.log(`(${msg.channel.recipient.id}) ${msg.channel.recipient.tag}: (${msg.author.id}) ${msg.author.tag}: ${msg.content}`); } }); @@ -78,6 +78,6 @@ process.on("uncaughtException", e => errLog(e, null, client)); process.on("unhandledRejection", e => errLog(e, null, client)); process.on("warning", e => errLog(e, null, client)); -//client.on("debug", (...args) => console.log(...args, timestampAt())); +client.on("debug", (...args) => console.log(...args, timestampAt())); client.login(configFile.token); \ No newline at end of file diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index 0734a3c..2e1d69a 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -7,6 +7,38 @@ const col = database.collection("Guild"); const schedule = database.collection("Schedule"); const { scheduler } = require("../../resources/scheduler"); +/*{ + footer: { + text: undefined, + icon: undefined + }, + timestamp: false + }; + { + mute: { + role: undefined, + duration: { + date: undefined, + string: undefined + }, + log: undefined, + publicLog: undefined + }, + ban: { + duration: { + date: undefined, + string: undefined + }, + log: undefined, + publicLog: undefined + }, + kick: { + log: undefined, + publicLog: undefined + } + } +*/ + module.exports = class mute extends commando.Command { constructor(client) { super(client, { @@ -30,7 +62,7 @@ module.exports = class mute extends commando.Command { defaultDurationDoc = muteSettingsDoc?.defaultDuration, infractionsDoc = modDoc?.infractions, args = arg.trim().split(/(?> [--duration -- | --log --]\` to set it up.`); + return trySend(this.clientPermissions, msg, `No mute role configured! Run \`${msg.guild.commandPrefix}${this.name} --settings <--role --> [--duration -- | --log --]\` to set it up.`); } if (duration.year > 275500) { duration.year = 275500; } let untilDate = new Date(String(duration.year), String(duration.month), String(duration.date), String(duration.hour), String(duration.minute), String(duration.second)); - if (untilDate.toUTCString() === invokedAt.toUTCString() && !settingDuration) { + if (untilDate?.toUTCString() === invokedAt.toUTCString() && !settingDuration) { if (defaultDurationDoc?.date?.valueOf() > 0) { untilDate = new Date(invokedAt.valueOf() + defaultDurationDoc.date.valueOf() - 1000); } else { untilDate = "Indefinite"; } - } + } if (untilDate !== "Indefinite") { timeForMessage = []; const elapsedTime = new Date(untilDate.valueOf() - invokedAt.valueOf() + 1000), @@ -251,8 +283,8 @@ module.exports = class mute extends commando.Command { resultMsg += `Can't find user: **${usermention.trim()}**\n`; } } else { - if (!settingUp && mentions.length === 1 && mentions[0].length === 0) { - return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`"); + if (!settingUp && mentions[0].length === 0) { + return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`. Use `,` to provide more than one user. Use `--` to split arguments.\nExample:```js\n" + `${msg.guild.commandPrefix}${this.name} 832423842785623423, @Shasha#1234, retard wanna get muted, #6969, ^fuck (ur)? .{5}#\\d\\d69$--69y69mo69w420d420h420m420s--Saying "joe"`); } } } diff --git a/cmds/moderation/src/duration.js b/cmds/moderation/src/duration.js new file mode 100644 index 0000000..eb109ab --- /dev/null +++ b/cmds/moderation/src/duration.js @@ -0,0 +1,2 @@ +'use strict'; + diff --git a/cmds/utility/send.js b/cmds/utility/send.js index ed67185..bb6a837 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); const emoteMessage = require("../../resources/emoteMessage"); -const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); +const { ranLog, errLog, trySend, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); module.exports = class send extends commando.Command { constructor(client) { @@ -48,7 +48,6 @@ module.exports = class send extends commando.Command { sendThis.disableMentions = "none"; } const send = await trySend(this.client, channel, sendThis); - sentAdCheck(send); const filter = () => true, collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); collector.on('collect', r => { diff --git a/resources/functions.js b/resources/functions.js index 2f76ba9..cb15a4a 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -187,7 +187,7 @@ function noPerm(msg) { * @param {MessageOptions} content - ({content:content,optionblabla}) * @returns {Promise} Sent message object */ -async function trySend(client, msg, content) { +async function trySend(client, msg, content, adCheck = true) { //console.log(...content); let msgOf; if (msg?.channel) { @@ -199,6 +199,15 @@ async function trySend(client, msg, content) { msgOf = msg; } } + if (adCheck) { + if (content.content) { + content.content = sentAdCheck(content.content); + } else { + if (typeof content === "string") { + content = sentAdCheck(content); + } + } + } const sentMes = await msgOf.send(content) .catch((e) => { console.error(e); @@ -207,7 +216,6 @@ async function trySend(client, msg, content) { } return }); - sentAdCheck(sentMes); return sentMes; } @@ -234,13 +242,13 @@ function tryReact(msg, reaction) { /** * Check a message sent by client for ads - * @param {Message} sent - Sent message object (await msg.channel.send("discord.gg/banana")) + * @param {String} content - Sent message object (await msg.channel.send("discord.gg/banana")) */ -function sentAdCheck(sent) { - if (sent) { - if (/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/.test(sent.content)) { - let newCont = sent.content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); - sent.edit(newCont, `Command abuse: Contain server invite link.`); +function sentAdCheck(content) { + if (content.length > 5) { + if (/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/.test(content)) { + let newCont = content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); + return newCont; } } } diff --git a/resources/scheduler/unmute.js b/resources/scheduler/unmute.js new file mode 100644 index 0000000..0fedcb2 --- /dev/null +++ b/resources/scheduler/unmute.js @@ -0,0 +1,5 @@ +'use strict'; + +require("@iceprod/discord.js-commando"); + +module.exports.unmuteExec = async function () {} \ No newline at end of file diff --git a/resources/shaChat.js b/resources/shaChat.js index daa61fd..f745a4d 100644 --- a/resources/shaChat.js +++ b/resources/shaChat.js @@ -24,7 +24,7 @@ const URL = [ ]; const browser = puppeteer.launch(); const page1 = browser.then(r => r.newPage()); -page1.then(r => r.goto(URL[10]).catch(console.error)); +page1.then(r => r.goto(URL[1]).catch(console.error)); /** * Chat with Shasha @@ -59,7 +59,7 @@ async function shaChat(client, index, question) { */ async function fetchAnswer(page, index) { try { - await page.waitForSelector(`#answer > div:nth-child(${index})`, {timeout:5000}).catch(() => {}); + await page.waitForSelector(`#answer > div:nth-child(${index})`).catch(() => {}); const result = await page.evaluate((index) => { const res = document.querySelector(`#answer > div:nth-child(${index})`).childNodes[4].textContent; return res; diff --git a/resources/structures.js b/resources/structures.js index d89d0d9..701c292 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -45,6 +45,20 @@ Structures.extend("Guild", g => { } } catch (e) { } } + async addInfraction(add) { + try { + const r = await database.collection("Guild").findOne({ document: this.id }); + this.infractions = r?.moderation?.infractions; + const ret = database.collection("Guild").updateOne({document: this.id}, {$push:{"moderation.infractions":add}}, (e, r) => { + if (e) return errLog(e, null, this.client); + if (r) { + this.infractions.push(add); + return true; + }; + }); + return ret; + } catch (e) { } + } setDefaultEmbed(set) { const ret = database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => { if (e) return errLog(e, null, this.client); From 129e070cb81d2c159d333ab143fe235b40a72d45 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Fri, 28 May 2021 23:55:53 +0000 Subject: [PATCH 30/37] disabled shaChat --- Main.js | 8 ++++---- cmds/fun/chat.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Main.js b/Main.js index 6317c62..fe66c00 100644 --- a/Main.js +++ b/Main.js @@ -11,7 +11,7 @@ const sqlite = require('sqlite'); let configFile = require('./config.json'); const { errLog, trySend } = require('./resources/functions'); const { join } = require('path'); -const { chatAnswer } = require("./resources/shaChat"); +//const { chatAnswer } = require("./resources/shaChat"); const { timestampAt } = require("./resources/debug"); client.registry @@ -46,14 +46,14 @@ client.on("message", async msg => { } if (msg.author.dbLoaded === false && !msg.author.bot) { await msg.author.dbLoad(); - } + }/* if (msg.channel.id === "837178237322919966" && !msg.author.bot && !msg.content.toLowerCase().startsWith(client.commandPrefix+"chat")) { chatAnswer(client, msg); } if (!msg.guild) { console.log(`(${msg.channel.recipient.id}) ${msg.channel.recipient.tag}: (${msg.author.id}) ${msg.author.tag}: ${msg.content}`); - } + } */ }); client.on("guildMemberRemove", memberLeave => { @@ -78,6 +78,6 @@ process.on("uncaughtException", e => errLog(e, null, client)); process.on("unhandledRejection", e => errLog(e, null, client)); process.on("warning", e => errLog(e, null, client)); -client.on("debug", (...args) => console.log(...args, timestampAt())); +//client.on("debug", (...args) => console.log(...args, timestampAt())); client.login(configFile.token); \ No newline at end of file diff --git a/cmds/fun/chat.js b/cmds/fun/chat.js index 15c8a4b..55554c0 100644 --- a/cmds/fun/chat.js +++ b/cmds/fun/chat.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { chatAnswer } = require("../../resources/shaChat"); +//const { chatAnswer } = require("../../resources/shaChat"); module.exports = class chat extends commando.Command { constructor(client) { @@ -13,6 +13,6 @@ module.exports = class chat extends commando.Command { }); } async run(msg) { - chatAnswer(this.client, msg); + //chatAnswer(this.client, msg); } }; \ No newline at end of file From de80d353e75c7dc2ede6c50bfc17bad6b3b05834 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sat, 29 May 2021 01:27:05 +0000 Subject: [PATCH 31/37] adCheck small bug --- resources/functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/functions.js b/resources/functions.js index cb15a4a..ac57c46 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -247,10 +247,10 @@ function tryReact(msg, reaction) { function sentAdCheck(content) { if (content.length > 5) { if (/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/.test(content)) { - let newCont = content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); - return newCont; + content = content.replace(/(https:\/\/)?(www\.)?discord\.gg\/(?:\w{2,15}(?!\w)(?= *))/, '`Some invite link goes here`'); } } + return content; } /** From e27516e60e51b649d109a9cb5ce7533b242d37bf Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sat, 29 May 2021 15:33:26 +0000 Subject: [PATCH 32/37] fix: split message --- cmds/utility/avatar.js | 2 +- cmds/utility/lookup.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index 305769c..6689c16 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -131,7 +131,7 @@ module.exports = class avatar extends commando.Command { 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: ", " || ",\n" || ". " || ".\n" || "," || ".",append:',```',prepend:'```md\n# ' }}); + trySend(this.client, msg, { embed: embelement, content: contelement, split:{maxLength:2000,char: ",",append:',```',prepend:'```js' }}); } return ranLog(msg,'avatar',arg); }); diff --git a/cmds/utility/lookup.js b/cmds/utility/lookup.js index d42ea63..58e5662 100644 --- a/cmds/utility/lookup.js +++ b/cmds/utility/lookup.js @@ -90,7 +90,7 @@ module.exports = class lookup extends commando.Command { } } if (memMes.length > 0) { - return trySend(this.client, msg, memMes); + return trySend(this.client, msg, { content: memMes, split: { char: ",", append: ",```", prepend: "```js", maxLength: 2000 } }); } } }; \ No newline at end of file From 40599b7071107016979943a0f5cfbb33d85588f3 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 13:47:44 +0000 Subject: [PATCH 33/37] 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)); } /** From 2f247ddaa95a87301f6950299fc439905f84112d Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 17:56:05 +0000 Subject: [PATCH 34/37] tiny fix --- cmds/utility/embmaker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index cb4dfa6..b909526 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -354,7 +354,9 @@ module.exports = class embmaker extends commando.Command { } sent.push(channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg))); } - tryReact(msg, "a:yesLife:794788847996370945"); + if (sent.length > 0) { + tryReact(msg, "a:yesLife:794788847996370945"); + } return sent; } catch (e) { return errLog(e, msg, this.client, true, "", true); From 2aeb498e366a5f882ee15ff0f789b17b1c159027 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 20:50:21 +0000 Subject: [PATCH 35/37] shorter fetch channel function --- cmds/utility/embmaker.js | 6 ++---- cmds/utility/send.js | 14 ++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index b909526..d4cbc3a 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -276,10 +276,8 @@ module.exports = class embmaker extends commando.Command { } 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); - } + if (!channel && this.client.owners.includes(msg.author.id)) { + channel = this.client.channels.cache.get(ID); } } else { channel = findChannelRegEx(msg, ID, ["category", "voice"])[0]; diff --git a/cmds/utility/send.js b/cmds/utility/send.js index c8a8446..f0a3867 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -24,17 +24,15 @@ module.exports = class send extends commando.Command { let channel; if (/^\d{17,19}$/.test(search)) { channel = msg.guild.channels.cache.get(search); + if (!channel && this.client.owners.includes(msg.author)) { + channel = this.client.channels.cache.get(search); + } } if (!channel) { channel = findChannelRegEx(msg, search, ["category", "voice"])[0]; - if (!channel) { - if (this.client.owners.includes(msg.author)) { - channel = this.client.channels.cache.get(search); - } - if (!channel) { - return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); - } - } + } + if (!channel) { + return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>"); } if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES") || !channel.permissionsFor(msg.author).has("VIEW_CHANNEL")) { return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>"); From 81c0ea6a7bed442fc1fb8c564d9520e495d60b6f Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 20:50:57 +0000 Subject: [PATCH 36/37] Infdefinite if Invalid Date --- cmds/moderation/mute.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index 2e1d69a..d9e2949 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -182,10 +182,8 @@ module.exports = class mute extends commando.Command { if (!roleConfCheck && !settingUp) { return trySend(this.clientPermissions, msg, `No mute role configured! Run \`${msg.guild.commandPrefix}${this.name} --settings <--role --> [--duration -- | --log --]\` to set it up.`); } - if (duration.year > 275500) { - duration.year = 275500; - } let untilDate = new Date(String(duration.year), String(duration.month), String(duration.date), String(duration.hour), String(duration.minute), String(duration.second)); + if (untilDate.toString() === "Invalid Date") untilDate = "Indefinite"; if (untilDate?.toUTCString() === invokedAt.toUTCString() && !settingDuration) { if (defaultDurationDoc?.date?.valueOf() > 0) { untilDate = new Date(invokedAt.valueOf() + defaultDurationDoc.date.valueOf() - 1000); @@ -193,7 +191,7 @@ module.exports = class mute extends commando.Command { untilDate = "Indefinite"; } } - if (untilDate !== "Indefinite") { + if (untilDate instanceof Date) { timeForMessage = []; const elapsedTime = new Date(untilDate.valueOf() - invokedAt.valueOf() + 1000), elapsed = [ @@ -284,7 +282,7 @@ module.exports = class mute extends commando.Command { } } else { if (!settingUp && mentions[0].length === 0) { - return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`. Use `,` to provide more than one user. Use `--` to split arguments.\nExample:```js\n" + `${msg.guild.commandPrefix}${this.name} 832423842785623423, @Shasha#1234, retard wanna get muted, #6969, ^fuck (ur)? .{5}#\\d\\d69$--69y69mo69w420d420h420m420s--Saying "joe"`); + return trySend(this.client, msg, "Who do you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`. Use `,` to provide more than one user. Use `--` to split arguments.\nExample:```js\n" + `${msg.guild.commandPrefix}${this.name} 832423842785623423, @Shasha#1234, retard wanna get muted, #6969, ^fuck (ur)? .{5}#\\d\\d69$--69y69mo69w420d420h420m420s--Saying "joe"\`\`\``); } } } @@ -313,7 +311,7 @@ module.exports = class mute extends commando.Command { infractionToDoc = { infraction: infractionCase ? infractionCase + 1 : 1, by: targetUser, - moderator: `**${msg.author.tag}** <@${msg.author.id}> (${msg.author.id})`, + moderator: msg.author, punishment: "mute", at: invokedAt, for: timeForMessage, From b338b6622fe9fddde98d3568605c2af666d72d4e Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 30 May 2021 22:39:46 +0000 Subject: [PATCH 37/37] ranlog --- cmds/image/neko.js | 8 ++--- cmds/moderation/mute.js | 2 +- cmds/utility/embmaker.js | 1 + cmds/utility/mesemb.js | 2 +- cmds/utility/mesinfo.js | 2 +- cmds/utility/newquoteotd.js | 3 +- cmds/utility/quoteotd.js | 5 ++- cmds/utility/say.js | 5 +-- cmds/utility/send.js | 1 + cmds/utility/setfootq.js | 1 + cmds/utility/uinfo.js | 2 +- resources/functions.js | 63 ++++++++++++++++++------------------- 12 files changed, 47 insertions(+), 48 deletions(-) diff --git a/cmds/image/neko.js b/cmds/image/neko.js index 44d8c05..90cf592 100644 --- a/cmds/image/neko.js +++ b/cmds/image/neko.js @@ -13,11 +13,9 @@ module.exports = class neko extends commando.Command { }); } async run(msg) { - const aut = msg.guild ? msg.guild.member(msg.author) : msg.author; - const title = `${msg.guild ? aut.displayName : aut.username}! ~Nyann~ (UwU) <3`; + const title = `${msg.guild ? msg.member.displayName : msg.author.username}! ~Nyann~ (UwU) <3`; const image = `https://nekos.best/nekos/${String(Math.floor(Math.random() * 314)).padStart(4, '0')}.png`; - const emb = await defaultImageEmbed(this.client, msg, aut, image, title); - trySend(this.client, msg, emb); - return ranLog(msg, "neko"); + const emb = await defaultImageEmbed(msg, image, title); + return trySend(this.client, msg, emb); } }; \ No newline at end of file diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index d9e2949..072263a 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -245,7 +245,7 @@ module.exports = class mute extends commando.Command { defaultDurationDoc = muteSettingsDoc?.defaultDuration, logChannelDoc = muteSettingsDoc?.logChannel, roleDoc = muteSettingsDoc?.role; - let settings = await defaultImageEmbed(this.client, msg, msg.member); + let settings = await defaultImageEmbed(msg); settings .setTitle("Mute Configuration") .addField("Role", roleDoc ? "<@&"+roleDoc+">" : "Not set") diff --git a/cmds/utility/embmaker.js b/cmds/utility/embmaker.js index d4cbc3a..4354059 100644 --- a/cmds/utility/embmaker.js +++ b/cmds/utility/embmaker.js @@ -355,6 +355,7 @@ module.exports = class embmaker extends commando.Command { if (sent.length > 0) { tryReact(msg, "a:yesLife:794788847996370945"); } + ranLog(this.client, msg, ("```js\n" + JSON.stringify(embed, null, 2) + "```").slice(0, 2048)); return sent; } catch (e) { return errLog(e, msg, this.client, true, "", true); diff --git a/cmds/utility/mesemb.js b/cmds/utility/mesemb.js index 2b0da9a..b5c5ea3 100644 --- a/cmds/utility/mesemb.js +++ b/cmds/utility/mesemb.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { getChannelMessage, ranLog, errLog, noPerm, trySend } = require("../../resources/functions"); +const { getChannelMessage, trySend } = require("../../resources/functions"); module.exports = class mesemb extends commando.Command { constructor(client) { diff --git a/cmds/utility/mesinfo.js b/cmds/utility/mesinfo.js index 581de16..303571b 100644 --- a/cmds/utility/mesinfo.js +++ b/cmds/utility/mesinfo.js @@ -1,7 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { errLog, getChannelMessage, ranLog, noPerm, trySend } = require("../../resources/functions"); +const { getChannelMessage, trySend } = require("../../resources/functions"); module.exports = class mesinfo extends commando.Command { constructor(client) { diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index 3465b7e..6372e33 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -2,7 +2,7 @@ const commando = require("@iceprod/discord.js-commando"); const { MessageEmbed } = require("discord.js"); -const { getChannelMessage, ranLog, errLog, noPerm, tryReact, trySend } = require("../../resources/functions"); +const { getChannelMessage, errLog, noPerm, tryReact, trySend, ranLog } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const col = database.collection("Guild"); @@ -57,6 +57,7 @@ module.exports = class newquoteotd extends commando.Command { } return sent; } + ranLog(this.client, msg, "New quote: " + msg.content + "\nBy: " + mes.author.tag + ` (${mes.author.id})`); 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); diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index d8e5f7a..5063d4a 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -1,9 +1,7 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { writeJSONSync } = require("fs-extra"); -const { join } = require("path"); -const { ranLog, trySend } = require("../../resources/functions"); +const { trySend, ranLog } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const col = database.collection("Guild"); @@ -56,6 +54,7 @@ module.exports = class quoteotd extends commando.Command { } } if (result.length > 0) { + ranLog(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]\``); diff --git a/cmds/utility/say.js b/cmds/utility/say.js index 992a876..a924915 100644 --- a/cmds/utility/say.js +++ b/cmds/utility/say.js @@ -13,7 +13,7 @@ module.exports = class say extends commando.Command { description: "Say." }); } - run(msg, args) { + async run(msg, args) { let noArgs = '​'; if (!args) { args = noArgs; @@ -23,10 +23,11 @@ module.exports = class say extends commando.Command { if (msg.member?.hasPermission('MENTION_EVERYONE')) { sendThis.disableMentions = "none"; } - const sent = trySend(this.client, msg, sendThis); + const sent = await trySend(this.client, msg, sendThis); if (args !== noArgs && msg.channel.guild && msg.member.hasPermission("MANAGE_MESSAGES")) { tryDelete(msg); } + ranLog(this.client, msg, sent.content); return sent; } }; \ No newline at end of file diff --git a/cmds/utility/send.js b/cmds/utility/send.js index f0a3867..40baff1 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -57,6 +57,7 @@ module.exports = class send extends commando.Command { if (send) { tryReact(msg, 'yeLife:796401669188354090'); } + ranLog(this.client, msg, send.content); return send; } catch (e) { return errLog(e, msg, this.client); diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index 63e2e02..2149c35 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -29,6 +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()}\``); + ranLog(this.client, msg, result.content); return result; }); } catch (e) { diff --git a/cmds/utility/uinfo.js b/cmds/utility/uinfo.js index 8717593..984fde0 100644 --- a/cmds/utility/uinfo.js +++ b/cmds/utility/uinfo.js @@ -39,7 +39,7 @@ module.exports = class uinfo extends commando.Command { result += 'Display color:```js\n'+member.displayColor+'```'; } } - return trySend(this.client, msg, result, {split:{maxLength:2000,char: ",",append:',```',prepend:'```js\n'}}); + return trySend(this.client, msg, {content: 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 e91f707..b1da318 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -1,15 +1,17 @@ 'use strict'; const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js'); -const { defaultErrorLogChannel } = require("../config.json"); +const { defaultErrorLogChannel, ranLogger } = require("../config.json"); const { database } = require("../database/mongo"); const { timestampAt } = require('./debug'); const getColor = require('./getColor'); +const { randomColors } = require("../config.json"); +const { CommandoMessage, CommandoClient } = require('@iceprod/discord.js-commando'); /** * Log an error. If second argument, third argument is required * @param {Error} theError - Catched error (error) - * @param {Message} msg - Message object (msg) + * @param {CommandoMessage} msg - Message object (msg) * @param {Client} client - This client (this.client) * @param {Boolean} sendTheError - Add error content to notify message (true | false) * @param {String} errorMessage - Error message ("You don't have enough permission to use that command!") @@ -18,8 +20,7 @@ const getColor = require('./getColor'); async function errLog(theError, msg, client, sendTheError, errorMessage, notify) { let errLogPath, [logThis, inLogChannel, sendErr] = ['', '', '']; if (msg) { - const comErr = msg.content.trim().split(/ +/)[0]; - logThis = `\`${comErr}\` (${msg.id}) ${msg.url} in ${msg.guild ? `**${msg.channel.name}** (${msg.channel.id}) of **${msg.guild.name}** (${msg.guild.id})` : `**DM**`} ran by **${msg.author.tag}** (${msg.author.id}) \n\n`; + logThis = `\`${msg.command.name}\` (${msg.id}) ${msg.url} in ${msg.guild ? `**${msg.channel.name}** (${msg.channel.id}) of **${msg.guild.name}** (${msg.guild.id})` : `**DM**`} ran by **${msg.author.tag}** (${msg.author.id}) \n\n`; msg.guild ? errLogPath = `../Guilds/${msg.guild.id}/Log/` : errLogPath = '../Log/'; if (errorMessage) { if (errorMessage.length > 0) { @@ -96,17 +97,22 @@ function execCB(error, stdout, stderr) { console.log('stdout:\n'+stdout); console.log('stderr:\n'+stderr); } - -async function ranLog(msg, cmd, addition) { return /* - let errLogPath; - if (msg.guild) { - errLogPath = `../Guilds/${msg.guild.id}/Log/`; - } else { - errLogPath = '../Log/'; - } - let add = '\n'+addition; - const b = new Date().toUTCString(); - return //console.log(inLog); */ +/** + * Command usage logger + * @param {CommandoClient} client + * @param {CommandoMessage} msg + * @param {String} addition + */ +async function ranLog(client, msg, addition) { + const channel = client.channels.cache.get(ranLogger); + const embed = await defaultImageEmbed(msg, null, msg.command.name.toLocaleUpperCase() + ` (${msg.id})`); + embed.setAuthor(msg.author.tag + ` (${msg.author.id})`, msg.author.displayAvatarURL({"size": 4096, "dynamic": true})) + .setURL(msg.url) + .setDescription(addition) + .setFooter(timestampAt(), msg.guild?.iconURL({"size": 4096, "dynamic": true})) + .addField("Guild", `**${msg.guild?.name}** (${msg.guild?.id})`, true) + .addField("Channel", `**${msg.channel?.name}** (${msg.channel.id})`, true); + trySend(client, channel, {embed: embed}); } /** @@ -247,32 +253,23 @@ function sentAdCheck(content) { /** * Make default image embed - * @param {Client} client * @param {Message} msg - * @param {URL} image + * @param {String} image * @param {GuildMember | User} author * @param {String} title - * @param {String} footerText + * @param {String} footerQuote * @returns {Promise} */ -async function defaultImageEmbed(client, msg, author, image, title, footerText) { - const { randomColors } = require("../config.json"); - let footerQuote = footerText; +async function defaultImageEmbed(msg, image, title, footerQuote) { if (!footerQuote) { - const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}); + const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}).catch(() => {}); footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote || ""; } - let emb = new MessageEmbed(); - try { - emb - .setTitle(title) - .setImage(image) - .setColor(msg.guild ? getColor(author?.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) - .setFooter(footerQuote); - } catch (e) { - return errLog(e, msg, client); - } - return emb; + return new MessageEmbed() + .setTitle(title) + .setImage(image) + .setColor(msg.guild ? getColor(msg.member.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) + .setFooter(footerQuote); } /**