public async Task <string> GetScoreboard(Activity activity, Match match, CancellationToken cancellationToken)
        {
            var    topOrBottom = match.Groups[1].Value;
            string partition   = "defaultpartition";

            if (MessageLogic.ThingsSlopPhrases.Contains(match.Groups[3].Value))
            {
                partition = "msteams_entity";
            }
            else if (MessageLogic.UsersSlopPhrases.Contains(match.Groups[3].Value))
            {
                partition = "msteams_user";
            }

            ScoreboardModel response = await _db.ExecuteStoredProcedureAsync($"/{_db.GetCollectionUri()}/sprocs/scoreboard", partition, cancellationToken, (topOrBottom == "bottom").ToString().ToLower());

            var sb = new StringBuilder();

            foreach (KarmaModel karma in response.Feed)
            {
                sb.AppendFormat("{0}={1},\n\n ", karma.Entity, karma.Score);
            }

            return(sb.ToString().TrimEnd(',', ' '));
        }
Exemplo n.º 2
0
        public async Task Hello(IDialogContext context, LuisResult result)
        {
            //Microsoft.Bot.Builder.Dialogs.Internals.JObjectBotData data = GetInstanceField(typeof(Microsoft.Bot.Builder.Dialogs.Internals.DialogContext), context, "botData") as Microsoft.Bot.Builder.Dialogs.Internals.JObjectBotData;
            Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser data = GetInstanceField(typeof(Microsoft.Bot.Builder.Dialogs.Internals.DialogContext), context, "botToUser") as Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser;
            Microsoft.Bot.Connector.Activity originalMessage = GetInstanceField(typeof(Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser), data, "toBot") as Microsoft.Bot.Connector.Activity;



            string userName = originalMessage.From.Name;
            //context.PerUserInConversationData.SetValue<AlegeusUser>("auser", new AlegeusUser());
            string message = "Hello, " + userName + "!" + Greeting;

            try
            {
                //message += " Type=" + originalMessage.Type;
                //message += " From=" + originalMessage.From.ToString();
                //message += " Type=" + originalMessage.Type;
                //message += " From.ChannelId=" + originalMessage.From.ChannelId;
                //message += " From.IsBot=" + originalMessage.From.IsBot;
                //message += " From.Id=" + originalMessage.From.Id;
                //message += " From.Address=" + originalMessage.From.Address;
                //message += " From.Name=" + originalMessage.From.Name;
            }
            catch (Exception e)
            {
                message += " Exception:" + e.Message;
            }

            await context.PostAsync(message);

            //await context.PostAsync("test");
            context.Wait(MessageReceived);
        }
Exemplo n.º 3
0
        public string Execute(Intent intent, Activity activity)
        {
            var client    = new GitHubClient(new ProductHeaderValue("Jarvis"));
            var tokenAuth = new Credentials("98b3dfccfd7a5475dc042f41e9c8c30bd599db7c");

            client.Credentials = tokenAuth;
            var request    = new RepositoryIssueRequest();// { State = ItemStateFilter.Closed, Assignee = "timu" };
            var parameters = intent.Actions.First().Parameters;
            var userParam  = parameters.FirstOrDefault(x => x.Name == "user");
            var userName   = userParam?.ParameterValues?.FirstOrDefault(x => x.Type == "User")?.Entity;

            if (!string.IsNullOrWhiteSpace(userName))
            {
                request.Assignee = userName;
            }

            var statusParam = parameters.FirstOrDefault(x => x.Name == "status");
            var statusName  = statusParam?.ParameterValues?.FirstOrDefault(x => x.Type == "Status")?.Entity;

            if (!string.IsNullOrWhiteSpace(statusName))
            {
                request.State = (ItemStateFilter)Enum.Parse(typeof(ItemStateFilter), statusName, true);
            }

            var issues = client.Issue.GetAllForRepository("HackandCraft", "LeviathanApi",
                                                          request,
                                                          new ApiOptions()
            {
                PageSize = 10, PageCount = 1
            }).Result;

            if (issues.Count == 0)
            {
                return($"No issues found for {userName}");
            }

            var sb = new StringBuilder();

            foreach (var issue in issues)
            {
                sb.AppendLine($"{issue.HtmlUrl} - {issue.Title}<br/>");
            }

            return(sb.ToString());
        }
        private static Microsoft.Bot.Connector.Activity CreateLoginContinueActivity(Microsoft.Bot.Connector.Activity activity, string userName)
        {
            var reply       = activity.CreateReply($"{userName} is now logged in ... you can continue.");
            var cardActions = new List <Microsoft.Bot.Connector.CardAction>
            {
                new Microsoft.Bot.Connector.CardAction()
                {
                    Title = "Continue",
                    Type  = Microsoft.Bot.Connector.ActionTypes.ImBack,
                    Value = "Continue"
                }
            };

            reply.SuggestedActions = new Microsoft.Bot.Connector.SuggestedActions()
            {
                Actions = cardActions
            };
            return(reply);
        }
