Example #1
0
        public async Task FindMangaAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                return;
            }

            int page = 0;

            if (e.Arguments.LastOrDefault()?.TakeInt() != null)
            {
                page = e.Arguments.LastOrDefault().TakeInt().Value;
            }

            arg = arg.TakeUntilEnd((page != 0) ? 1 : 0);
            string searchQuery = arg.Argument;

            arg = arg.Next();

            ISearchResult <IMediaSearchResult> result = (await anilistClient.SearchMediaAsync(searchQuery, page, e.Channel.IsNsfw, MediaFormat.MUSIC, MediaFormat.ONA, MediaFormat.ONE_SHOT, MediaFormat.OVA, MediaFormat.SPECIAL, MediaFormat.TV, MediaFormat.TV_SHORT));

            if (result.Items.Count == 0)
            {
                if (page > result.PageInfo.TotalPages && page != 0)
                {
                    e.ErrorEmbed($"You've exceeded the total amount of pages available, might want to move back a bit!")
                    .ToEmbed().QueueToChannel(e.Channel);
                }
                else
                {
                    e.ErrorEmbed($"No characters listed containing `{e.Arguments.ToString()}`, try something else!")
                    .ToEmbed().QueueToChannel(e.Channel);
                }
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < result.Items.Count; i++)
            {
                sb.AppendLine($"`{result.Items[i].Id.ToString().PadRight(5)}:` {result.Items[i].DefaultTitle}");
            }

            new EmbedBuilder()
            .SetAuthor($"Search result for `{searchQuery}`", "https://anilist.co/img/logo_al.png", "")
            .SetDescription(sb.ToString())
            .SetColor(0, 170, 255)
            .SetFooter($"Page {result.PageInfo.CurrentPage} of {result.PageInfo.TotalPages} | Powered by anilist.co", "")
            .ToEmbed().QueueToChannel(e.Channel);
        }
Example #2
0
        public async Task FindMangas()
        {
            AnilistClient client = new AnilistClient();
            var           ch     = await client.SearchMediaAsync("miki", type : MediaType.MANGA);

            Assert.All(ch.Items, i => Assert.Equal(MediaType.MANGA, i.Type));
            Assert.NotNull(ch);
            Assert.NotEmpty(ch.Items);
        }
Example #3
0
        public async Task FindAnimesAndMangas()
        {
            AnilistClient client = new AnilistClient();
            var           ch     = await client.SearchMediaAsync("miki");

            Assert.True(ch.Items.Select(i => i.Type).Distinct().Count() == 2);
            Assert.NotNull(ch);
            Assert.NotEmpty(ch.Items);
        }
Example #4
0
        public async Task FindMangaAsync(EventContext e)
        {
            List <string> args = e.arguments.Split(' ').ToList();
            int           page = 0;

            if (int.TryParse(args.Last(), out int r))
            {
                args.RemoveAt(args.Count - 1);
                page = r;
            }

            string searchQuery = string.Join(' ', args);

            ISearchResult <IMediaSearchResult> result = (await anilistClient.SearchMediaAsync(searchQuery, page, e.Channel.Nsfw, MediaFormat.MUSIC, MediaFormat.ONA, MediaFormat.ONE_SHOT, MediaFormat.OVA, MediaFormat.SPECIAL, MediaFormat.TV, MediaFormat.TV_SHORT));

            if (result.Items.Count == 0)
            {
                if (page > result.PageInfo.TotalPages && page != 0)
                {
                    e.ErrorEmbed($"You've exceeded the total amount of pages available, might want to move back a bit!")
                    .QueueToChannel(e.Channel);
                }
                else
                {
                    e.ErrorEmbed($"No characters listed containing `{e.arguments}`, try something else!")
                    .QueueToChannel(e.Channel);
                }
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < result.Items.Count; i++)
            {
                sb.AppendLine($"`{result.Items[i].Id.ToString().PadRight(5)}:` {result.Items[i].DefaultTitle}");
            }

            Utils.Embed.SetAuthor($"Search result for `{searchQuery}`", "https://anilist.co/img/logo_al.png", "")
            .SetDescription(sb.ToString())
            .SetColor(0, 170, 255)
            .SetFooter($"Page {result.PageInfo.CurrentPage} of {result.PageInfo.TotalPages} | Powered by anilist.co", "")
            .QueueToChannel(e.Channel);
        }
