diff --git a/.gitignore b/.gitignore index d1d8501..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/ @@ -119,5 +120,3 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* -settings.sqlite3 -settings.sqlite3 diff --git a/Main.js b/Main.js index a5678a6..381eec5 100644 --- a/Main.js +++ b/Main.js @@ -68,6 +68,10 @@ client.on("guildMemberAdd", newMember => { //console.log(`New member ${newMember.displayName} (${newMember.user.tag}) (${newMember.id}) joined ${newMember.guild.name} (${newMember.guild.id})! Now it has ${newMember.guild.memberCount} total members count.`); }); +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.login(configFile.token); \ No newline at end of file diff --git a/cmds/experiment/dropexp.js b/cmds/experiment/dropexp.js deleted file mode 100644 index 2e7adb9..0000000 --- a/cmds/experiment/dropexp.js +++ /dev/null @@ -1,22 +0,0 @@ -'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 deleted file mode 100644 index dbf55bf..0000000 --- a/cmds/experiment/mydatabase.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -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) { - super(client, { - name: "mydatabase", - memberName: "mydatabase", - group: "experiment", - description: "Show all document collection.", - ownerOnly:true - }); - } - 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, - 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)}\`\`\`` + `\`\`\`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); - }); - } -}; \ No newline at end of file diff --git a/cmds/experiment/regive.js b/cmds/experiment/regive.js deleted file mode 100644 index 9ca6216..0000000 --- a/cmds/experiment/regive.js +++ /dev/null @@ -1,32 +0,0 @@ -'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 deleted file mode 100644 index f59d0a5..0000000 --- a/cmds/experiment/replace.js +++ /dev/null @@ -1,29 +0,0 @@ -'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 deleted file mode 100644 index 9954a17..0000000 --- a/cmds/experiment/resetdatabase.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -const commando = require("@iceprod/discord.js-commando"); -const { ranLog, trySend, errLog } = require("../../resources/functions"); -const { database } = require("../../database/mongo"); - -module.exports = class resetdatabase extends commando.Command { - constructor(client) { - super(client, { - name: "resetdatabase", - memberName: "resetdatabase", - group: "experiment", - 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."); - const confirm = msg.channel.createMessageCollector(() => true, {time:30000}); - confirm.on("collect", h => { - if (h.author === msg.author) { - if (h.content.trim() === "yes") { - col.findOneAndDelete({document: doc}) - .then( - trySend(this.client, msg, "Wiped!")) - .catch(e => errLog(e, msg, this.client)); - } else { - trySend(this.client, msg, "Request aborted."); - } - confirm.stop(); - return ranLog(msg, "resetdatabase", h.content); - } - }); - } -}; \ No newline at end of file diff --git a/cmds/experiment/resetinfractions.js b/cmds/experiment/resetinfractions.js deleted file mode 100644 index dfb0aed..0000000 --- a/cmds/experiment/resetinfractions.js +++ /dev/null @@ -1,28 +0,0 @@ -'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 deleted file mode 100644 index 73cc890..0000000 --- a/cmds/experiment/screenshot.js +++ /dev/null @@ -1,32 +0,0 @@ -'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/moderation/mute.js b/cmds/moderation/mute.js index a8bd17b..0734a3c 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -115,10 +115,10 @@ module.exports = class mute extends commando.Command { const found = findChannelRegEx(msg, key); logChannel = found[0]; } - if (/^none$/.test(key)) { + if (/^none$/i.test(key)) { logChannel = undefined; } - if (logChannel || /^none$/.test(key)) { + if (logChannel || /^none$/i.test(key)) { theSettingUp.logChannel = logChannel?.id; } else { resultMsg += `No channel found for: **${argument}**\n`; @@ -134,10 +134,10 @@ module.exports = class mute extends commando.Command { const found = findRoleRegEx(msg, key); role = found[0]?.id; } - if (/^none$/.test(key)) { + if (/^none$/i.test(key)) { role = undefined; } - if (role || /^none$/.test(key)) { + if (role || /^none$/i.test(key)) { theSettingUp.role = role; } else { resultMsg += `No role found for: **${argument}**\n`; @@ -251,10 +251,8 @@ module.exports = class mute extends commando.Command { 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 { - + 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]]>`"); } } } diff --git a/cmds/utility/send.js b/cmds/utility/send.js index ace55bd..f96dc5a 100644 --- a/cmds/utility/send.js +++ b/cmds/utility/send.js @@ -1,6 +1,6 @@ 'use strict'; const commando = require("@iceprod/discord.js-commando"); -const { ranLog, errLog, trySend, sentAdCheck, tryReact } = require("../../resources/functions"); +const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions"); module.exports = class send extends commando.Command { constructor(client) { @@ -9,36 +9,37 @@ module.exports = class send extends commando.Command { memberName: "send", group: "utility", description: "Send message to designated channel.", - userPermissions:["MANAGE_MESSAGES"] + guildOnly:true }); } async run(msg, args ) { const comarg = args.trim().split(/ +/); - const bot = this.client; let at = comarg[0]; if (!comarg[0]) { return trySend(this.client, msg, 'Where?!?'); } - if (comarg[0].startsWith('<#') && comarg[0].endsWith('>')) { - at = comarg[0].slice(2, -1); - } - const channel = bot.channels.cache.get(at); - const sendTheMes = args.slice(comarg[0].length).trim(); + const search = cleanMentionID(comarg[0]), + channel = findChannelRegEx(msg, search)[0], + sendTheMes = args.slice(comarg[0].length).trim(); if (!channel) { - return trySend(this.client, msg, "Give me the right `channel_[mention, ID]` bruh"); + 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>"); + } } try { 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>`); + 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("ADMINISTRATOR")) { + if (msg.member?.hasPermission("MENTION_EVERYONE")) { sendThis.disableMentions = "none"; } const send = await trySend(this.client, channel, sendThis); sentAdCheck(send); - const filter = () => true; - const collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); + const filter = () => true, + collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); collector.on('collect', r => { try { msg.react(r.emoji); diff --git a/resources/structures.js b/resources/structures.js new file mode 100644 index 0000000..b9f1b9b --- /dev/null +++ b/resources/structures.js @@ -0,0 +1,70 @@ +'use strict'; + +const { Structures } = require("discord.js"); + +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 { + constructor(client, data) { + super(client, data); + this.settings = new Settings(client, "Guild", this.id); + } + 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 + } + } + } +}); + +Structures.extend("User", User => { + return class Settings extends User { + constructor(client, data) { + super(client, data); + this.settings = new Settings(client, User, this.id); + } + embed = { + footer: { + text: undefined, + icon: undefined + }, + timestamp: false + }; + } +}); \ No newline at end of file