示例#1
0
        public void Setup(IRobot robot)
        {
            robot.AddResponder(@"bing\s+(me\s+)?(?<query>.*)", (session, message, room, match) =>
            {
                Task.Factory.StartNew(() =>
                {
                    var query = match.ValueFor("query");

                    var result = _bingClient.WebSearch(query);

                    var resultMatch = Regex.Match(result, @"<div class=""sb_tlst""><h3><a href=""(?<result>[^""]*)");

                    string resultMessage;
                    if (resultMatch.Success)
                    {
                        resultMessage = string.Format("@{0} {1}", session.Message.User.Name, resultMatch.ValueFor("result"));
                    }
                    else
                    {
                        resultMessage = string.Format("@{0} Sorry, Bing had zero results for '{1}'", session.Message.User.Name, query);
                    }

                    robot.SendMessage(room, resultMessage);
                });
            });
        }
示例#2
0
        public void Setup(IRobot robot)
        {
            robot.AddResponder(@"github status$", (session, message, room, match) =>
            {
                robot.SendMessage(room, "GitHub {0}", Status());
            });

            robot.AddResponder(@"github status last$", (session, message, room, match) =>
            {
                robot.SendMessage(room, "GitHub {0}", LastStatus());
            });

            robot.AddResponder(@"github status messages$", (session, message, room, match) =>
            {
                robot.SendMessage(room, string.Join("\n\n", StatusMessages()));
            });
        }
示例#3
0
        public void Setup(IRobot robot)
        {
            robot.AddResponder(@"push\s+(?<project>.*)\s+from\s+(?<from>.*)\s+to\s+(?<to>.*)", (session, message, room, match) =>
            {
                var project = match.ValueFor("project");
                var from = match.ValueFor("from");
                var to = match.ValueFor("to");

                robot.SendMessage(room, "{0} was just pushed from ({1}) to ({2}) successfully.", project, from, to);
            });

            robot.AddResponder(@"push-alias\s+(?<from>.*)\s+is\s+(?<to>.*)", (session, message, room, match) =>
            {
                var from = match.ValueFor("from");
                var to = match.ValueFor("to");

                robot.SendMessage(room, "({0}) is now an alis for ({1})", from, to);
            });

            robot.AddResponder(@"push-alias\s+list", (session, message, room, match) =>
            {
                robot.SendMessage(room, "@{0} listing all user aliases", session.Message.User.Name);
            });
        }
示例#4
0
        public void Setup(IRobot robot)
        {
            robot.AddResponder(@"(calc|calculate|convert|math)( me)? (?<query>.*)", (session, message, room, match) =>
            {
                Task.Factory.StartNew(() =>
                {
                    var query = match.ValueFor("query");

                    var restClient = new RestClient(@"https://www.google.com/ig/calculator");

                    var request = new RestRequest(Method.GET);
                    request.AddParameter("hl", "en");
                    request.AddParameter("q", query);

                    var response = restClient.Execute(request);

                    var result = JObject.Parse(response.Content).Value<string>("rhs");

                    var solution = string.IsNullOrWhiteSpace(result) ? "Could not compute." : result;

                    robot.SendMessage(room, "@{0} {1}", session.Message.User.Name, solution);
                });
            });
        }