Example #5
0
        public async Task FindAnimeAsync(IContext e)
        {
            if (!e.GetArgumentPack().Take(out string query))
            {
                return;
            }
            e.GetArgumentPack().Take(out int page);

            ISearchResult <IMediaSearchResult> result = (await anilistClient.SearchMediaAsync(query, page, e.GetChannel().IsNsfw, MediaType.ANIME, MediaFormat.MANGA, MediaFormat.NOVEL));

            if (!result.Items.Any())
            {
                if (page > result.PageInfo.TotalPages && page != 0)
                {
                    await e.ErrorEmbed("You've exceeded the total amount of pages available, might want to move back a bit!")
                    .ToEmbed().QueueAsync(e, e.GetChannel());
                }
                else
                {
                    await e.ErrorEmbed($"No characters listed containing `{e.GetArgumentPack().Pack.TakeAll()}`, try something else!")
                    .ToEmbed().QueueAsync(e, e.GetChannel());
                }
                return;
            }

            StringBuilder sb = new StringBuilder();

            foreach (var t in result.Items)
            {
                sb.AppendLine(
                    $"`{t.Id.ToString().PadRight(5)}:` {t.DefaultTitle}");
            }

            await new EmbedBuilder()
            .SetAuthor($"Search result for `{query}`", "https://anilist.co/img/logo_al.png", "")
            .SetDescription(sb.ToString())
            .SetColor(0, 170, 255)
            .SetFooter($"Page {result.PageInfo.CurrentPage} of {result.PageInfo.TotalPages} | Powered by anilist.co", "")
            .ToEmbed().QueueAsync(e, e.GetChannel());
        }
Example #6
0
        public async Task FindMangaAsync(CommandContext e)
        {
            if (!e.Arguments.Take(out string query))
            {
                return;
            }
            e.Arguments.Take(out int page);

            ISearchResult <IMediaSearchResult> result = (await anilistClient.SearchMediaAsync(query, page, e.Channel.IsNsfw, null, MediaFormat.MUSIC, MediaFormat.ONA, MediaFormat.ONE_SHOT, MediaFormat.OVA, MediaFormat.SPECIAL, MediaFormat.TV, MediaFormat.TV_SHORT));

            if (result.Items.Count == 0)
            {
                if (page > result.PageInfo.TotalPages && page != 0)
                {
                    await e.ErrorEmbed($"You've exceeded the total amount of pages available, might want to move back a bit!")
                    .ToEmbed().QueueToChannelAsync(e.Channel);
                }
                else
                {
                    await e.ErrorEmbed($"No characters listed containing `{e.Arguments.Pack.TakeAll()}`, try something else!")
                    .ToEmbed().QueueToChannelAsync(e.Channel);
                }
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < result.Items.Count; i++)
            {
                sb.AppendLine($"`{result.Items[i].Id.ToString().PadRight(5)}:` {result.Items[i].DefaultTitle}");
            }

            await new EmbedBuilder()
            .SetAuthor($"Search result for `{query}`", "https://anilist.co/img/logo_al.png", "")
            .SetDescription(sb.ToString())
            .SetColor(0, 170, 255)
            .SetFooter($"Page {result.PageInfo.CurrentPage} of {result.PageInfo.TotalPages} | Powered by anilist.co", "")
            .ToEmbed().QueueToChannelAsync(e.Channel);
        }
