From 47a5151c74a8ecb6736f7cf16ecc5f37a61d6fc9 Mon Sep 17 00:00:00 2001 From: Benedikt Magnus <magnus@magnuscraft.de> Date: Fri, 5 Nov 2021 17:15:50 +0100 Subject: [PATCH] Removed special functions abstraction from the messageHandler. --- .../wichtelbot/message/handlingDefinition.ts | 2 +- scripts/wichtelbot/message/messageHandler.ts | 28 ++++++++++--------- .../message/modules/generalModule.ts | 22 +-------------- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/scripts/wichtelbot/message/handlingDefinition.ts b/scripts/wichtelbot/message/handlingDefinition.ts index 76afd79..97c8f82 100644 --- a/scripts/wichtelbot/message/handlingDefinition.ts +++ b/scripts/wichtelbot/message/handlingDefinition.ts @@ -410,7 +410,7 @@ export default class HandlingDefinition public publicCommands: CommandDefinition[] = [ { commandInfo: Localisation.commands.contacting, - handlerFunction: async (message: Message): Promise<void> => this.generalModule.firstContact(message) + handlerFunction: async (message: Message): Promise<void> => this.generalModule.makeFirstContact(message) } ]; diff --git a/scripts/wichtelbot/message/messageHandler.ts b/scripts/wichtelbot/message/messageHandler.ts index cfd00f0..f7fa2aa 100644 --- a/scripts/wichtelbot/message/messageHandler.ts +++ b/scripts/wichtelbot/message/messageHandler.ts @@ -36,12 +36,6 @@ export default class MessageHandler // In group/server channels: protected publicCommands: CommandMap = new Map<string, CommandHandlerFunction>(); protected moderatorCommands: CommandMap = new Map<string, CommandHandlerFunction>(); - // Special: - protected firstContact: CommandHandlerFunction = async (message): Promise<void> => this.generalModule.firstContact(message); - protected messageNotUnterstood = async (message: Message): Promise<void> => this.generalModule.notUnderstood(message); - protected sentHelpText = async (message: Message, availableCommands: CommandInfo[]): Promise<void> => - this.generalModule.sendHelpText(message, availableCommands); - protected sentComponentText: CommandHandlerFunction = async (message): Promise<void> => this.generalModule.sentComponentText(message); protected componentExpectedStates: Set<State> = new Set(); @@ -168,7 +162,7 @@ export default class MessageHandler if (this.helpCommands.includes(message.command)) { const availableCommands = this.getAvailableCommands(state); - await this.sentHelpText(message, availableCommands); + await this.generalModule.sendHelpText(message, availableCommands); return CommandCallResult.Called; } @@ -271,18 +265,26 @@ export default class MessageHandler // We need to do nothing here, already called successfully. break; case CommandCallResult.MissingComponentOrigin: - // Who sent us the text on a button has to be put to his place: - await this.sentComponentText(message); - break; + { + // Who sent us the text on a button has to be put to his place: + const answer = Localisation.texts.sentComponentText.process(message.author); + await message.reply(answer); + + break; + } case CommandCallResult.NotFound: - await this.messageNotUnterstood(message); - break; + { + const answer = Localisation.texts.notUnderstood.process(message.author); + await message.reply(answer); + + break; + } } } else { // First contact: - await this.firstContact(message); + await this.generalModule.makeFirstContact(message); } } else diff --git a/scripts/wichtelbot/message/modules/generalModule.ts b/scripts/wichtelbot/message/modules/generalModule.ts index 33046d3..60aab5a 100644 --- a/scripts/wichtelbot/message/modules/generalModule.ts +++ b/scripts/wichtelbot/message/modules/generalModule.ts @@ -52,7 +52,7 @@ export default class GeneralModule * Makes first contact with a new user. \ * Will save the new contact in the database. */ - public async firstContact (message: Message): Promise<void> + public async makeFirstContact (message: Message): Promise<void> { let answer: string; @@ -150,26 +150,6 @@ export default class GeneralModule } } - /** - * Replies with the appropriate text for sending the text on a component instead of clicking it. - */ - public async sentComponentText (message: Message): Promise<void> - { - const answer = Localisation.texts.sentComponentText.process(message.author); - - await message.reply(answer); - } - - /** - * Replies context-dependend help messages. - */ - public async notUnderstood (message: Message): Promise<void> - { - const answer = Localisation.texts.notUnderstood.process(message.author); - - await message.reply(answer); - } - public async sendHelpText (message: Message, availableCommands: CommandInfo[]): Promise<void> { let helpText: string|null = null; -- GitLab