From ca7b05ce78626fc8711be4ce7293a0085ae78186 Mon Sep 17 00:00:00 2001 From: Almeida Date: Fri, 7 May 2021 20:32:33 +0100 Subject: [PATCH] fix: leave_voice_channel not triggering --- .../src/plugins/Automod/triggers/joinVoiceChannel.ts | 11 +++++++---- .../src/plugins/Automod/triggers/leaveVoiceChannel.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts b/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts index ecd34e3e..9064fb45 100644 --- a/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts +++ b/backend/src/plugins/Automod/triggers/joinVoiceChannel.ts @@ -1,5 +1,6 @@ import * as t from "io-ts"; import { automodTrigger } from "../helpers"; +import { Constants } from "eris"; interface JoinVoiceChannelResult { matchedChannelId: string; @@ -11,18 +12,19 @@ export const JoinVoiceChannelTrigger = automodTrigger()( defaultConfig: "", async match({ triggerConfig, context }) { - if (!context.member || !context.voiceChannel) { + const matchedChannelId = context.voiceChannel?.joined?.id; + if (!context.member || !matchedChannelId) { return; } const triggerChannels = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig]; - if (!triggerChannels.includes(context.voiceChannel.id)) { + if (!triggerChannels.includes(matchedChannelId)) { return; } return { extra: { - matchedChannelId: context.voiceChannel.id, + matchedChannelId, }, }; }, @@ -32,6 +34,7 @@ export const JoinVoiceChannelTrigger = automodTrigger()( const channelName = channel?.name || "Unknown"; const member = contexts[0].member!; const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`; - return `${memberName} has joined the ${channelName} (\`${matchResult.extra.matchedChannelId}\`) voice channel`; + const voiceOrStage = channel?.type === Constants.ChannelTypes.GUILD_STAGE ? "stage" : "voice"; + return `${memberName} has joined the ${channelName} (\`${matchResult.extra.matchedChannelId}\`) ${voiceOrStage} channel`; }, }); diff --git a/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts b/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts index 51b6467e..d4125d6f 100644 --- a/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts +++ b/backend/src/plugins/Automod/triggers/leaveVoiceChannel.ts @@ -1,3 +1,4 @@ +import { Constants } from "eris"; import * as t from "io-ts"; import { automodTrigger } from "../helpers"; @@ -11,18 +12,19 @@ export const LeaveVoiceChannelTrigger = automodTrigger( defaultConfig: "", async match({ triggerConfig, context }) { - if (!context.member || !context.voiceChannel) { + const matchedChannelId = context.voiceChannel?.left?.id; + if (!context.member || !matchedChannelId) { return; } const triggerChannels = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig]; - if (!triggerChannels.includes(context.voiceChannel.id)) { + if (!triggerChannels.includes(matchedChannelId)) { return; } return { extra: { - matchedChannelId: context.voiceChannel.id, + matchedChannelId, }, }; }, @@ -32,6 +34,7 @@ export const LeaveVoiceChannelTrigger = automodTrigger( const channelName = channel?.name || "Unknown"; const member = contexts[0].member!; const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`; - return `${memberName} has left the ${channelName} (\`${matchResult.extra.matchedChannelId}\`) voice channel`; + const voiceOrStage = channel?.type === Constants.ChannelTypes.GUILD_STAGE ? "stage" : "voice"; + return `${memberName} has left the ${channelName} (\`${matchResult.extra.matchedChannelId}\`) ${voiceOrStage} channel`; }, });