From bcfdb975d742fdd873e029fa5dabc21b4da96f7f Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sat, 15 May 2021 18:25:30 +0000 Subject: [PATCH 01/10] little progress on mute.js --- .gitignore | 1 + cmds/experiment/dropexp.js | 22 ++++ cmds/experiment/mydatabase.js | 16 ++- cmds/experiment/regive.js | 32 +++++ cmds/experiment/replace.js | 29 +++++ cmds/experiment/resetdatabase.js | 6 +- cmds/experiment/resetinfractions.js | 28 ++++ cmds/experiment/screenshot.js | 32 +++++ cmds/image/neko.js | 2 +- cmds/moderation/mute.js | 195 +++++++++++++++++++++++----- resources/functions.js | 18 +-- resources/getColor.js | 3 + resources/shaChat.js | 2 +- 13 files changed, 331 insertions(+), 55 deletions(-) create mode 100644 cmds/experiment/dropexp.js create mode 100644 cmds/experiment/regive.js create mode 100644 cmds/experiment/replace.js create mode 100644 cmds/experiment/resetinfractions.js create mode 100644 cmds/experiment/screenshot.js diff --git a/.gitignore b/.gitignore index 7182f91..d7885fb 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ build/Release # Dependency directories node_modules/ jspm_packages/ +exp/ # Snowpack dependency directory (https://snowpack.dev/) web_modules/ diff --git a/cmds/experiment/dropexp.js b/cmds/experiment/dropexp.js new file mode 100644 index 0000000..2e7adb9 --- /dev/null +++ b/cmds/experiment/dropexp.js @@ -0,0 +1,22 @@ +'use strict'; + +const { trySend } = require("../../resources/functions"); + +const commando = require("@iceprod/discord.js-commando"), +{ database } = require("../../database/mongo"), +col = database.collection("Experiment"); + +module.exports = class dropexp extends commando.Command { + constructor(client) { + super(client, { + name: "dropexp", + memberName: "dropexp", + group: "experiment", + description: "description", + ownerOnly:true + }); + } + run(msg, arg) { + col.drop().then(trySend(this.client, msg, "cleared")).catch(e => trySend(this.client, msg, `\`\`\`js\n${e.stack}\`\`\``)); + } +}; \ No newline at end of file diff --git a/cmds/experiment/mydatabase.js b/cmds/experiment/mydatabase.js index 9874bb7..dbf55bf 100644 --- a/cmds/experiment/mydatabase.js +++ b/cmds/experiment/mydatabase.js @@ -3,6 +3,7 @@ const commando = require("@iceprod/discord.js-commando"); const { errLog, trySend, ranLog } = require("../../resources/functions"); const { database } = require("../../database/mongo"); +const exp = database.collection("Experiment"); module.exports = class mydatabase extends commando.Command { constructor(client) { @@ -10,19 +11,24 @@ module.exports = class mydatabase extends commando.Command { name: "mydatabase", memberName: "mydatabase", group: "experiment", - description: "Show all document collection." + description: "Show all document collection.", + ownerOnly:true }); } - run(msg) { + async run(msg) { + if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD")) { + return trySend(this.client, msg, "No"); + } const data = msg.guild ? "Guild" : "User"; - const doc = msg.guild?.id ?? msg.author.id; + const doc = msg.guild?.id ?? msg.author.id, + dbExp = await exp.find({}).toArray(); database.collection(data).find({document: doc}).toArray(async (e, fetched) => { if (e) { return errLog(e, msg, this.client); } let mes = `Fetched documents for ${msg.guild ? `server **${msg.guild.name}**` : `**${msg.author.tag}**`}`; - mes = `${mes}\`\`\`js\n${JSON.stringify(fetched, null, 2)}\`\`\``; - trySend(this.client, msg, mes); + mes = `${mes}\`\`\`js\n${JSON.stringify(fetched, null, 2)}\`\`\`` + `\`\`\`js\n${JSON.stringify(dbExp, null, 2)}\`\`\``; + trySend(this.client, msg, {content:mes,split:{maxLength:2000,append:",```",prepend:"```js\n",char:","}}); return ranLog(msg, "mydatabase", fetched); }); } diff --git a/cmds/experiment/regive.js b/cmds/experiment/regive.js new file mode 100644 index 0000000..9ca6216 --- /dev/null +++ b/cmds/experiment/regive.js @@ -0,0 +1,32 @@ +'use strict'; + +const { trySend, cleanMentionID } = require("../../resources/functions"); + +const commando = require("@iceprod/discord.js-commando"), +{ database } = require("../../database/mongo"), +col = database.collection("Experiment"); + +module.exports = class regive extends commando.Command { + constructor(client) { + super(client, { + name: "regive", + memberName: "regive", + group: "experiment", + description: "description" + }); + } + /** + * + * @param {commando.CommandoMessage} msg + * @param {*} arg + */ + async run(msg, arg ) { + const args = arg.split(" "), + member = msg.guild.member(cleanMentionID(args[0])), + doc = await col.findOne({"rolesScreenshot.name":member.id}).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")), + test = doc.rolesScreenshot.data; + await member.roles.add(test.map(r => r)).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")); + await member.roles.remove("772114626720432128").catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")) + trySend(this.client, msg, "Success!"+"```js\n"+JSON.stringify(test, null, 2)+"```"); + } +}; \ No newline at end of file diff --git a/cmds/experiment/replace.js b/cmds/experiment/replace.js new file mode 100644 index 0000000..f59d0a5 --- /dev/null +++ b/cmds/experiment/replace.js @@ -0,0 +1,29 @@ +'use strict'; + +const commando = require("@iceprod/discord.js-commando"); +const { cleanMentionID, trySend } = require("../../resources/functions"); + +module.exports = class replace extends commando.Command { + constructor(client) { + super(client, { + name: "replace", + memberName: "replace", + group: "experiment", + description: "replace test" + }); + } + /** + * + * @param {commando.CommandoMessage} msg + * @param {*} arg + */ + async run(msg, arg) { + const args = arg.split(" "), + targetID = cleanMentionID(args[0]), + targetUser = msg.guild.member(targetID); + await targetUser.roles.remove(targetUser.roles.cache.array()).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")); + await targetUser.roles.add("772114626720432128").catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")); + //trySend(this.client, msg, "```js\n"+JSON.stringify(mes, null, 2)+"```"); + trySend(this.client, msg, "Replaced!"); + } +}; \ No newline at end of file diff --git a/cmds/experiment/resetdatabase.js b/cmds/experiment/resetdatabase.js index d3df9fa..9954a17 100644 --- a/cmds/experiment/resetdatabase.js +++ b/cmds/experiment/resetdatabase.js @@ -10,10 +10,14 @@ module.exports = class resetdatabase extends commando.Command { name: "resetdatabase", memberName: "resetdatabase", group: "experiment", - description: "Reset your server/private database." + description: "Reset your server/private database.", + ownerOnly:true }); } async run(msg) { + if (!msg.guild?.member(msg.author).hasPermission("MANAGE_GUILD")) { + return trySend(this.client, msg, "No"); + } const doc = msg.guild?.id ?? msg.author.id; const col = database.collection(msg.guild ? "Guild" : "User"); trySend(this.client, msg, "Are you sure? You will lose every saved settings. This process can't be undone. Type `yes` in 30 seconds to confirm."); diff --git a/cmds/experiment/resetinfractions.js b/cmds/experiment/resetinfractions.js new file mode 100644 index 0000000..dfb0aed --- /dev/null +++ b/cmds/experiment/resetinfractions.js @@ -0,0 +1,28 @@ +'use strict'; + +const commando = require("@iceprod/discord.js-commando"), +{ database } = require("../../database/mongo"); +const { trySend } = require("../../resources/functions"), +col = database.collection("Guild"); + +module.exports = class resetinfractions extends commando.Command { + constructor(client) { + super(client, { + name: "resetinfractions", + memberName: "resetinfractions", + group: "experiment", + description: "description", + guildOnly:true, + ownerOnly:true + }); + } + run(msg) { + col.updateOne({document:msg.guild.id}, {$set:{"moderation.infractions":[]}}, {upsert:true}, (e, r) => { + if (e) { + return trySend(this.client, msg, "```js\n"+e.stack+"```"); + } + col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute": {}}}); + return trySend(this.client, msg, "Wiped!"); + }); + } +}; \ No newline at end of file diff --git a/cmds/experiment/screenshot.js b/cmds/experiment/screenshot.js new file mode 100644 index 0000000..73cc890 --- /dev/null +++ b/cmds/experiment/screenshot.js @@ -0,0 +1,32 @@ +'use strict'; + +const { cleanMentionID, trySend } = require("../../resources/functions"); + +const commando = require("@iceprod/discord.js-commando"), +{ database } = require("../../database/mongo"), +dbExp = database.collection("Experiment"); + +module.exports = class screenshot extends commando.Command { + constructor(client) { + super(client, { + name: "screenshot", + memberName: "screenshot", + group: "experiment", + description: "description" + }); + } + /** + * + * @param {commando.CommandoMessage} msg + * @param {*} arg + */ + async run(msg, arg) { + const args = arg.split(" "), + targetID = cleanMentionID(args[0]), + targetUser = msg.guild.member(targetID), + test = targetUser.roles.cache.map(r => r.id); + //trySend(this.client,msg,{content:`\`\`\`js\n${test}\`\`\``,split:true}) + await dbExp.insertOne({ rolesScreenshot: { name: targetUser.id, data: test }}).catch(e => trySend(this.client, msg, "```js\n" + e.stack + "```")); + trySend(this.client, msg, "Sceenshoted!") + } +}; \ No newline at end of file diff --git a/cmds/image/neko.js b/cmds/image/neko.js index 578cb76..44d8c05 100644 --- a/cmds/image/neko.js +++ b/cmds/image/neko.js @@ -16,7 +16,7 @@ module.exports = class neko extends commando.Command { const aut = msg.guild ? msg.guild.member(msg.author) : msg.author; const title = `${msg.guild ? aut.displayName : aut.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, image, aut, title); + const emb = await defaultImageEmbed(this.client, msg, aut, image, title); trySend(this.client, msg, emb); return ranLog(msg, "neko"); } diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index 6418c55..67233bb 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -1,10 +1,10 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { trySend, findMemberRegEx, cleanMentionID } = require("../../resources/functions"); +const { trySend, findMemberRegEx, cleanMentionID, findChannelRegEx, findRoleRegEx, defaultImageEmbed } = require("../../resources/functions"); const { database } = require("../../database/mongo"); const col = database.collection("Guild"); -const dbExp = database.collection("Experiment"); +const schedule = database.collection("Schedule"); const { scheduler } = require("../../resources/scheduler"); module.exports = class mute extends commando.Command { @@ -25,9 +25,11 @@ module.exports = class mute extends commando.Command { */ async run(msg, arg) { const doc = await col.findOne({document: msg.guild.id}), - moderationDoc = doc?.["moderation"], - infractionDoc = moderationDoc?.infractions, - args = arg.trim().split(/(? 0 && argument !== "--") { + if (!settingRole && !settingLogChannel && argument.length > 0 && argument !== "--") { reason = argument.trim(); + } else { + if (settingLogChannel && !settingLogChannelHasSet && argument.length > 0 && argument !== "--" && setArg !== "log") { + settingLogChannelHasSet = true; + const key = cleanMentionID(argument); + let logChannel; + if (/^\d{17,19}$/.test(key)) { + logChannel = msg.guild.channels.cache.get(argument); + } else { + const found = findChannelRegEx(msg, key); + logChannel = found[0]; + } + if (logChannel) { + theSettingUp.logChannel = logChannel.id; + resultMsg += `Log channel set to: **${logChannel.name}**\n`; + } else { + resultMsg += `No channel found for: **${argument}**\n`; + } + } + if (settingRole && !settingRoleHasSet && argument.length > 0 && argument !== "--" && setArg !== "role") { + settingRoleHasSet = true; + const key = cleanMentionID(argument); + let role; + if (/^\d{17,19}$/.test(key)) { + role = msg.guild.roles.cache.get(argument); + } else { + const found = findRoleRegEx(msg, key); + role = found[0].id; + } + if (role) { + theSettingUp.role = role; + resultMsg += `Mute role set to: **${role.name}**\n`; + } else { + resultMsg += `No role found for: **${argument}**\n`; + } + } } } } + const roleConfCheck = msg.guild.roles.cache.get(muteSettingsDoc?.role); + if (!roleConfCheck && !settingUp) { + return trySend(this.clientPermissions, msg, `No mute role configured! Run \`${this.client.commandPrefix}mute --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()) { - untilDate = "Indefinite"; - } else { + 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), elapsed = [ @@ -110,19 +176,49 @@ module.exports = class mute extends commando.Command { "minute", "second" ]; + for (let index = 0; index < elapsed.length; index++) { if (elapsed[index] > 0) { - timeForMessage.push(`${elapsed[index]} ${elapsedName[index]}`); + let mes = `${elapsed[index]} ${elapsedName[index]}`; + if (elapsed[index] > 1) { + mes += "s"; + } else {} + timeForMessage.push(mes); } else {} } - for (let index = 0; index < timeForMessage.length; index++) { - if (parseInt(timeForMessage[index].split(" ")[0], 10) > 1) { - timeForMessage[index] += "s"; - } - } if (timeForMessage.length > 1) { timeForMessage[timeForMessage.length - 2] += " and"; } + if (settingDuration && !settingDurationHasSet && timeForMessage.length > 0) { + settingDurationHasSet = true; + theSettingUp.defaultDuration.date = elapsedTime, + theSettingUp.defaultDuration.string = timeForMessage.join(" "); + resultMsg += `Default Duration set to: **${theSettingUp.defaultDuration.string}**\n`; + } + } + if (settingUp) { + if(settingRoleHasSet) { + await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.role":theSettingUp.role}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")}); + } + if (durationHasSet) { + await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.defaultDuration":theSettingUp.defaultDuration}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")}); + } + if (settingLogChannelHasSet) { + await col.updateOne({document:msg.guild.id}, {$set:{"moderation.settings.mute.logChannel":theSettingUp.logChannel}}, {upsert:true}).catch(e => {return trySend(this.client, msg, "```js\n"+e.stack+"```")}); + } + const doc = await col.findOne({document: msg.guild.id}), + modDoc = doc?.["moderation"], + muteSettingsDoc = modDoc?.["settings"]?.mute, + defaultDurationDoc = muteSettingsDoc?.defaultDuration, + logChannelDoc = muteSettingsDoc?.logChannel, + roleDoc = muteSettingsDoc?.role; + let settings = await defaultImageEmbed(this.client, msg, msg.member); + settings + .setTitle("Mute Configuration") + .addField("Role", roleDoc ? "<@&"+roleDoc+">" : "Not set") + .addField("Duration", defaultDurationDoc?.string ?? "Not set") + .addField("Log", logChannelDoc ? "<#"+logChannelDoc+">" : "Not set"); + return trySend(this.client, msg, settings); } for (const usermention of mentions) { if (usermention.length > 0) { @@ -151,35 +247,62 @@ module.exports = class mute extends commando.Command { } else { resultMsg += `Can't find user: **${usermention.trim()}**\n`; } + } else { + if (!settingUp) { + return trySend(this.client, msg, "Who are you wanna mute? Provide as first argument `<[RegExp | user_[mention | ID]]>`"); + } else { + + } } } let infractionToDoc; if (targetUser.length > 0) { - const infractionCase = infractionDoc?.map(r => r.infraction)?.length; + let targetMember = [], + notInServer = []; + for (const user of targetUser) { + const member = msg.guild.member(user); + if (member) { + const pushIt = { + name:member.user.tag, + id:member.id, + roles:member.roles.cache.map(r => r.id) + } + targetMember.push(pushIt); + } else { + const pushIt = { + name: user.tag, + id:user.id + } + notInServer.push(pushIt); + } + } + const infractionCase = infractionsDoc?.map(r => r.infraction)?.length; infractionToDoc = { infraction: infractionCase ? infractionCase + 1 : 1, by: targetUser, moderator: `**${msg.author.tag}** <@${msg.author.id}> (${msg.author.id})`, - punishment: "**Mute**", + punishment: "mute", at: invokedAt, for: timeForMessage, until: untilDate, reason: reason, - scene: msg.url + scene: msg.url, + members: targetMember, + users: notInServer } + await col.updateOne({document: msg.guild.id}, { $push:{"moderation.infractions": infractionToDoc}}, {upsert:true}); const newUnmuteSchedule = { - name: "unmute schedule " + targetUser?.id, + name: "unmute", path: "./scheduler/unmute.js", worker: { - argv: { - - } - } + argv: [msg, infractionToDoc.infraction] + }, + date: untilDate } } - resultMsg += `Result:\`\`\`js\nUsers: ${targetUser.map(r => r?.tag).join(", ")}\nReason: ${reason}\nAt: ${invokedAt.toUTCString()}\nFor: ${timeForMessage.join(" ")}\nUntil: ${typeof untilDate !== "string" ? untilDate.toUTCString() : untilDate}\`\`\`\n`; - trySend(this.client, msg, "```js\n" + JSON.stringify(infractionToDoc, null, 2) + "```"); - return trySend(this.client, msg, resultMsg); + resultMsg += `Result:\`\`\`js\nUsers: ${targetUser.map(r => r?.tag).join(", ")}\nReason: ${reason}\nAt: ${invokedAt.toUTCString()}\nFor: ${timeForMessage.join(" ")}\nUntil: ${typeof untilDate !== "string" ? untilDate.toUTCString() : untilDate}\`\`\``; + trySend(this.client, msg, {content:resultMsg+"```js\n" + JSON.stringify(infractionToDoc, null, 2) + "```",split:{maxLength:2000,append:",```",prepend:"```js\n",char:","}}); + return } }; diff --git a/resources/functions.js b/resources/functions.js index 7d4135e..e254b1f 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -3,6 +3,7 @@ const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions } = require('discord.js'); const { defaultErrorLogChannel } = require("../config.json"); const { database } = require("../database/mongo"); +const getColor = require('./getColor'); /** * Log an error. If second argument, third argument is required @@ -139,7 +140,6 @@ async function ranLog(msg, cmd, addition) { * @returns {String} */ function multipleMembersFound(client, msg, arr, key, max = 4, withID) { - arr = arr.slice(1); if (arr.length > 0) { try { let multipleFound = []; @@ -216,7 +216,8 @@ async function trySend(client, msg, content) { msgOf = client.channels.cache.get(msg); } const sentMes = await msgOf.send(content) - .catch(() => { + .catch((e) => { + console.error(e); if (msg?.channel) { noPerm(msg); } @@ -270,23 +271,20 @@ function sentAdCheck(sent) { * @param {String} footerText * @returns {Promise} */ -async function defaultImageEmbed(client, msg, image, author, title, footerText) { +async function defaultImageEmbed(client, msg, author, image, title, footerText) { const { randomColors } = require("../config.json"); let footerQuote = footerText; if (!footerQuote) { - const doc = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}); - footerQuote = doc?.["settings"]?.defaultEmbed?.footerQuote || ""; + const r = await database.collection(msg.guild ? "Guild" : "User").findOne({document: msg.guild?.id ?? msg.author.id}); + footerQuote = r?.["settings"]?.defaultEmbed?.footerQuote || ""; } let emb = new MessageEmbed(); try { emb .setTitle(title) .setImage(image) - .setColor(msg.guild ? author?.displayColor : randomColors[Math.floor(Math.random() * randomColors.length)]) + .setColor(msg.guild ? getColor(author?.displayColor) : randomColors[Math.floor(Math.random() * randomColors.length)]) .setFooter(footerQuote); - if (author?.displayColor === 16777215) { - emb.setColor(16777214); - } } catch (e) { return errLog(e, msg, client, false, "", false); } @@ -363,7 +361,6 @@ function findRoleRegEx(msg, name) { * @returns {String} */ function multipleChannelsFound(client, msg, arr, key, max = 4, withID) { - arr = arr.slice(1); if (arr.length > 0) { try { let multipleFound = []; @@ -404,7 +401,6 @@ function multipleChannelsFound(client, msg, arr, key, max = 4, withID) { * @returns {String} */ function multipleRolesFound(client, msg, arr, key, max = 4, withID) { - arr = arr.slice(1); if (arr.length > 0) { try { let multipleFound = []; diff --git a/resources/getColor.js b/resources/getColor.js index 8714a79..2518245 100644 --- a/resources/getColor.js +++ b/resources/getColor.js @@ -6,6 +6,9 @@ * @returns {String | Number} Color hex | Color number */ module.exports = function getColor(name) { + if (!name) { + return + } if (typeof name === "string") { name = name.toLowerCase(); } diff --git a/resources/shaChat.js b/resources/shaChat.js index f758997..daa61fd 100644 --- a/resources/shaChat.js +++ b/resources/shaChat.js @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer'); -const { trySend, errLog, ranLog, noPerm } = require('./functions'); +const { trySend, ranLog, noPerm } = require('./functions'); const Commando = require("@iceprod/discord.js-commando"); require("discord.js"); From 2dbcccc337ef58af901ae7234aa211b3b0397ba9 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 08:43:31 +0000 Subject: [PATCH 02/10] added "none" argument --- .gitignore | 3 +++ cmds/moderation/mute.js | 19 +++++++++++-------- cmds/utility/avatar.js | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d7885fb..99e6043 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ web_modules/ # TypeScript cache *.tsbuildinfo +*.sqlite3 # Optional npm cache directory .npm @@ -118,3 +119,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* +settings.sqlite3 +settings.sqlite3 diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index 67233bb..a8bd17b 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -115,9 +115,11 @@ module.exports = class mute extends commando.Command { const found = findChannelRegEx(msg, key); logChannel = found[0]; } - if (logChannel) { - theSettingUp.logChannel = logChannel.id; - resultMsg += `Log channel set to: **${logChannel.name}**\n`; + if (/^none$/.test(key)) { + logChannel = undefined; + } + if (logChannel || /^none$/.test(key)) { + theSettingUp.logChannel = logChannel?.id; } else { resultMsg += `No channel found for: **${argument}**\n`; } @@ -130,11 +132,13 @@ module.exports = class mute extends commando.Command { role = msg.guild.roles.cache.get(argument); } else { const found = findRoleRegEx(msg, key); - role = found[0].id; + role = found[0]?.id; } - if (role) { + if (/^none$/.test(key)) { + role = undefined; + } + if (role || /^none$/.test(key)) { theSettingUp.role = role; - resultMsg += `Mute role set to: **${role.name}**\n`; } else { resultMsg += `No role found for: **${argument}**\n`; } @@ -193,7 +197,6 @@ module.exports = class mute extends commando.Command { settingDurationHasSet = true; theSettingUp.defaultDuration.date = elapsedTime, theSettingUp.defaultDuration.string = timeForMessage.join(" "); - resultMsg += `Default Duration set to: **${theSettingUp.defaultDuration.string}**\n`; } } if (settingUp) { @@ -218,7 +221,7 @@ module.exports = class mute extends commando.Command { .addField("Role", roleDoc ? "<@&"+roleDoc+">" : "Not set") .addField("Duration", defaultDurationDoc?.string ?? "Not set") .addField("Log", logChannelDoc ? "<#"+logChannelDoc+">" : "Not set"); - return trySend(this.client, msg, settings); + return trySend(this.client, msg, {content:resultMsg, embed:settings}); } for (const usermention of mentions) { if (usermention.length > 0) { diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index 6fe9e25..a04358e 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -43,7 +43,7 @@ module.exports = class avatar extends commando.Command { if (ops.toLowerCase().startsWith("show")) { const val = ops.trim().split(/ +/); const theVal = val[1]?.match(/\d*/); - if (theVal[0]) { + if (theVal?.[0]) { show = parseInt(theVal[0].trim(), 10); } } From a46aa25d2fa1e9515de2402ca63bb71d6a8b4e9c Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 08:45:43 +0000 Subject: [PATCH 03/10] ignore sqlite3 --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 99e6043..d1d8501 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ config.json package-lock.json +*.sqlite3 # Logs logs @@ -50,7 +51,6 @@ web_modules/ # TypeScript cache *.tsbuildinfo -*.sqlite3 # Optional npm cache directory .npm From c81898912727b922797a966f1d9d20bf4af3fe80 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 09:25:34 +0000 Subject: [PATCH 04/10] update owners --- Main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main.js b/Main.js index 08f73fd..7bee20c 100644 --- a/Main.js +++ b/Main.js @@ -2,7 +2,7 @@ const Commando = require('@iceprod/discord.js-commando'); const client = new Commando.Client({ - owner: '750335181285490760', + owner: ['820696421912412191', '750335181285490760'], partials: ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION", "USER"] }); const sqlite = require('sqlite'); From 0b83136fbe80773be70c0bb56bdd26cfc86e15fc Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 09:26:00 +0000 Subject: [PATCH 05/10] update permissions --- cmds/utility/newquoteotd.js | 3 ++- cmds/utility/quoteotd.js | 3 ++- cmds/utility/say.js | 8 ++++++-- cmds/utility/send.js | 9 +++++++-- cmds/utility/servav.js | 13 +++++++++---- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index a3d86fc..48cfabf 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -13,7 +13,8 @@ module.exports = class newquoteotd extends commando.Command { memberName: "newquoteotd", group: "utility", description: "The Life exclusive command for Quote of the day.", - guildOnly: true + guildOnly: true, + userPermissions:"ADMINISTRATOR" }); } async run(msg, arg) { diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index ea355c0..7b588b9 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -15,7 +15,8 @@ module.exports = class quoteotd extends commando.Command { group: "utility", description: "Set Quote of the day channel and settings.", details:"```\n--channel\n--text\n--icon```", - guildOnly: true + guildOnly: true, + userPermissions:"ADMINISTRATOR" }); } async run(msg, arg) { diff --git a/cmds/utility/say.js b/cmds/utility/say.js index 119cde9..6ea45da 100644 --- a/cmds/utility/say.js +++ b/cmds/utility/say.js @@ -17,8 +17,12 @@ module.exports = class say extends commando.Command { if (!args) { args = noArgs; } - trySend(this.client, msg, args); - if (args !== noArgs && msg.channel.guild) { + const sendThis = {content:args, disableMentions:"all"}; + if (msg.member?.hasPermission("ADMINISTRATOR")) { + sendThis.disableMentions = "none"; + } + trySend(this.client, msg, sendThis); + if (args !== noArgs && msg.channel.guild && msg.member.hasPermission("MANAGE_MESSAGES")) { tryDelete(msg); } return ranLog(msg,'say',`Content: ${args}`); diff --git a/cmds/utility/send.js b/cmds/utility/send.js index 54df3d4..7779cde 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -8,7 +8,8 @@ module.exports = class send extends commando.Command { name: "send", memberName: "send", group: "utility", - description: "Send message to designated channel." + description: "Send message to designated channel.", + userPermissions:"MANAGE_MESSAGES" }); } async run(msg, args ) { @@ -30,7 +31,11 @@ module.exports = class send extends commando.Command { if (sendTheMes.length === 0) { return trySend(this.client, at, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`); } - const send = await channel.send(sendTheMes); + const sendThis = {content:sendTheMes, disableMentions:"all"}; + if (msg.member?.hasPermission("ADMINISTRATOR")) { + sendThis.disableMentions = "none"; + } + const send = await trySend(this.client, msg, sendThis); sentAdCheck(send); const filter = () => true; const collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); diff --git a/cmds/utility/servav.js b/cmds/utility/servav.js index 88d9059..e432121 100644 --- a/cmds/utility/servav.js +++ b/cmds/utility/servav.js @@ -9,13 +9,18 @@ const getColor = require("../../resources/getColor"); module.exports = class servav extends commando.Command { constructor(client) { super(client, { - name: "servav", - memberName: "servav", - aliases: ["serveravatar", "servavatar", "serverav"], + name: "serv-av", + memberName: "serv-av", + aliases: ["server-avatar", "serv-avatar", "server-av"], group: "utility", description: "Show server avatar." }); } + /** + * + * @param {commando.CommandoMessage} msg + * @param {*} arg + */ run(msg, arg) { const server_ID = arg.split(/ +/)[0]; const doc = msg.guild?.id ?? msg.author.id; @@ -26,7 +31,7 @@ module.exports = class servav extends commando.Command { } const footerQuote = res?.["settings"]?.defaultEmbed?.footerQuote; let icon, target; - if (server_ID) { + if (server_ID && this.client.owners.includes(msg.author.id)) { if (!/\D/.test(server_ID)) { target = this.client.guilds.cache.get(server_ID); } else { From 8388ab41d0a24c0f00728f2aa830f07609ad1e5c Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 09:31:07 +0000 Subject: [PATCH 06/10] uhh "forgot" array... --- cmds/utility/newquoteotd.js | 2 +- cmds/utility/quoteotd.js | 2 +- cmds/utility/send.js | 2 +- cmds/utility/setfootq.js | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmds/utility/newquoteotd.js b/cmds/utility/newquoteotd.js index 48cfabf..62e0dca 100644 --- a/cmds/utility/newquoteotd.js +++ b/cmds/utility/newquoteotd.js @@ -14,7 +14,7 @@ module.exports = class newquoteotd extends commando.Command { group: "utility", description: "The Life exclusive command for Quote of the day.", guildOnly: true, - userPermissions:"ADMINISTRATOR" + userPermissions:["ADMINISTRATOR"] }); } async run(msg, arg) { diff --git a/cmds/utility/quoteotd.js b/cmds/utility/quoteotd.js index 7b588b9..d693518 100644 --- a/cmds/utility/quoteotd.js +++ b/cmds/utility/quoteotd.js @@ -16,7 +16,7 @@ module.exports = class quoteotd extends commando.Command { description: "Set Quote of the day channel and settings.", details:"```\n--channel\n--text\n--icon```", guildOnly: true, - userPermissions:"ADMINISTRATOR" + userPermissions:["ADMINISTRATOR"] }); } async run(msg, arg) { diff --git a/cmds/utility/send.js b/cmds/utility/send.js index 7779cde..e35c6c9 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -9,7 +9,7 @@ module.exports = class send extends commando.Command { memberName: "send", group: "utility", description: "Send message to designated channel.", - userPermissions:"MANAGE_MESSAGES" + userPermissions:["MANAGE_MESSAGES"] }); } async run(msg, args ) { diff --git a/cmds/utility/setfootq.js b/cmds/utility/setfootq.js index ea4161b..f9ce8f6 100644 --- a/cmds/utility/setfootq.js +++ b/cmds/utility/setfootq.js @@ -11,7 +11,8 @@ module.exports = class setfootq extends commando.Command { aliases:["setfooterquote"], memberName: "setfootq", group: "utility", - description: "Set server embed footer text." + description: "Set server embed footer text.", + userPermissions: ["ADMINISTRATOR"] }); } async run(msg, args) { From 0c36b96040e8f97d0819cdef87cb9a00f9e183eb Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 09:43:32 +0000 Subject: [PATCH 07/10] forgot channel --- cmds/utility/send.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/utility/send.js b/cmds/utility/send.js index e35c6c9..ace55bd 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -35,7 +35,7 @@ module.exports = class send extends commando.Command { if (msg.member?.hasPermission("ADMINISTRATOR")) { sendThis.disableMentions = "none"; } - const send = await trySend(this.client, msg, sendThis); + const send = await trySend(this.client, channel, sendThis); sentAdCheck(send); const filter = () => true; const collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); From 30082e91db3f1d44e3ecf12874737f037e31a59b Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 09:53:48 +0000 Subject: [PATCH 08/10] trySend update --- resources/functions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/functions.js b/resources/functions.js index e254b1f..4bc976a 100644 --- a/resources/functions.js +++ b/resources/functions.js @@ -1,6 +1,6 @@ 'use strict'; -const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions } = require('discord.js'); +const { MessageEmbed, Message, GuildMember, User, Client, GuildChannel, Role, MessageOptions, Channel } = require('discord.js'); const { defaultErrorLogChannel } = require("../config.json"); const { database } = require("../database/mongo"); const getColor = require('./getColor'); @@ -203,7 +203,7 @@ function noPerm(msg) { /** * Send message * @param {Client} client - (this.client) - * @param {Message | String} msg Message object | channel_ID + * @param {Message | String | Channel} msg Message object | channel_ID * @param {MessageOptions} content - ({content:content,optionblabla}) * @returns {Promise} Sent message object */ @@ -213,7 +213,11 @@ async function trySend(client, msg, content) { if (msg?.channel) { msgOf = msg.channel; } else { - msgOf = client.channels.cache.get(msg); + if (typeof msg === "string") { + msgOf = client.channels.cache.get(msg); + } else { + msgOf = msg; + } } const sentMes = await msgOf.send(content) .catch((e) => { From 629cdb86fd68937fbde26fbbf6a50e224e310060 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 10:18:34 +0000 Subject: [PATCH 09/10] small bug in DM --- cmds/utility/avatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/utility/avatar.js b/cmds/utility/avatar.js index a04358e..c1f44f2 100644 --- a/cmds/utility/avatar.js +++ b/cmds/utility/avatar.js @@ -55,7 +55,7 @@ module.exports = class avatar extends commando.Command { if (uID.length > 0) { let ree = []; if (/^\d{17,19}$/.test(uID)) { - const findmem = msg.guild.member(uID); + const findmem = msg.guild?.member(uID); if (findmem) { ree.push(findmem.user); } else { From 6171ad9e73e351bb6e1431f454cff56befa2fd5a Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 16 May 2021 12:15:36 +0000 Subject: [PATCH 10/10] removed settings.sqlite3 --- settings.sqlite3 | Bin 8192 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 settings.sqlite3 diff --git a/settings.sqlite3 b/settings.sqlite3 deleted file mode 100644 index 313b6038e1015eabeaff4c0eb312f543a4e0184b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCU|zu0aX` zL7u*jL6HjHu8}$jMIo*cA)27RITQZ{2L22DPq0}(DmEGdqaiRF0;3@?8UmvsFd71* zAut*OqaiRF0;3@?8UmvsF!(}12smx8U9D75l$w@Vp=700tfy2f)VlWG+0B!eG+>bf E0K05BzyJUM