当前位置: 首页>>代码示例>>C#>>正文


C# Robot.Respond方法代码示例

本文整理汇总了C#中Robot.Respond方法的典型用法代码示例。如果您正苦于以下问题:C# Robot.Respond方法的具体用法?C# Robot.Respond怎么用?C# Robot.Respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Robot的用法示例。


在下文中一共展示了Robot.Respond方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(cat|cats)( gif)( \d+)?$", async msg =>
            {
                int number = 1;
                try
                {
                    number = Int32.Parse(msg.Match[3]);
                }
                catch (Exception) { }
                if (number == 0)
                {
                    number = 1;
                }

                await CatMeGifCore(msg, number);
            });
            
            robot.Respond(@"(cat|cats)( me)?( \d+)?$", async msg =>
            {
                int number = 1;
                try
                {
                    number = Int32.Parse(msg.Match[3]);
                }
                catch (Exception) { }
                if (number == 0)
                {
                    number = 1;
                }

                await CatMeCore(msg, number);
            });
        }
开发者ID:holytshirt,项目名称:mmbot,代码行数:34,代码来源:Cats.cs

示例2: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"spot me winning", msg =>
            {
                msg.Send("http://open.spotify.com/track/77NNZQSqzLNqh2A9JhLRkg");
                msg.Message.Done = true;
            });

            robot.Respond(@"spot me (.*)$", async msg =>
            {
                var q = msg.Match[1];
                var res = await msg.Http("http://ws.spotify.com/search/1/track.json")
                    .Query(new {q})
                    .GetJson();

                foreach(var t in res.tracks)
                {
                    try
                    {
                        if (t.album.availability.territories.ToString() == "worldwide" || t.album.availability.territories.ToString().IndexOf("NZ") > -1)
                        {
                            msg.Send(string.Format("http://open.spotify.com/track/{0}",
                                t.href.ToString().Replace("spotify:track:", string.Empty)));
                            msg.Message.Done = true;
                            return;
                        }
                    }
                    catch (Exception)
                    {

                    }
                }
            });
        }
开发者ID:nardin,项目名称:mmbot,代码行数:34,代码来源:Spot.cs

示例3: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"PING$",msg => msg.Send("PONG"));

            robot.Respond(@"ECHO (.*)$", msg => msg.Send(msg.Match[1]));

            robot.Respond(@"TIME$", msg => msg.Send(string.Format("Server time is: {0} {1}", DateTime.Now.ToString("U"), TimeZoneInfo.Local.DisplayName)));

            robot.Respond(@"DIE$", msg => Environment.Exit(0));

            robot.Respond(@"RESPAWN$", msg => robot.Reset());
        }
开发者ID:nardin,项目名称:mmbot,代码行数:12,代码来源:Ping.cs

