Exemplo n.º 1
0
        /// <summary>
        /// Check if a message contains a command and if so, handle it.
        /// </summary>
        /// <returns>A BotResponseCode if a command was handled, or NoAction if no matching command was found.</returns>
        public async Task <BotResponseCode> TryHandleCommand(UpdateDto updateDto)
        {
            foreach (var command in Enum.GetValues(typeof(TCommand)).Cast <TCommand>())
            {
                if (_commandsService.IsCommand(updateDto.ParsedTextMessage, command))
                {
                    var errorText = await ValidateRequirements(command, updateDto);

                    if (!string.IsNullOrEmpty(errorText))
                    {
                        // If there is a chat, answer with the errorText.
                        if (updateDto.ParsedChat != null)
                        {
                            await _sendMessageService.SendTextMessage(updateDto.ParsedChat.Id, errorText);
                        }

                        return(BotResponseCode.CommandRequirementNotFulfilled);
                    }

                    var responseCode = await HandleCommand(command, updateDto);

                    if (responseCode != BotResponseCode.NoAction)
                    {
                        return(responseCode);
                    }
                }
            }

            return(BotResponseCode.NoAction);
        }
Exemplo n.º 2
0
 private bool IsStartCommand(UpdateDto updateDto)
 {
     return(_commandsService.IsCommand(updateDto.ParsedTextMessage, Command.Start));
 }