Example #7
0
        public async Task AnilistAsync([Remainder][Summary("Search query (use keyword `search:` to get multiple results)")] string query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query), "No input passed");
            }
            AnilistClient anilist = new AnilistClient();

            if (query.ToLower().StartsWith("search:"))
            {
                query = query.Replace("search:", "");
                var results = await anilist.SearchMediaAsync(query).ConfigureAwait(false);

                EmbedBuilder _eb = new EmbedBuilder
                {
                    Author = new EmbedAuthorBuilder
                    {
                        Name    = $"SEARCH",
                        IconUrl = "https://submission-manual.anilist.co/logo.png",
                    },
                    Title  = $"{results.Items.Count} results for {query}",
                    Color  = Discord.Color.Blue,
                    Footer = new EmbedFooterBuilder
                    {
                        Text = "Anilist for Ranka"
                    }
                };

                foreach (var item in results.Items)
                {
                    _eb.AddField(item.DefaultTitle, $"{item.Type} | [Link](https://anilist.co/{item.Type.ToString().ToLower()}/{item.Id})");
                }

                await RankaReplyAsync(_eb).ConfigureAwait(false);

                return;
            }

            var res = await anilist.GetMediaAsync(query).ConfigureAwait(false);

            var color = await StringUtils.DiscordParseColor(new Uri(res.CoverImage)).ConfigureAwait(false);

            EmbedBuilder eb = new EmbedBuilder
            {
                Author = new EmbedAuthorBuilder
                {
                    Name    = $"{res.Type}",
                    IconUrl = "https://submission-manual.anilist.co/logo.png",
                },
                Title        = res.DefaultTitle,
                Description  = res.Description,
                Color        = color,
                Url          = res.Url,
                ThumbnailUrl = res.CoverImage,
                Footer       = new EmbedFooterBuilder
                {
                    Text = "Anilist for Ranka"
                }
            };

            var score = res.Score.HasValue ? $"{res.Score.Value}/100" : "N/A";

            eb.AddField("Japanese Title", res.NativeTitle, true);
            eb.AddField("Transcripted Title", res.RomajiTitle, true);
            eb.AddField("Score", score, true);
            eb.AddField("Genres", string.Join(", ", res.Genres));
            if (res.Episodes.HasValue)
            {
                eb.AddField("Episodes", res.Episodes.Value, true);
            }
            if (res.Chapters.HasValue)
            {
                eb.AddField("Chapters", res.Chapters.Value, true);
            }
            if (res.Volumes.HasValue)
            {
                eb.AddField("Volumes", res.Volumes.Value, true);
            }
            eb.AddField("Status", res.Status, true);

            await RankaReplyAsync(eb).ConfigureAwait(false);
        }
Example #8
0
        static async Task AnimeAction(IEnumerable <string> args, Dictionary <string, string> @params)
        {
            List <MediaFormat> formats = new List <MediaFormat>();

            foreach (var f in Enum.GetNames(typeof(MediaFormat)))
            {
                if (@params.ContainsKey($"--{f.ToLower().Replace('_', '-')}"))
                {
                    formats.Add(Enum.Parse <MediaFormat>(f));
                }
            }

            bool nsfw = @params.ContainsKey("-nsfw");

            if (args.Count() == 0)
            {
                return;
            }

            switch (args.ElementAtOrDefault(0) ?? "")
            {
            case "search":
            {
                int page = 0;
                @params.TryGetValue("-p", out string pageCount);
                int.TryParse(pageCount, out page);

                var searchResult = await client.SearchMediaAsync(string.Join(" ", args.Skip(1).Take(args.Count() - 1)), page, nsfw, formats.ToArray());

                if (searchResult == null)
                {
                    Console.WriteLine("Nothing was found here!");
                    return;
                }

                for (int i = 0; i < searchResult.Items.Count; i++)
                {
                    Console.WriteLine($"{searchResult.Items[i].Id.ToString().PadLeft(6)}: {searchResult.Items[i].DefaultTitle}");
                }
                Console.WriteLine("----------");
                Console.WriteLine($"Page {searchResult.PageInfo.CurrentPage} of {searchResult.PageInfo.TotalPages}");
            } break;

            default:
            {
                var media = await client.GetMediaAsync(string.Join(" ", args), formats.ToArray());

                if (media == null)
                {
                    Console.WriteLine("response was empty, most likely this media does not exist!");
                    return;
                }

                Console.WriteLine($"{media.EnglishTitle} ({media.NativeTitle})");
                Console.WriteLine($"Parts: {media.Episodes ?? media.Volumes ?? 0} | Status: {media.Status}");
                Console.WriteLine($"Score: {media.Score} | {string.Join(", ", media.Genres)}");
                Console.WriteLine($"{media.Description}");
            }
            break;
            }
        }
 protected override Task <ISearchResult <IMediaSearchResult> > SearchPage(AnilistClient client, string search, int index)
 {
     return(client.SearchMediaAsync(search, index, false, filter: _formats));
 }