コード例 #1
0
        public async Task randomPastebin()
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.GoogleShortener);
            if (!(Context.Channel as ITextChannel).IsNsfw)
            {
                await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id));
            }
            else
            {
                Tuple <string, string> result = null;
                try
                {
                    result = await getUrl();
                }
                catch (GoogleApiException ex)
                {
                    if (ex.HttpStatusCode == HttpStatusCode.Forbidden)
                    {
                        await ReplyAsync(Sentences.tooManyRequests(Context.Guild.Id, "goo.gl"));

                        return;
                    }
                }
                if (result == null)
                {
                    await ReplyAsync(Sentences.nothingAfterXIterations(Context.Guild.Id, 500));
                }
                else
                {
                    await ReplyAsync("I found something, here is the short URL: " + result.Item1 + Environment.NewLine
                                     + ((result != null) ? ("It'll lead you here: " + result.Item2) : ("It will lead you nowhere since the URL was disabled...")));
                }
            }
        }
コード例 #2
0
        public async Task malManga(params string[] mangaNameArr) // Stuck in loop ?
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);
            string mangaName = Program.addArgs(mangaNameArr);

            if (mangaName.Length == 0)
            {
                await ReplyAsync(Sentences.animeHelp(Context.Guild.Id));

                return;
            }
            try
            {
                string result = p.malClient.DownloadString("https://myanimelist.net/api/manga/search.xml?q=" + mangaName.Replace(" ", "%20"));
                if (!result.Contains("<entry>"))
                {
                    await ReplyAsync(Sentences.mangaNotFound(Context.Guild.Id));
                }
                else
                {
                    EmbedBuilder b = parseContent(result, mangaName, (Context.Channel as ITextChannel).IsNsfw);
                    if (b == null)
                    {
                        await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id));
                    }
                    else
                    {
                        await ReplyAsync("", false, b.Build());
                    }
                }
            }
            catch (WebException ex)
            {
                HttpWebResponse code = ex.Response as HttpWebResponse;
                if (code.StatusCode == HttpStatusCode.Forbidden)
                {
                    await ReplyAsync(Sentences.tooManyRequests(Context.Guild.Id, "MyAnimeList"));
                }
            }
        }
コード例 #3
0
        public async Task mal(params string[] animeNameArr)
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);
            string animeName = Program.addArgs(animeNameArr);

            if (animeName.Length == 0)
            {
                await ReplyAsync(Sentences.animeHelp(Context.Guild.Id));

                return;
            }
            try
            {
                string result = p.malClient.DownloadString("https://myanimelist.net/api/anime/search.xml?q=" + animeName.Replace(" ", "%20"));
                if (!result.Contains("<entry>"))
                {
                    await ReplyAsync(Sentences.animeNotFound(Context.Guild.Id));
                }
                else
                {
                    EmbedBuilder b = parseContent(result, animeName, (Context.Channel as ITextChannel).IsNsfw);
                    await ReplyAsync("", false, b.Build());
                }
            }
            catch (WebException ex)
            {
                HttpWebResponse code = ex.Response as HttpWebResponse;
                if (code != null)
                {
                    if (code.StatusCode == HttpStatusCode.Forbidden)
                    {
                        await ReplyAsync(Sentences.tooManyRequests(Context.Guild.Id, "MyAnimeList"));
                    }
                }
                else
                {
                    await ReplyAsync("An unexpected error occured: " + ex.Message);
                }
            }
        }