示例4: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"what ?is ([^\?]*)[\?]*", async msg =>
            {
                string query = msg.Match[1];

                var res =
                    await msg.Http(string.Format("http://api.urbandictionary.com/v0/define?term={0}", query)).GetJson();
                if (res.list.Count == 0)
                {
                    await msg.Send("I don't know what \"" + query + "\" is");
                    return;
                }

                var entry = res.list[0];
                await msg.Send((string)entry.definition);

                //var sounds = res.sounds;
                //if (sounds != null && sounds.Count != 0)
                //{
                //    await msg.Send(string.Join(" ", ((JArray) sounds).Select(s => s.ToString())));
                //}
            });


            robot.Respond(@"(urban)( define)?( example)?( me)? (.*)", async msg =>
            {
                string query = msg.Match[5];

                var res =
                    await msg.Http(string.Format("http://api.urbandictionary.com/v0/define?term={0}", query)).GetJson();
                if (res.list.Count == 0)
                {
                    await msg.Send("\"" + query + "\" not found");
                    return;
                }
                var entry = res.list[0];
                if (!string.IsNullOrWhiteSpace(msg.Match[3]))
                {
                    await msg.Send((string)entry.example);
                }
                else
                {
                    await msg.Send((string)entry.definition);
                }
                //var sounds = res.sounds;
                //if (sounds != null && sounds.Count != 0)
                //{
                //    await msg.Send(string.Join(" ", ((JArray)sounds).Select(s => s.ToString())));
                //}
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:52,代码来源:Urban.cs

示例5: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(calc|calculate|calculator|convert|math|maths)( me)? (.*)", async msg =>
            {
                dynamic res = await msg
                    .Http("https://www.google.com/ig/calculator")
                    .Query(new
                        {
                            hl = "en",
                            q = msg.Match[3]
                        })
                    .Headers(new Dictionary<string, string>
                        {
                            {"Accept-Language", "en-us,en;q=0.5"},
                            {"Accept-Charset", "utf-8"},
                            {"User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}
                        })
                    .GetJson();

                try
                {
                    await msg.Send((string)res.rhs ?? "Could not compute");
                    return;
                }
                catch (Exception)
                { }
                await msg.Send("Could not compute");
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:29,代码来源:Math.cs

示例6: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"help\s*(.*)?$", msg =>
            {
                IEnumerable<string> help = robot.HelpCommands;

                var filter = msg.Match[1];

                if (!string.IsNullOrWhiteSpace(filter))
                {
                    help = help.Where(h => h.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) > -1).ToArray();
                    if (!help.Any())
                    {
                        msg.Send(string.Format("No available commands match {0}", filter));
                    }
                }

                var alias = robot.Alias ?? robot.Name;

                help = help.Select(h => NameReplacementRegex.Replace(h, alias));

                msg.Send(string.Join(Environment.NewLine, help.OrderBy(h => h)));
                msg.Message.Done = true;
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:25,代码来源:Help.cs

示例7: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(youtube|yt)( me)? (.*)", async msg =>
            {
                var query = msg.Match[3];
                var res = await msg.Http("http://gdata.youtube.com/feeds/api/videos")
                    .Query(new Dictionary<string, string>
                    {
                        {"orderBy", "relevance"},
                        {"max-results", "15"},
                        {"alt", "json"},
                        {"q", query}
                    })
                    .GetJson();

                var videos = res.feed.entry;

                if (videos == null)
                {
                    await msg.Send(string.Format("No video results for \"{0}\"", query));
                    return;
                }

                dynamic video = msg.Random(videos);
                foreach (var link in video.link)
                {
                    if ((string) link.rel == "alternate" || (string) link.type == "text/html")
                    {
                        await msg.Send((string) link.href);
                    }
                }
            });
        }
开发者ID:holytshirt,项目名称:mmbot,代码行数:33,代码来源:Youtube.cs

示例8: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(ascii)( me)? (.*)", async msg =>
            {
                var query = msg.Match[3];

                await AsciiMeCore(msg, query);
            });
        }
开发者ID:nardin,项目名称:mmbot,代码行数:9,代码来源:Ascii.cs

示例9: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(what are )?the (three |3 )?(rules|laws)", msg =>
            {
                var rules = msg.Message != null && msg.Message.Text != null && (msg.Message.Text.ToLower().Contains("apple") || msg.Message.Text.ToLower().Contains("dev"))
                    ? _otherRules
                    : _rules;

                msg.Send(string.Join(Environment.NewLine, rules));
            });
        }
开发者ID:nardin,项目名称:mmbot,代码行数:11,代码来源:Rules.cs

示例10: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"xkcd(\s+latest)?$", async msg =>
            {
                var res = await msg.Http("http://xkcd.com/info.0.json").Get();
                if (res.StatusCode == HttpStatusCode.NotFound)
                {
                    await msg.Send("Comic not found");
                    return;
                }

                var body = await res.Json();
                await msg.Send((string)body.title, (string)body.img, (string)body.alt);
            });


            robot.Respond(@"xkcd\s+(\d+)", async msg =>
            {
                var num = msg.Match[1];

                await FetchComic(msg, num);
            });

            robot.Respond(@"xkcd\s+random", async msg =>
            {
                var res = await msg.Http("http://xkcd.com/info.0.json").Get();
                if (res.StatusCode == HttpStatusCode.NotFound)
                {
                    await msg.Send("Comic not found");
                    return;
                }

                var body = await res.Json();
                var max = int.Parse((string) body.num);
                var num = _random.Next(max);
                await FetchComic(msg, num.ToString());
            });

            
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:40,代码来源:Xkcd.cs

