From 3172abe5a8c5ad74c2cb8cd16e11ddb36ca33816 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Sun, 19 Jan 2020 11:23:51 +1100 Subject: [PATCH 1/2] mute command can now remove muted role from users who are not in the mutes DB table --- backend/src/plugins/ModActions.ts | 7 ++++--- backend/src/plugins/Mutes.ts | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/ModActions.ts b/backend/src/plugins/ModActions.ts index 578fd7c7..9906e7d9 100644 --- a/backend/src/plugins/ModActions.ts +++ b/backend/src/plugins/ModActions.ts @@ -892,16 +892,17 @@ export class ModActionsPlugin extends ZeppelinPlugin { async unmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) { const user = await this.resolveUser(args.user); if (!user) return this.sendErrorMessage(msg.channel, `User not found`); + const memberToUnmute = await this.getMember(user.id); + const mutesPlugin = this.getPlugin("mutes"); + const hasMuteRole = mutesPlugin.hasMutedRole(memberToUnmute); // Check if they're muted in the first place - if (!(await this.mutes.isMuted(args.user))) { + if (!(await this.mutes.isMuted(args.user)) && !hasMuteRole) { this.sendErrorMessage(msg.channel, "Cannot unmute: member is not muted"); return; } // Find the server member to unmute - const memberToUnmute = await this.getMember(user.id); - if (!memberToUnmute) { const isBanned = await this.isBanned(user.id); const prefix = this.guildConfig.prefix; diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index 567878d8..6363d0c7 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -275,14 +275,18 @@ export class MutesPlugin extends ZeppelinPlugin { caseArgs: Partial = {}, ): Promise { const existingMute = await this.mutes.findExistingMuteForUserId(userId); - if (!existingMute) return; - const user = await this.resolveUser(userId); const member = await this.getMember(userId, true); // Grab the fresh member so we don't have stale role info + if (!existingMute && !this.hasMutedRole(member)) return; + if (unmuteTime) { // Schedule timed unmute (= just set the mute's duration) - await this.mutes.updateExpiryTime(userId, unmuteTime); + if (!existingMute) { + await this.mutes.addMute(userId, unmuteTime); + } else { + await this.mutes.updateExpiryTime(userId, unmuteTime); + } } else { // Unmute immediately if (member) { @@ -295,8 +299,9 @@ export class MutesPlugin extends ZeppelinPlugin { `Member ${userId} not found in guild ${this.guild.name} (${this.guildId}) when attempting to unmute`, ); } - - await this.mutes.clear(userId); + if (existingMute) { + await this.mutes.clear(userId); + } } const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime); @@ -338,6 +343,13 @@ export class MutesPlugin extends ZeppelinPlugin { }; } + public hasMutedRole(member: Member) { + if (member.roles.includes(this.getConfig().mute_role)) { + return true; + } + return false; + } + @d.command("mutes", [], { options: [ { From b239d8ba567cc098427e7e3a6d0f086c2651c849 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Tue, 21 Jan 2020 21:57:15 +1100 Subject: [PATCH 2/2] added extra notes --- backend/src/plugins/Mutes.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index 6363d0c7..b23e78a5 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -313,6 +313,9 @@ export class MutesPlugin extends ZeppelinPlugin { } else { noteDetails.push(`Unmuted immediately`); } + if (!existingMute) { + noteDetails.push(`Removed manual role mute`); + } const casesPlugin = this.getPlugin("cases"); const createdCase = await casesPlugin.createCase({