From 098230b091b21037d1e9cd4a93aada575e6dc5b8 Mon Sep 17 00:00:00 2001
From: Benedikt Magnus <magnus@magnuscraft.de>
Date: Tue, 2 Nov 2021 22:32:58 +0100
Subject: [PATCH] Fixed that select component's contents could still be send as
 text.

---
 .../wichtelbot/message/handlingDefinition.ts    | 17 ++++++++++++++---
 scripts/wichtelbot/message/messageHandler.ts    | 10 +++++-----
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/scripts/wichtelbot/message/handlingDefinition.ts b/scripts/wichtelbot/message/handlingDefinition.ts
index a4bca66..2771211 100644
--- a/scripts/wichtelbot/message/handlingDefinition.ts
+++ b/scripts/wichtelbot/message/handlingDefinition.ts
@@ -21,18 +21,21 @@ interface CommandPath
     result: any;
 }
 
-interface PathedStateCommandDefinition
+interface BaseCommandDefinition
 {
     state: State;
     /** True if the command comes from a previously send component, otherwise false. */
     expectsComponentResult: boolean;
+}
+
+interface PathedStateCommandDefinition extends BaseCommandDefinition
+{
     paths: CommandPath[];
     handlerFunction: StateCommandHandlerFunction;
 }
 
-interface CatchallStateCommandDefinition
+interface CatchallStateCommandDefinition extends BaseCommandDefinition
 {
-    state: State;
     paths: null;
     handlerFunction: CommandHandlerFunction;
 }
@@ -195,6 +198,7 @@ export default class HandlingDefinition
         // Information, Address:
         {
             state: State.InformationAddress,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -211,6 +215,7 @@ export default class HandlingDefinition
         // Information, Country:
         {
             state: State.InformationCountry,
+            expectsComponentResult: true,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -256,6 +261,7 @@ export default class HandlingDefinition
         // Information, DigitalAddress:
         {
             state: State.InformationDigitalAddress,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -304,6 +310,7 @@ export default class HandlingDefinition
         // Information, Wish List:
         {
             state: State.InformationWishList,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -326,6 +333,7 @@ export default class HandlingDefinition
         // Information, Allergies:
         {
             state: State.InformationAllergies,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -337,6 +345,7 @@ export default class HandlingDefinition
         // Information, GiftExclusion:
         {
             state: State.InformationGiftExclusion,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -348,6 +357,7 @@ export default class HandlingDefinition
         // Information, UserExclusion:
         {
             state: State.InformationUserExclusion,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
@@ -359,6 +369,7 @@ export default class HandlingDefinition
         // Information, FreeText:
         {
             state: State.InformationFreeText,
+            expectsComponentResult: false,
             paths: null,
             handlerFunction: async (message: Message): Promise<void> =>
             {
diff --git a/scripts/wichtelbot/message/messageHandler.ts b/scripts/wichtelbot/message/messageHandler.ts
index db4c972..868abb4 100644
--- a/scripts/wichtelbot/message/messageHandler.ts
+++ b/scripts/wichtelbot/message/messageHandler.ts
@@ -71,6 +71,11 @@ export default class MessageHandler
         // State commands:
         for (const stateCommandDefinition of this.handlingDefinition.stateCommands)
         {
+            if (stateCommandDefinition.expectsComponentResult)
+            {
+                this.componentExpectedStates.add(stateCommandDefinition.state);
+            }
+
             if (stateCommandDefinition.paths === null)
             {
                 const stateCommand = new StateCommand(stateCommandDefinition.state, '');
@@ -79,11 +84,6 @@ export default class MessageHandler
             }
             else
             {
-                if (stateCommandDefinition.expectsComponentResult)
-                {
-                    this.componentExpectedStates.add(stateCommandDefinition.state);
-                }
-
                 for (const path of stateCommandDefinition.paths)
                 {
                     this.prepareCommandInfo(path.command,
-- 
GitLab