Ejemplo n.º 1
0
        public static async Task <List <AnimeDataModel> > GetAnime(string input, int loop = 10)
        {
            try
            {
                var reply = await Anime.GetAnimeAsync(input);

                var list = new List <AnimeDataModel>();
                if (reply.Data.Count > loop)
                {
                    for (int i = 0; i < loop; i++)
                    {
                        list.Add(reply.Data[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < reply.Data.Count; i++)
                    {
                        list.Add(reply.Data[i]);
                    }
                }
                return(list);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public async Task AnimeAsync([Remainder, Name("anime_name")] string args)
        {
            try
            {
                await Context.Channel.TriggerTypingAsync();

                var res = await Anime.GetAnimeAsync(args);

                var anime = res.Data[0];

                var embed = new EmbedBuilder
                {
                    Color        = new Color(33, 176, 252),
                    Title        = anime.Attributes.CanonicalTitle ?? anime.Attributes.Titles.JaJp,
                    ThumbnailUrl = anime.Attributes.PosterImage.Medium,
                    Description  = anime.Attributes.Synopsis ?? "-"
                }.Build();

                await ReplyAsync("", embed : embed);
            }
            catch (Exception e)
            {
                var embed = new EmbedBuilder
                {
                    Color       = new Color(0xFF0000),
                    Description = e.Message
                }.Build();
                await ReplyAsync("", embed : embed);

                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task GetAnime([Remainder] string animetitle)
        {
            using var Database = new SkuldDbContextFactory().CreateDbContext();

            var usr = await Database
                      .InsertOrGetUserAsync(Context.User)
                      .ConfigureAwait(false);

            var loc = Locale.GetLocale(
                usr.Language ?? Locale.DefaultLocale
                );

            var raw = await Anime
                      .GetAnimeAsync(animetitle)
                      .ConfigureAwait(false);

            var data = raw.Data;

            if (data.Count > 1) // do pagination
            {
                var pages = data.PaginateList(25);

                IUserMessage sentmessage = await ReplyAsync(null, false,
                                                            EmbedExtensions
                                                            .FromMessage(
                                                                loc.GetString("SKULD_SEARCH_MKSLCTN") + " 30s",
                                                                pages[0],
                                                                Context
                                                                )
                                                            .WithColor(Color.Purple)
                                                            .Build()
                                                            ).ConfigureAwait(false);

                var response = await NextMessageAsync(
                    true,
                    true,
                    TimeSpan.FromSeconds(30)
                    ).ConfigureAwait(false);

                if (response is null)
                {
                    await sentmessage.DeleteAsync().ConfigureAwait(false);

                    return;
                }

                var selection = Convert.ToInt32(response.Content);

                var anime = data[selection - 1];

                await anime
                .ToEmbed(loc)
                .QueueMessageAsync(Context)
                .ConfigureAwait(false);
            }
            else
            {
                var anime = data[0];

                await anime
                .ToEmbed(loc)
                .QueueMessageAsync(Context)
                .ConfigureAwait(false);
            }
        }
Ejemplo n.º 4
0
        public async Task AnimeGet(CommandContext ctx, [RemainingText] string search)
        {
            try
            {
                var ine = ctx.Client.GetInteractivity();
                var a   = await Anime.GetAnimeAsync(search);

                var emb = new DiscordEmbedBuilder();
                List <DiscordEmbedBuilder> res = new();
                List <Page> ress = new();
                foreach (var aa in a.Data)
                {
                    emb.WithColor(new DiscordColor(0212255));
                    emb.WithTitle(aa.Attributes.Titles.EnJp);
                    if (aa.Attributes.Synopsis.Length != 0)
                    {
                        emb.WithDescription(aa.Attributes.Synopsis);
                    }
                    if (aa.Attributes.Subtype.Length != 0)
                    {
                        emb.AddField("Type", $"{aa.Attributes.Subtype}", true);
                    }
                    if (aa.Attributes.EpisodeCount != null)
                    {
                        emb.AddField("Episodes", $"{aa.Attributes.EpisodeCount}", true);
                    }
                    if (aa.Attributes.EpisodeLength != null)
                    {
                        emb.AddField("Length", $"{aa.Attributes.EpisodeLength}", true);
                    }
                    if (aa.Attributes.StartDate != null)
                    {
                        emb.AddField("Start Date", $"{aa.Attributes.StartDate}", true);
                    }
                    if (aa.Attributes.EndDate != null)
                    {
                        emb.AddField("End Date", $"{aa.Attributes.EndDate}", true);
                    }
                    if (aa.Attributes.AgeRating != null)
                    {
                        emb.AddField("Age Rating", $"{aa.Attributes.AgeRating}", true);
                    }
                    if (aa.Attributes.AverageRating != null)
                    {
                        emb.AddField("Score", $"{aa.Attributes.AverageRating}", true);
                    }
                    emb.AddField("NSFW", $"{aa.Attributes.Nsfw}", true);
                    if (aa.Attributes.CoverImage?.Small != null)
                    {
                        emb.WithThumbnail(aa.Attributes.CoverImage.Small);
                    }
                    res.Add(emb);
                    emb = new DiscordEmbedBuilder();
                }
                res.Sort((x, y) => x.Title.CompareTo(y.Title));
                int i = 1;
                foreach (var aa in res)
                {
                    aa.WithFooter($"via Kitsu.io -- Page {i}/{a.Data.Count}", "https://kitsu.io/kitsu-256-ed442f7567271af715884ca3080e8240.png");
                    ress.Add(new Page(embed: aa));
                    i++;
                }
                await ine.SendPaginatedMessageAsync(ctx.Channel, ctx.User, ress, PaginationBehaviour.WrapAround, ButtonPaginationBehavior.Disable);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                var ee = new DiscordEmbedBuilder();
                ee.WithTitle("Error");
                ee.WithDescription(ex.Message + "\n" + ex.StackTrace);
                await ctx.RespondAsync("No Anime Found!", embed : ee.Build());
            }
        }
Ejemplo n.º 5
0
        public async Task KitsuAnimeAsync([Remainder] string animeSearch)
        {
            EmbedBuilder kitsuAnime = new EmbedBuilder();

            var episodeCount = "";
            var rating       = "";

            try
            {
                var animes = await Anime.GetAnimeAsync(animeSearch);

                foreach (var ani in animes.Data)
                {
                    if (ani.Attributes.Titles.EnJp != "")
                    {
                        if (ani.Attributes.EpisodeCount == null)
                        {
                            episodeCount = "Unknown";
                        }

                        else
                        {
                            episodeCount = ani.Attributes.EpisodeCount.ToString();
                        }

                        if (ani.Attributes.AverageRating == null)
                        {
                            rating = "Unknown";
                        }

                        else
                        {
                            rating = ani.Attributes.AverageRating;
                        }

                        string animeStatus = char.ToUpper(ani.Attributes.Status.First()) + ani.Attributes.Status.Substring(1);

                        string animeType = char.ToUpper(ani.Attributes.Subtype.First()) + ani.Attributes.Subtype.Substring(1);

                        kitsuAnime
                        .WithTitle(ani.Attributes.Titles.EnJp)
                        .WithUrl("https://kitsu.io/anime/" + ani.Attributes.Slug)
                        .WithThumbnailUrl(ani.Attributes.PosterImage.Original)
                        .AddInlineField("Status:", animeStatus)
                        .AddInlineField("Episodes:", episodeCount)
                        .AddInlineField("Score:", rating)
                        .AddInlineField("Type:", animeType)
                        .WithDescription($"{ani.Attributes.Synopsis}")
                        .WithFooter("Kitsu.io", "https://pbs.twimg.com/profile_images/807964865511862278/pIYOVdsl_400x400.jpg");

                        await ReplyAsync("", false, kitsuAnime.Build());

                        break;
                    }
                }
            }
            catch (NoDataFoundException e)
            {
                await ReplyAsync(e.Message);
            }
        }