From 9aa4516a3a6e81ef3b73808bb96951cb7640dbd0 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Mon, 13 Jan 2020 21:45:27 +1100 Subject: [PATCH 1/4] initial commit --- backend/src/plugins/Mutes.ts | 45 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index 1f060991..dbdf7458 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -37,6 +37,7 @@ const ConfigSchema = t.type({ message_channel: tNullable(t.string), mute_message: tNullable(t.string), timed_mute_message: tNullable(t.string), + update_mute_message: tNullable(t.string), can_view_list: t.boolean, can_cleanup: t.boolean, @@ -86,6 +87,7 @@ export class MutesPlugin extends ZeppelinPlugin { message_channel: null, mute_message: "You have been muted on the {guildName} server. Reason given: {reason}", timed_mute_message: "You have been muted on the {guildName} server for {time}. Reason given: {reason}", + update_mute_message: "Your mute on the {guildName} server has been updated to {time}.", can_view_list: false, can_cleanup: false, @@ -144,6 +146,7 @@ export class MutesPlugin extends ZeppelinPlugin { const user = await this.resolveUser(userId); const member = await this.getMember(user.id, true); // Grab the fresh member so we don't have stale role info + const config = this.getMatchingConfig({ member, userId }); if (member) { // Apply mute role if it's missing @@ -169,29 +172,31 @@ export class MutesPlugin extends ZeppelinPlugin { await this.mutes.updateExpiryTime(user.id, muteTime); } else { await this.mutes.addMute(user.id, muteTime); + } - // If it's a new mute, attempt to message the user - const config = this.getMatchingConfig({ member, userId }); - const template = muteTime ? config.timed_mute_message : config.mute_message; + const template = existingMute + ? config.update_mute_message + : muteTime + ? config.timed_mute_message + : config.mute_message; - const muteMessage = - template && - (await renderTemplate(template, { - guildName: this.guild.name, - reason, - time: timeUntilUnmute, - })); + const muteMessage = + template && + (await renderTemplate(template, { + guildName: this.guild.name, + reason, + time: timeUntilUnmute, + })); - if (reason && muteMessage) { - if (user instanceof User) { - notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, { - useDM: config.dm_on_mute, - useChannel: config.message_on_mute, - channelId: config.message_channel, - }); - } else { - notifyResult = { status: NotifyUserStatus.Failed }; - } + if (reason && muteMessage) { + if (user instanceof User) { + notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, { + useDM: config.dm_on_mute, + useChannel: config.message_on_mute, + channelId: config.message_channel, + }); + } else { + notifyResult = { status: NotifyUserStatus.Failed }; } } From 58831212817841d17fcf7035d28bda8ced6a594c Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Wed, 15 Jan 2020 22:15:39 +1100 Subject: [PATCH 2/4] implemented user alerts for mute updates --- backend/src/plugins/Mutes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index dbdf7458..24c86f10 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -188,7 +188,7 @@ export class MutesPlugin extends ZeppelinPlugin { time: timeUntilUnmute, })); - if (reason && muteMessage) { + if ((reason && muteMessage) || existingMute) { if (user instanceof User) { notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, { useDM: config.dm_on_mute, From 3d5969979aca1d7475da977ebaf51de1344561b3 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Thu, 16 Jan 2020 22:19:08 +1100 Subject: [PATCH 3/4] implemented user alerts for updates --- backend/src/plugins/Mutes.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index 24c86f10..41c74337 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -33,7 +33,9 @@ const ConfigSchema = t.type({ move_to_voice_channel: tNullable(t.string), dm_on_mute: t.boolean, + dm_on_update: t.boolean, message_on_mute: t.boolean, + message_on_update: t.boolean, message_channel: tNullable(t.string), mute_message: tNullable(t.string), timed_mute_message: tNullable(t.string), @@ -83,7 +85,9 @@ export class MutesPlugin extends ZeppelinPlugin { move_to_voice_channel: null, dm_on_mute: false, + dm_on_update: false, message_on_mute: false, + message_on_update: false, message_channel: null, mute_message: "You have been muted on the {guildName} server. Reason given: {reason}", timed_mute_message: "You have been muted on the {guildName} server for {time}. Reason given: {reason}", @@ -137,7 +141,7 @@ export class MutesPlugin extends ZeppelinPlugin { const muteRole = this.getConfig().mute_role; if (!muteRole) return; - const timeUntilUnmute = muteTime && humanizeDuration(muteTime); + const timeUntilUnmute = muteTime ? muteTime && humanizeDuration(muteTime) : "indefinite"; // No mod specified -> mark Zeppelin as the mod if (!caseArgs.modId) { @@ -184,22 +188,23 @@ export class MutesPlugin extends ZeppelinPlugin { template && (await renderTemplate(template, { guildName: this.guild.name, - reason, + reason: reason || reason === "" ? "None" : reason, time: timeUntilUnmute, })); - if ((reason && muteMessage) || existingMute) { + if (muteMessage) { + const useDm = existingMute ? config.dm_on_update : config.dm_on_mute; + const useChannel = existingMute ? config.message_on_update : config.message_on_mute; if (user instanceof User) { notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, { - useDM: config.dm_on_mute, - useChannel: config.message_on_mute, + useDM: useDm.valueOf(), + useChannel: useChannel.valueOf(), channelId: config.message_channel, }); } else { notifyResult = { status: NotifyUserStatus.Failed }; } } - // Create/update a case const casesPlugin = this.getPlugin("cases"); let theCase; From be28b641025c8050fa66b3af3aa7ae32245f94b4 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Thu, 16 Jan 2020 22:19:53 +1100 Subject: [PATCH 4/4] fixed bad parameter --- backend/src/plugins/Mutes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index 41c74337..b76b5e27 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -197,8 +197,8 @@ export class MutesPlugin extends ZeppelinPlugin { const useChannel = existingMute ? config.message_on_update : config.message_on_mute; if (user instanceof User) { notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, { - useDM: useDm.valueOf(), - useChannel: useChannel.valueOf(), + useDM: useDm, + useChannel, channelId: config.message_channel, }); } else {