Exemplo n.º 1
0
        private async Task <HttpResponseMessage> HandleGroupMessage(Activity activity, CancellationToken cancellationToken)
        {
            var enableDisableSucceeded = await CheckEnableDisable(activity, cancellationToken);

            if (enableDisableSucceeded)
            {
                return(null);
            }

            if (!_teamsToggleLogic.Value.IsEnabledInChannel)
            {
                return(null);
            }

            activity.Text = Utilities.TrimWhitespace(activity.Text);

            var scoreboardRegexMatch = _messageLogic.IsGettingScoreboard(activity.Text);

            if (scoreboardRegexMatch.Success)
            {
                return(await HandleScoreboardRequest(activity, scoreboardRegexMatch, cancellationToken));
            }
            else
            {
                var scoreRegexMatch = _messageLogic.IsGettingScore(activity.Text);
                if (scoreRegexMatch.Success)
                {
                    return(await HandleScoreRequest(activity, scoreRegexMatch, cancellationToken));
                }
            }

            // Check for commands.
            if (KarmaLogic.SomeoneReceivedKarmaInWholeMessage(activity.Text))
            {
                // Karma command
                return(await HandleKarmaChange(activity, cancellationToken));
            }

            // Add more commands here.

            if (_messageLogic.IsAskingForHelp(activity.Text))
            {
                return(await SendHelpMessage(activity, cancellationToken));
            }

            // Often, users respond with a gif just after karma has been given.
            // they also accidentally mention @karma. Don't respond to this.
            if (activity.Attachments.Any(a => a.ContentType.Contains("image")))
            {
                return(null);
            }

            return(await SendMessage(Strings.DidNotUnderstand, activity, cancellationToken));
        }
Exemplo n.º 2
0
        private async Task <HttpResponseMessage> HandlePersonalMessage(Activity activity, CancellationToken cancellationToken)
        {
            activity.Text = Utilities.TrimWhitespace(activity.Text);

            var scoreboardRegexMatch = _messageLogic.IsGettingScoreboard(activity.Text);

            if (scoreboardRegexMatch.Success)
            {
                return(await HandleScoreboardRequest(activity, scoreboardRegexMatch, cancellationToken));
            }
            else
            {
                var scoreRegexMatch = _messageLogic.IsGettingScore(activity.Text);
                if (scoreRegexMatch.Success)
                {
                    return(await HandleScoreRequest(activity, scoreRegexMatch, cancellationToken));
                }
            }

            // Check for forbidden commands.
            if (KarmaLogic.SomeoneReceivedKarmaInWholeMessage(activity.Text))
            {
                var reply = activity.CreateReply("You cannot change karma in a personal chat.", activity.Locale);
                using (var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl)))
                {
                    await connectorClient.Conversations.ReplyToActivityAsync(reply, cancellationToken);
                }

                Trace.TraceInformation($"<message>{activity.Text}</message><reply>{reply.Text}</reply>");
            }

            // Add things you *can* do in personal chat (like leaderboard checking) below.
            if (_messageLogic.IsAskingForHelp(activity.Text))
            {
                return(await SendHelpMessage(activity, cancellationToken));
            }

            return(await SendMessage(Strings.DidNotUnderstand, activity, cancellationToken));
        }
Exemplo n.º 3
0
        public void TestSomeoneReceivedKarmaInWholeMessage(string message, bool expected)
        {
            var result = KarmaLogic.SomeoneReceivedKarmaInWholeMessage(message);

            Assert.Equal(result, expected);
        }