Exemplo n.º 5
0
        public Microsoft.Bot.Connector.Activity ToActivity(Microsoft.Bot.Connector.Activity origin)
        {
            var a = origin.CreateReply(text: String.Format("{0}: " + "{1}", this.Name, this.Message));

            if (this.Attachments != null)
            {
                foreach (var attachment in this.Attachments)
                {
                    if (a.Attachments == null)
                    {
                        a.Attachments = new List <Microsoft.Bot.Connector.Attachment>();
                    }
                    a.Attachments.Add(new Microsoft.Bot.Connector.Attachment()
                    {
                        ContentType = attachment.Type,
                        ContentUrl  = attachment.Url
                    });
                }
            }

            return(a);
        }
Exemplo n.º 6
0
 public string Execute(Intent intent, Activity activity)
 {
     return("Something  about " + activity.Conversation.Name);
 }
Exemplo n.º 7
0
        public async Task <IList <string> > GetKarmaResponseTextsAsync(Activity activity, CancellationToken cancellationToken)
        {
            List <string> responses = new List <string>();

            // Get Mentions
            var userMentions = Utilities.GetUserMentions(activity).ToList();

            // Strips stuff like '@' so '@msteams' and 'msteams' can have the same karma.
            Utilities.StripCharactersWeDontCareAbout(activity);

            // Remove the space before the karma score
            activity.Text = Regex.Replace(activity.Text, "[ ]([+-]{2,})", "$1");

            // Remove spaces in entity names
            foreach (var mention in userMentions)
            {
                var mentionName          = mention.Mentioned.Name;
                var spaceStrippedMention = mentionName.Replace(" ", "");
                activity.Text = activity.Text.Replace(mentionName, spaceStrippedMention);
            }

            var karmaChanges          = new List <KarmaChange>();
            var multiWordKarmaMatches = Regex.Matches(activity.Text, MultiWordKarmaRegexPattern, RegexOptions.RightToLeft);

            foreach (Match match in multiWordKarmaMatches)
            {
                var karmaStr  = match.Value;
                var cleanName = karmaStr.TrimEnd(' ', '+', '-').Trim('\"');
                karmaChanges.Add(new KarmaChange(karmaStr, cleanName, cleanName.ToLower()));
                // less frustrating to have "test karma" and "Test Karma" use the same karma.
                activity.Text = activity.Text.Replace(karmaStr, "");
            }

            // Get list of karma strings
            var separatedBySpaces = activity.Text.Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            // Add all the user karma strings
            foreach (var mention in userMentions)
            {
                string mentionName          = mention.Mentioned.Name;
                string spaceStrippedMention = mentionName.Replace(" ", "");
                string karmaString          = separatedBySpaces.FirstOrDefault(a => a.Contains(spaceStrippedMention));
                separatedBySpaces.Remove(karmaString);
                karmaChanges.Add(new KarmaChange(karmaString, mention.Mentioned.Name, mention.Mentioned.Id));
            }

            // Now add all the non-user karma strings
            foreach (var nonUserKarmaString in separatedBySpaces)
            {
                string cleanName = nonUserKarmaString.TrimEnd(' ', '+', '-').Trim('\"');
                karmaChanges.Add(new KarmaChange(nonUserKarmaString, cleanName, cleanName.ToLower()));
            }

            // Generate messages
            foreach (var karmaChange in karmaChanges.Distinct(new DuplicateKarmaComparer()))
            {
                // Process the alleged Karma instruction and add the response message
                if (KarmaLogic.IsKarmaString(karmaChange.KarmaString))
                {
                    var replyMessage = await _karmaLogic.GetReplyMessageForKarma(karmaChange.KarmaString, karmaChange.UniqueId, karmaChange.Name, cancellationToken);

                    if (string.IsNullOrEmpty(replyMessage))
                    {
                        return(null);
                    }

                    responses.Add(replyMessage);
                }
            }

            // Add space back... "AaronRosenberger" -> "Aaron Rosenberger"
            foreach (var mention in userMentions)
            {
                var mentionName          = mention.Mentioned.Name;
                var spaceStrippedMention = mentionName.Replace(" ", "");
                responses = responses.Select(a => a = a.Replace(spaceStrippedMention, mentionName)).ToList();
            }

            // Remove extra line breaks
            responses = responses.Select(Utilities.TrimWhitespace).ToList();

            return(responses);
        }
Exemplo n.º 8
0
        public virtual async Task <IActionResult> Post([FromBody] Microsoft.Bot.Connector.Activity activity)
        {
            await this._handler.QueueActivity(activity);

            return(Ok());
        }