コード例 #1
0
ファイル: GeneralModule.cs プロジェクト: SaeSyl/Sylph
        public async Task UrbanAsync(EventContext e)
        {
            if (string.IsNullOrEmpty(e.arguments))
            {
                return;
            }

            Locale               locale = Locale.GetEntity(e.Channel.Id.ToDbLong());
            UrbanDictionaryApi   api    = new UrbanDictionaryApi(Global.UrbanKey);
            UrbanDictionaryEntry entry  = api.GetEntry(e.arguments);

            if (entry != null)
            {
                IDiscordEmbed embed = Utils.Embed
                                      .SetAuthor(entry.Term,
                                                 "http://cdn9.staztic.com/app/a/291/291148/urban-dictionary-647813-l-140x140.png",
                                                 "http://www.urbandictionary.com/define.php?term=" + e.arguments)
                                      .SetDescription(locale.GetString("miki_module_general_urban_author", entry.Author));

                embed.AddInlineField(locale.GetString("miki_module_general_urban_definition"), entry.Definition);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_example"), entry.Example);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_rating"), "👍 " + entry.ThumbsUp + "  👎 " + entry.ThumbsDown);

                await embed.SendToChannel(e.Channel);
            }
            else
            {
                await Utils.ErrorEmbed(locale, "This term couldn't been found!")
                .SendToChannel(e.Channel.Id);
            }
        }
コード例 #2
0
ファイル: GeneralModule.cs プロジェクト: Auxiliatrix/Miki.Bot
        public async Task UrbanAsync(EventContext e)
        {
            if (string.IsNullOrEmpty(e.Arguments.ToString()))
            {
                return;
            }

            UrbanDictionaryApi   api   = new UrbanDictionaryApi(UrbanKey);
            UrbanDictionaryEntry entry = await api.GetEntryAsync(e.Arguments.ToString());

            if (entry != null)
            {
                await new EmbedBuilder()
                {
                    Author = new EmbedAuthor()
                    {
                        Name    = entry.Term,
                        IconUrl = "http://cdn9.staztic.com/app/a/291/291148/urban-dictionary-647813-l-140x140.png",
                        Url     = "http://www.urbandictionary.com/define.php?term=" + e.Arguments.ToString(),
                    },
                    Description = e.Locale.GetString("miki_module_general_urban_author", entry.Author)
                }.AddField(e.Locale.GetString("miki_module_general_urban_definition"), entry.Definition, true)
                .AddField(e.Locale.GetString("miki_module_general_urban_example"), entry.Example, true)
                .AddField(e.Locale.GetString("miki_module_general_urban_rating"), "👍 " + entry.ThumbsUp.ToFormattedString() + "  👎 " + entry.ThumbsDown.ToFormattedString(), true)
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
            else
            {
                await e.ErrorEmbed(e.Locale.GetString("error_term_invalid"))
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
        }
コード例 #3
0
        public async Task UrbanAsync(EventContext e)
        {
            if (string.IsNullOrEmpty(e.arguments))
            {
                return;
            }

            Locale               locale = new Locale(e.Channel.Id);
            UrbanDictionaryApi   api    = new UrbanDictionaryApi(Global.Config.UrbanKey);
            UrbanDictionaryEntry entry  = await api.GetEntryAsync(e.arguments);

            if (entry != null)
            {
                IDiscordEmbed embed = Utils.Embed
                                      .SetAuthor(entry.Term,
                                                 "http://cdn9.staztic.com/app/a/291/291148/urban-dictionary-647813-l-140x140.png",
                                                 "http://www.urbandictionary.com/define.php?term=" + e.arguments)
                                      .SetDescription(locale.GetString("miki_module_general_urban_author", entry.Author));

                embed.AddInlineField(locale.GetString("miki_module_general_urban_definition"), entry.Definition);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_example"), entry.Example);
                embed.AddInlineField(locale.GetString("miki_module_general_urban_rating"), "👍 " + entry.ThumbsUp + "  👎 " + entry.ThumbsDown);

                embed.QueueToChannel(e.Channel);
            }
            else
            {
                e.ErrorEmbed(e.GetResource("error_term_invalid"))
                .QueueToChannel(e.Channel.Id);
            }
        }
コード例 #4
0
        public async Task UrbanAsync(EventContext e)
        {
            if (!e.Arguments.Pack.CanTake)
            {
                return;
            }

            var api = (UrbanDictionaryAPI)e.Services.GetService(typeof(UrbanDictionaryAPI));

            var query        = e.Arguments.Pack.TakeAll();
            var searchResult = await api.SearchTermAsync(query);

            if (searchResult == null)
            {
                // TODO (Veld): Something went wrong/No results found.
                return;
            }

            UrbanDictionaryEntry entry = searchResult.Entries
                                         .FirstOrDefault();

            if (entry != null)
            {
                string desc = Regex.Replace(entry.Definition, "\\[(.*?)\\]",
                                            (x) => $"[{x.Groups[1].Value}]({api.GetUserDefinitionURL(x.Groups[1].Value)})"
                                            );

                string example = Regex.Replace(entry.Example, "\\[(.*?)\\]",
                                               (x) => $"[{x.Groups[1].Value}]({api.GetUserDefinitionURL(x.Groups[1].Value)})"
                                               );

                await new EmbedBuilder()
                {
                    Author = new EmbedAuthor()
                    {
                        Name = "📚 " + entry.Term,
                        Url  = "http://www.urbandictionary.com/define.php?term=" + query,
                    },
                    Description = e.Locale.GetString("miki_module_general_urban_author", entry.Author)
                }.AddField(e.Locale.GetString("miki_module_general_urban_definition"), desc, true)
                .AddField(e.Locale.GetString("miki_module_general_urban_example"), example, true)
                .AddField(e.Locale.GetString("miki_module_general_urban_rating"), "👍 " + entry.ThumbsUp.ToFormattedString() + "  👎 " + entry.ThumbsDown.ToFormattedString(), true)
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
            else
            {
                await e.ErrorEmbed(e.Locale.GetString("error_term_invalid"))
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
        }