From 2fc8cffd80a8a17a003f0932d54b4d5ce28b884e Mon Sep 17 00:00:00 2001 From: Nils <7890309+DarkView@users.noreply.github.com> Date: Fri, 2 Apr 2021 15:39:22 +0200 Subject: [PATCH] Allow kicking the user from VC on mute (#156) * Allow kicking the user from VC on mute If any non-id string is entered in `move_to_voice_channel`, the user is kicked from the VC instead of being moved. We do not automatically kick if the option is set to null in order to not make this a breaking change for old, intended behavior * Add explicit config option for kicking instead of kicking on any non-id Kicking takes precedent in this case and will take effect instead of moving to voice id --- backend/src/plugins/Mutes/MutesPlugin.ts | 1 + backend/src/plugins/Mutes/functions/muteUser.ts | 7 ++++--- backend/src/plugins/Mutes/types.ts | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Mutes/MutesPlugin.ts b/backend/src/plugins/Mutes/MutesPlugin.ts index ac55acc6..36fb425e 100644 --- a/backend/src/plugins/Mutes/MutesPlugin.ts +++ b/backend/src/plugins/Mutes/MutesPlugin.ts @@ -25,6 +25,7 @@ const defaultOptions = { config: { mute_role: null, move_to_voice_channel: null, + kick_from_voice_channel: false, dm_on_mute: false, dm_on_update: false, diff --git a/backend/src/plugins/Mutes/functions/muteUser.ts b/backend/src/plugins/Mutes/functions/muteUser.ts index 2f8e4e28..393a00e1 100644 --- a/backend/src/plugins/Mutes/functions/muteUser.ts +++ b/backend/src/plugins/Mutes/functions/muteUser.ts @@ -120,11 +120,12 @@ export async function muteUser( } // If enabled, move the user to the mute voice channel (e.g. afk - just to apply the voice perms from the mute role) - const moveToVoiceChannelId = pluginData.config.get().move_to_voice_channel; - if (moveToVoiceChannelId) { + const cfg = pluginData.config.get(); + const moveToVoiceChannel = cfg.kick_from_voice_channel ? null : cfg.move_to_voice_channel; + if (moveToVoiceChannel || cfg.kick_from_voice_channel) { // TODO: Add back the voiceState check once we figure out how to get voice state for guild members that are loaded on-demand try { - await member.edit({ channelID: moveToVoiceChannelId }); + await member.edit({ channelID: moveToVoiceChannel }); } catch (e) {} // tslint:disable-line } } diff --git a/backend/src/plugins/Mutes/types.ts b/backend/src/plugins/Mutes/types.ts index 72ea52c2..7da2cb0d 100644 --- a/backend/src/plugins/Mutes/types.ts +++ b/backend/src/plugins/Mutes/types.ts @@ -15,6 +15,7 @@ import { EventEmitter } from "events"; export const ConfigSchema = t.type({ mute_role: tNullable(t.string), move_to_voice_channel: tNullable(t.string), + kick_from_voice_channel: t.boolean, dm_on_mute: t.boolean, dm_on_update: t.boolean,