示例11: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"(image|img)( me)? (.*)", msg => ImageMe(msg, msg.Match[3], url => msg.Send(url)));

            robot.Respond(@"animate( me)? (.*)", msg => ImageMe(msg, msg.Match[2], url => msg.Send(url), true));

            robot.Respond(@"(?:mo?u)?sta(?:s|c)he?(?: me)? (.*)", async msg =>
            {
                var type = _random.Next(2);
                var mustachify = string.Format("http://mustachify.me/{0}?src=", type);
                var imagery = msg.Match[1];
                if (_httpRegex.IsMatch(imagery))
                {
                    await msg.Send(mustachify + imagery);
                }
                else
                {
                    await ImageMe(msg, imagery, url => msg.Send(mustachify + url), false, true);
                }
                
            });
        }
开发者ID:holytshirt,项目名称:mmbot,代码行数:22,代码来源:GoogleImages.cs

示例12: Register

        public void Register(Robot robot)
        {
            var apiKey = GetApiKey(robot);

            

            robot.Respond(@"(gif|giphy)( me)? (.*)", async msg =>
            {
                var query = msg.Match[3];

                await GifMeCore(msg, query, apiKey);
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:13,代码来源:Giphy.cs

示例13: Register

        public void Register(Robot robot)
        {
            var languageChoices = string.Join("|", _languages.Select(kvp => kvp.Value));
            var regex = string.Format("translate(?: me)?" +
                        "(?: from ({0}))?" +
                        "(?: (?:in)?to ({0}))?" +
                        "(.*)", languageChoices);

            robot.Respond(regex, async msg =>
            {
                var term = "\"" + msg.Match[3].Trim() + "\"";
                var origin = GetCode(msg.Match[1]) ?? "auto";
                var target = GetCode(msg.Match[2]) ?? "en";

                var res = await msg.Http("https://translate.google.com/translate_a/t")
                    .Query(new
                    {
                        client = "t",
                        hl = "en",
                        multires = 1,
                        sc = 1,
                        sl = origin,
                        ssel = 0,
                        tl = target,
                        tsel = 0,
                        uptl = "en",
                        text = term
                    })
                    .Headers(new Dictionary<string, string> {{"User-Agent", "Mozilla/5.0"}})
                    .GetJson();

                var language = _languages[(string) res[2]];
                string result;
                try
                {
                    result = res[0][0][0];
                }
                catch (Exception)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(msg.Match[2]))
                {
                    await msg.Send(string.Format("{0} is {1} for {2}", term, language, result.Trim()));
                }
                else
                {
                    await msg.Send(string.Format("The {1} {0} translates as {2} in {3}", term, language, result.Trim(), _languages[target]));
                }
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:51,代码来源:Translate.cs

示例14: Register

        public void Register(Robot robot)
        {
            robot.Respond(@"pug me", async msg =>
            {
                var res = await msg.Http("http://pugme.herokuapp.com/random").GetJson();
                await msg.Send((string)res.pug);
            });

            robot.Respond(@"pug bomb( (\d+))?", async msg =>
            {
                var count = msg.Match.Count() > 2 ? msg.Match[2] : "5";
                var res = await msg.Http("http://pugme.herokuapp.com/bomb?count=" + count).GetJson();
                foreach(var pug in res.pugs)
                {
                    await msg.Send((string)pug);
                }
            });

            robot.Respond(@"how many pugs are there", async msg =>
            {
                var res = await msg.Http("http://pugme.herokuapp.com/count").GetJson();
                await msg.Send(string.Format("There are {0} pugs.", res.pug_count));
            });
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:24,代码来源:Pug.cs

示例15: Register

        public void Register(Robot robot)
        {
            Brain = robot.Brain;

            robot.Respond(command, msg =>
            {
                var adapter = new MmbotResponseAdapter(msg);
                try
                {
                    CurrentUser = msg.Message.User;
                    Execute(msg.Match.Select(CleanupLinkFormattedMatches).ToArray(), adapter)
                         .Wait();
                }
                catch (Exception ex)
                {
                    adapter.Send(ex.ToString());
                    throw;
                }
            });
        }
开发者ID:adamralph,项目名称:PBot,代码行数:20,代码来源:BotCommand.cs


注:本文中的Robot.Respond方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。