Ejemplo n.º 1
0
        static async Task MainAsync(string[] args)
        {
            discord.MessageCreated += async e =>
            {
                var channel = channelbotConfiguration.GetChannelConfiguration(e);
                UpdateStatus();

                if (e.Message.Author.Username == discord.CurrentUser.Username)
                {
                    await chatUpdateService.UpdateChatAsync(e);
                }
                else if (commandService.command(e, channel))
                {

                }
                else if(!botUtilityService.ignoreMessage(e))
                {
                    var reaction = await reactionService.GetReactionAsync(e);
                    botReactionService.reactionResponse(e, reaction, channel.ChannelSettings);

                    var hasRequiredProperty = await userDetailService.HasRequiredPropertyAsync(e);
                    if(hasRequiredProperty)
                    {
                        var chatResponse = await chatResponseService.GetChatResponseAsync(e);
                        requiredPropertyResponseService.hasRequiredPropertyResponse(e, chatResponse, channel.ChannelSettings);
                    }
                    else
                    {
                        var chatResponse = await chatResponseService.GetChatResponseAsync(e);
                        hasRequiredProperty = await userDetailService.HasRequiredPropertyAsync(e);
                        if(!hasRequiredProperty && botUtilityService.alwaysRespond(e))
                        {
                            botUtilityService.defaultResponse(e);
                        }
                        else
                        {
                            requiredPropertyResponseService.hasRequiredPropertyResponse(e, chatResponse, channel.ChannelSettings);
                        }
                    }
                }
            };

            discord.MessageReactionAdded += async e =>
            {
                await reactionAddService.AddReactionAsync(e);
            };

            await discord.ConnectAsync();
            await Task.Delay(-1);
        }
Ejemplo n.º 2
0
        public async Task GetChatResponseAsyncReturnsApiResponse()
        {
            var chatResponse = new ChatResponse();

            chatResponse.response = new List <string>();
            chatResponse.response.Add("hello world");
            chatResponse.confidence = .42;

            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(chatResponse)),
            }).Verifiable();

            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };


            var botConfiguration = new BotConfiguration();
            var service          = new ChatResponseService(httpClient, botConfiguration);

            var result = await service.GetChatResponseAsync("test");

            Assert.Equal(chatResponse.response, result.response);
            Assert.Equal(chatResponse.confidence, result.confidence);
        }