From bb9b8cfe06437cc1b977f2e7f410ebaef4c65f5f Mon Sep 17 00:00:00 2001
From: Dark <7890309+DarkView@users.noreply.github.com>
Date: Thu, 1 Jul 2021 00:30:48 +0200
Subject: [PATCH] Proper button validation, bugfix for voice move spam

---
 .../src/plugins/ReactionRoles/ReactionRolesPlugin.ts   | 10 ++++++++++
 backend/src/plugins/Spam/events/SpamVoiceEvt.ts        |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts
index 47aa4c64..1c841457 100644
--- a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts
+++ b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts
@@ -63,6 +63,11 @@ const configPreprocessor: ConfigPreprocessorFn<ReactionRolesPluginType> = option
             `Invalid value for default_buttons/${defaultButtonNames[i]}/role_or_menu: ${defBtn.role_or_menu} is neither an existing menu nor a valid snowflake.`,
           ]);
         }
+        if (!defBtn.label && !defBtn.emoji) {
+          throw new StrictValidationError([
+            `Invalid values for default_buttons/${defaultButtonNames[i]}/(label|emoji): Must have label, emoji or both set for the button to be valid.`,
+          ]);
+        }
       }
 
       for (const [menuName, menuButtonEntries] of Object.entries(group.button_menus ?? [])) {
@@ -83,6 +88,11 @@ const configPreprocessor: ConfigPreprocessorFn<ReactionRolesPluginType> = option
               `Invalid value for button_menus/${menuButtonNames[i]}/role_or_menu: ${menuBtn.role_or_menu} is neither an existing menu nor a valid snowflake.`,
             ]);
           }
+          if (!menuBtn.label && !menuBtn.emoji) {
+            throw new StrictValidationError([
+              `Invalid values for default_buttons/${defaultButtonNames[i]}/(label|emoji): Must have label, emoji or both set for the button to be valid.`,
+            ]);
+          }
         }
       }
     }
diff --git a/backend/src/plugins/Spam/events/SpamVoiceEvt.ts b/backend/src/plugins/Spam/events/SpamVoiceEvt.ts
index 7e862325..36aba638 100644
--- a/backend/src/plugins/Spam/events/SpamVoiceEvt.ts
+++ b/backend/src/plugins/Spam/events/SpamVoiceEvt.ts
@@ -7,7 +7,8 @@ export const SpamVoiceStateUpdateEvt = spamEvt({
   async listener(meta) {
     const member = meta.args.newState.member;
     if (!member) return;
-    const channel = meta.args.newState.channel!;
+    const channel = meta.args.newState.channel;
+    if (!channel) return;
 
     const config = await meta.pluginData.config.getMatchingConfig({ member, channelId: channel.id });
     const maxVoiceMoves = config.max_voice_moves;