Пример #1
0
        public void should_find_and_execute_command()
        {
            var expectedResult = new BotCommandResult(BotCode.Good, "expectedResult");

            A.CallTo(() => fakeCommand.Execute(A <string[]> .Ignored)).Returns(expectedResult);

            var commandResult = _bot.HandleCommand(fakeCommandName);

            Assert.AreEqual(commandResult, "expectedResult");
        }
Пример #2
0
        public async Task <IBotMessage> ExecuteCommand(CommandContainer args)
        {
            IBotCommand command = _serviceProvider.GetCommand(args.CommandName);

            try
            {
                return(await command.Execute(args));
            }
            catch (Exception e)
            {
                LoggerHolder.Instance.Error("Command execution failed. Command: {args.CommandName}; arguments: {string.Join(", ", args.Arguments)}");
                throw;
            }
        }
        private async Task OnDiscordClientMessageCreated(DiscordClient sender, DSharpPlus.EventArgs.MessageCreateEventArgs e)
        {
            if (e.Message.Content.StartsWith("!"))
            {
                var response          = "";
                var discordBotCommand = new DiscordBotCommand(e.Message.Content);

                try
                {
                    IBotCommand botCommand = _factory.GetByName(discordBotCommand.Command);

                    if (botCommand != null)
                    {
                        response = await botCommand.Execute(discordBotCommand);
                    }
                }
                catch { }

                await e.Message.RespondAsync(response);
            }
        }
Пример #4
0
        public void ShouldSendMessage()
        {
            _command.Execute();

            Assert.True(_senderSpy.SendMessageTriggered);
        }