Пример #1
0
        private async Task ProcessMessage(BotEventArgs e)
        {
            using var scope = _serviceProvider.CreateScope();
            var commandHandler = new CommandHandler(scope.ServiceProvider);

            CommandContainer commandContainer = _commandParser.ParseCommand(e);

            if (!commandContainer.StartsWithPrefix(_prefix))
            {
                return;
            }

            commandContainer.RemovePrefix(_prefix);

            Result checkResult = commandHandler.CheckArgsCount(commandContainer);

            if (!checkResult.IsSuccess)
            {
                throw new CommandArgumentsException(checkResult.Message);
            }

            checkResult = commandHandler.CanCommandBeExecuted(commandContainer);
            if (!checkResult.IsSuccess)
            {
                throw new CommandCantBeExecutedException(checkResult.Message);
            }

            IBotMessage message = await commandHandler.ExecuteCommand(commandContainer);

            await message.SendAsync(_apiProvider, e.SenderInfo);
        }