From f949a3825a7b248d7a800bf4b55e470e13e37379 Mon Sep 17 00:00:00 2001 From: Almeida Date: Sat, 8 May 2021 14:45:38 +0100 Subject: [PATCH] added include_moves option to join_voice_channel and leave_voice_channel --- .../plugins/Automod/triggers/joinVoiceChannel.ts | 14 ++++++++++---- .../plugins/Automod/triggers/leaveVoiceChannel.ts | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts b/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts index 16723584..55ff01ac 100644 --- a/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts +++ b/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts @@ -7,17 +7,23 @@ interface JoinVoiceChannelResult { } export const JoinVoiceChannelTrigger = automodTrigger()({ - configType: t.union([t.string, t.array(t.string)]), + configType: t.type({ + channels: t.union([t.string, t.array(t.string)]), + include_moves: t.boolean, + }), - defaultConfig: "", + defaultConfig: {}, async match({ triggerConfig, context }) { const matchedChannelId = context.voiceChannel?.joined?.id; - if (!context.member || !matchedChannelId || context.voiceChannel?.left) { + const includeMoves = + typeof triggerConfig === "object" && !Array.isArray(triggerConfig) && triggerConfig.include_moves; + + if (!context.member || !matchedChannelId || (context.voiceChannel?.left && !includeMoves)) { return; } - const triggerChannels = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig]; + const triggerChannels = Array.isArray(triggerConfig.channels) ? triggerConfig.channels : [triggerConfig.channels]; if (!triggerChannels.includes(matchedChannelId)) { return; } diff --git a/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts b/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts index 4c8d2e09..91ffb27d 100644 --- a/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts +++ b/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts @@ -7,17 +7,23 @@ interface LeaveVoiceChannelResult { } export const LeaveVoiceChannelTrigger = automodTrigger()({ - configType: t.union([t.string, t.array(t.string)]), + configType: t.type({ + channels: t.union([t.string, t.array(t.string)]), + include_moves: t.boolean, + }), - defaultConfig: "", + defaultConfig: {}, async match({ triggerConfig, context }) { const matchedChannelId = context.voiceChannel?.left?.id; - if (!context.member || !matchedChannelId || context.voiceChannel?.joined) { + const includeMoves = + typeof triggerConfig === "object" && !Array.isArray(triggerConfig) && triggerConfig.include_moves; + + if (!context.member || !matchedChannelId || (context.voiceChannel?.joined && !includeMoves)) { return; } - const triggerChannels = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig]; + const triggerChannels = Array.isArray(triggerConfig.channels) ? triggerConfig.channels : [triggerConfig.channels]; if (!triggerChannels.includes(matchedChannelId)) { return; }