コード例 #1
0
        public async Task TheHandleMethodShouldRemoveResponseAsync()
        {
            // Arrange
            chatResponseRepository.RemoveAsync("foo").Returns(true);

            // Act
            await commandHandler.HandleAsync("remove foo", string.Empty, default);

            // Assert
            await chatResponseRepository.Received().RemoveAsync("foo");

            slackbot.Received().SendMessage(string.Empty, "I just forgot your response. Can't remember a thing.");
        }
コード例 #2
0
        public async Task HandleAsync(string arguments, string channel, CancellationToken cancellationToken)
        {
            Match match = regex.Match(arguments ?? string.Empty);

            if (match.Success)
            {
                switch (match.Groups[1].Value)
                {
                case "add":

                    await chatResponseRepository.AddAsync(match.Groups[2].Value, match.Groups[3].Value);

                    slackbot.SendMessage(channel, "I added your chat response to my AI.");

                    break;

                case "remove":
                    if (await chatResponseRepository.RemoveAsync(match.Groups[2].Value))
                    {
                        slackbot.SendMessage(channel, "I just forgot your response. Can't remember a thing.");
                    }

                    break;
                }
            }
            else
            {
                foreach (ChatResponse chatResponse in await chatResponseRepository.GetAsync(cancellationToken))
                {
                    if (new Regex(chatResponse.Regex).IsMatch(arguments ?? string.Empty))
                    {
                        slackbot.SendMessage(channel, chatResponse.Response);

                        break;
                    }
                }
            }
        }