diff --git a/cmds/moderation/mute.js b/cmds/moderation/mute.js index ccd13f2..4ffddbe 100644 --- a/cmds/moderation/mute.js +++ b/cmds/moderation/mute.js @@ -124,15 +124,15 @@ module.exports = class mute extends commando.Command { muted.push(EXEC.id); } catch (e) { if (/Missing Permissions|someone with higher position/.test(e.message)) cant.push(EXEC.id); - else if (/already muted/.test(e.message)) already.push(EXEC.id); else trySend(msg.client, msg, e.message); continue; + else if (/already muted/.test(e.message)) already.push(EXEC.id); else console.log(e); continue; } if (!EXEC.bot) { const emb = defaultEventLogEmbed(msg.guild); emb.setTitle("You have been muted") .setDescription("**Reason**\n" + reason) .addField("At", defaultDateFormat(duration.invoked), true) - .addField("For", duration.duration?.strings.join(" ") || "Indefinite", true) - .addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true); + .addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true) + .addField("For", duration.duration?.strings.join(" ") || "Indefinite", true); EXEC.createDM().then(r => trySend(msg.client, r, emb)); } } @@ -154,9 +154,6 @@ module.exports = class mute extends commando.Command { }; let emb = defaultImageEmbed(msg, null, "Infraction #" + infractionToDoc.infraction); - - if (cant.length > 0) emb.addField("Can't mute", "<@" + cant.join(">, <@") + ">\n\n**You can't mute someone with higher position than you <:nekokekLife:852865942530949160>**"); - if (already.length > 0) emb.addField("Already muted", "<@" + already.join(">, <@") + ">\n\nDuration updated for these users"); let mutedStr = "", mutedArr = []; if (muted.length > 0) for (const U of muted) { const tU = "<@" + U + ">\n"; @@ -166,8 +163,11 @@ module.exports = class mute extends commando.Command { emb.setDescription("**Reason**\n" + reason) .addField("Muted", mutedStr || "`[NONE]`") .addField("At", defaultDateFormat(duration.invoked), true) - .addField("For", duration.duration?.strings.join(" ") || "Indefinite", true) - .addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true); + .addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true) + .addField("For", duration.duration?.strings.join(" ") || "Indefinite"); + + if (cant.length > 0) emb.addField("Can't mute", "<@" + cant.join(">, <@") + ">\n\n**You can't mute someone with higher position than you <:nekokekLife:852865942530949160>**"); + if (already.length > 0) emb.addField("Already muted", "<@" + already.join(">, <@") + ">\n\nDuration updated for these users"); return trySend(msg.client, msg, { content: resultMsg, embed: emb }); } diff --git a/cmds/moderation/src/createInfraction.js b/cmds/moderation/src/createInfraction.js index ae66253..a5d1bc2 100644 --- a/cmds/moderation/src/createInfraction.js +++ b/cmds/moderation/src/createInfraction.js @@ -11,7 +11,7 @@ const { Message, User } = require("discord.js"); module.exports = (msg, targetUsers, punishment, reason) => { let infractionCase = msg.guild.DB.infractions.size; return { - infraction: infractionCase ? infractionCase++ : 1, + infraction: infractionCase ? ++infractionCase : 1, by: targetUsers, moderator: msg.author, punishment: punishment, diff --git a/cmds/moderation/src/targetUser.js b/cmds/moderation/src/targetUser.js index 99f2e31..bf0f4e9 100644 --- a/cmds/moderation/src/targetUser.js +++ b/cmds/moderation/src/targetUser.js @@ -13,33 +13,32 @@ const { cleanMentionID, findMemberRegEx } = require("../../../resources/function module.exports = async (msg, mentions = [], targetUser = [], resultMsg = "") => { if (mentions.length === 0) throw new TypeError("Mentions has no length"); for (const usermention of mentions) { - if (usermention.length > 0) { - let found = [], - nameid = cleanMentionID(usermention); - if (/^\d{17,19}$/.test(nameid)) { - const findmem = msg.guild.member(nameid); - if (findmem) { - found.push(findmem.user); - } else { - await msg.client.users.fetch(nameid).then(fetchUser => found.push(fetchUser)).catch(() => { }); - } + if (usermention.trim().length < 1) continue; + let found = [], + nameid = cleanMentionID(usermention); + if (/^\d{17,19}$/.test(nameid)) { + const findmem = msg.guild.member(nameid); + if (findmem) { + found.push(findmem.user); } else { - found = findMemberRegEx(msg, nameid).map(r => r.user); + await msg.client.users.fetch(nameid).then(fetchUser => found.push(fetchUser)).catch(() => { }); } - if (found.length > 0 && found[0] !== null) { - const foundDupli = targetUser.findIndex(r => r === found[0]); - if (foundDupli !== -1) { - resultMsg += `**[WARNING]** Duplicate for user **${targetUser[foundDupli].tag}** with keyword: **${usermention.trim()}**\n`; - } else { - targetUser.push(found[0]); - if (found.length > 1) { - resultMsg += `**[WARNING]** Multiple users found for: **${usermention.trim()}**\n`; - } - } + } else { + found = findMemberRegEx(msg, nameid)?.map(r => r.user); + } + if (found?.length > 0 && found[0] !== null) { + const foundDupli = targetUser.findIndex(r => r === found[0]); + if (foundDupli !== -1) { + resultMsg += `**[WARNING]** Duplicate for user **${targetUser[foundDupli].tag}** with keyword: **${usermention.trim()}**\n`; } else { - resultMsg += `Can't find user: **${usermention.trim()}**\n`; + targetUser.push(found[0]); + if (found.length > 1) { + resultMsg += `**[WARNING]** Multiple users found for: **${usermention.trim()}**\n`; + } } - } else continue; + } else { + resultMsg += `Can't find user: **${usermention.trim()}**\n`; + } } return { targetUser, resultMsg }; } \ No newline at end of file diff --git a/cmds/moderation/unmute.js b/cmds/moderation/unmute.js index 697fdb5..6d296ba 100644 --- a/cmds/moderation/unmute.js +++ b/cmds/moderation/unmute.js @@ -60,10 +60,10 @@ module.exports = class unmute extends commando.Command { } let emb = defaultImageEmbed(msg, null, "Unmute"); + emb.setDescription("**Reason**\n" + reason) + .addField("Unmuted", (success.length > 0 ? "<@" + success.join(">, <@") + ">" : "`[NONE]`")); if (cant.length > 0) emb.addField("Can't unmute", "<@" + cant.join(">, <@") + ">"); if (notMuted.length > 0) emb.addField("Wasn't muted", "<@" + notMuted.join(">, <@") + ">"); - emb.setDescription("**Unmuted**\n" + (success.length > 0 ? "<@" + success.join(">, <@") + ">" : "`[NONE]`")) - .addField("Reason", reason); return trySend(msg.client, msg, { content: resultMsg, embed: emb }); } } \ No newline at end of file diff --git a/cmds/utility/perms.js b/cmds/utility/perms.js index 98649db..20549f7 100644 --- a/cmds/utility/perms.js +++ b/cmds/utility/perms.js @@ -25,7 +25,7 @@ module.exports = class perms extends commando.Command { run(msg, arg) { let member, channel, mes = ""; if (arg) { - const forC = arg.match(/(? 0) { mes += `${res.join(", ")}\`\`\``; } else { diff --git a/resources/structures.js b/resources/structures.js index 09de44a..f65d677 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -14,14 +14,17 @@ Structures.extend("Guild", u => { async dbLoad() { return database.collection("Guild").findOne({ document: this.id }).then((r, e) => { if (e) return errLog(e, null, this.client); + console.log(r); if (!r) r = {}; if (!r.eventChannels) r.eventChannels = {}; if (!r.settings) r.settings = {}; let infractions = new Map(), timedPunishments = new Map(); if (r.infractions) - for (const U in r.infractions) + for (const U in r.infractions) { + console.log(r.infractions[U]); infractions.set(U, r.infractions[U]); + } if (r.timedPunishments) for (const U in r.timedPunishments) { const tr = new TimedPunishment(r.timedPunishments[U]); @@ -58,9 +61,10 @@ Structures.extend("Guild", u => { try { if (!this.DB) await this.dbLoad(); console.log("SETTING INF"); - const ret = this.DB.infractions.set(add.infraction, add); + const ret = this.DB.infractions.set(add.moderator.id + "/" + add.infraction, add); console.log(ret); await this.setDb("infractions", this.DB.infractions); + console.log(ret); return ret; } catch (e) { } } @@ -187,7 +191,7 @@ Structures.extend("User", u => { } /** - * @param {Guild} guild + * @param {Guild} guild * @param {string} reason * @param {{duration: object, saveTakenRoles: boolean, infraction: number, moderator: User}} data */ @@ -197,7 +201,7 @@ Structures.extend("User", u => { if (!guild.DB) await guild.dbLoad(); const MEM = guild.member(this); if (MEM) { - if (data.moderator.roles.highest.position < MEM.roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>"); + if (data.moderator.roles.highest.position < MEM.roles.highest.position || MEM.roles.highest.position > guild.member(this.client.user).roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>"); await MEM.mute(data, reason); } const MC = guild.getTimedPunishment(this.id, "mute"), @@ -212,7 +216,7 @@ Structures.extend("User", u => { if (!MC) throw new Error(this.tag + " isn't muted in " + guild.name); const MEM = guild.member(this); if (MEM) { - if (moderator.roles.highest.position < MEM.roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>"); + if (moderator.roles.highest.position < MEM.roles.highest.position || MEM.roles.highest.position > guild.member(this.client.user).roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>"); await MEM.unmute(reason); } return guild.removeTimedPunishment(this.id, "mute"); @@ -308,14 +312,15 @@ Structures.extend("GuildMember", u => { async mute(data, reason) { if (!this.DB) await this.dbLoad(); if (!data || !data.infraction) throw new Error("Missing infraction id"); - if (data.saveTakenRoles === undefined) data.saveTakenRoles = true; + if (!this.DB.muted) this.DB.muted = {}; + if (data.saveTakenRoles === undefined) data.saveTakenRoles = !(this.DB.muted.takenRoles?.length > 0); const ROLES = this.roles.cache.filter((r) => !r.managed).map(r => r.id); if (data.saveTakenRoles && ROLES?.length > 0) { console.log("populating takenRoles M"); this.DB.muted.takenRoles = ROLES; } - this.DB.muted.muteRole = this.guild.DB.mute.role; + this.DB.muted.muteRole = this.guild.DB.settings.mute.role; try { if (ROLES?.length > 0) await this.roles.remove(ROLES, reason);