Restructure BotManager logic to use switch cases.#3
Restructure BotManager logic to use switch cases.#3tergytrg wants to merge 1 commit intoPlaceNL:masterfrom
Conversation
|
Wat betreft code ben ik het eens dat dit er beter uit ziet, maar ook ik heb nog geen test bot. @Sheepolution kun jij testen of dit werkt? |
|
The idea is good, but I'm not a fan of the nested switch statements. Don't forget to add |
| } else if (interaction.customId.startsWith('coordinate_claim')) { | ||
| ArtHandler.OnClaimPixel(messageInfo, interaction.customId.split('_')[2]); | ||
| const messageInfo: IMessageInfo = await DiscordUtils.ParseInteractionToInfo(interaction); | ||
| const id_parts = interaction.customId.split('_'); |
There was a problem hiding this comment.
Use idParts instead.
| const id_parts = interaction.customId.split('_'); | |
| const idParts = interaction.customId.split('_'); |
| const messageInfo: IMessageInfo = await DiscordUtils.ParseInteractionToInfo(interaction); | ||
| const id_parts = interaction.customId.split('_'); | ||
| switch(id_parts[0]) { | ||
| case 'onboarding': { |
There was a problem hiding this comment.
Don't forget to place a break after each case.
| const id_parts = interaction.customId.split('_'); | ||
| switch(id_parts[0]) { | ||
| case 'onboarding': { | ||
| switch(id_parts[1]) { |
There was a problem hiding this comment.
Instead of a nested switch statement, create an InteractionHandler and place the inner switch statement in a method there.
There was a problem hiding this comment.
An InteractionHandler is a good idea! At that point, is there any reason to distinguish between Button, Modal, and ThreadMenu interactions? I feel like we can leave that to the BotManager, and let the InteractionHandler contain methods like onDiplomacyInteraction and onVoteInteraction to reduce the complexity.
This PR refactors the existing interaction handling logic to use switch statements instead of if-else blocks. This makes the code more concise, easier to read, and it better represents the Interaction categories.
Changes Made:
Disclaimer:
I have not tested this code as setting up a Discord Application would require a lot of work. I would greatly appreciate if someone with a test-application available could make sure the functionality is unchanged.