public override async Task InvokeAsync(CommandContext ctx, string[] args) { if (args.Length < 1) { await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this)); return; } string animeName = String.Join(' ', args); if (animeName.Length < 4) { await ctx.ReplyAsync("Please have your search query be more than four characters long."); return; } var client = new MalClient(ctx.Bot.Configuration.MALUsername, ctx.Bot.Configuration.MALPassword); MALAnimeEntry entry; try { entry = await client.FirstAnimeAsync(animeName); } catch (HttpRequestException e) { Console.WriteLine(e.ToString()); await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later."); return; } if (entry == null) { await ctx.ReplyAsync("No results were found for your query."); return; } string desc = Util.BBCodeToMarkdown(HttpUtility.HtmlDecode(Regex.Replace(entry.Synopsis, @"<(?:[^>=]|='[^']*'|=""[^""]*""|=[^'""][^\s>]*)*>", ""))); EmbedBuilder embed = new EmbedBuilder { Color = Util.CyanColor, Title = entry.Title, Description = desc.Length > 2000 ? desc.Substring(0, 1996) + "..." : desc, ThumbnailUrl = entry.Image }; embed.AddField("Rating", entry.Score); embed.AddField("Episodes", entry.Episodes == 0 ? "Unknown" : entry.Episodes.ToString()); embed.AddField("Type", entry.Type); embed.AddField("Status", entry.Status); embed.AddField("Started Airing", entry.StartDate == "0000-00-00" ? "N/A" : entry.StartDate); embed.AddField("Ended Airing", entry.EndDate == "0000-00-00" ? "N/A" : entry.EndDate); embed.WithFooter("https://myanimelist.net", "https://i.imgur.com/DcMFqr6.jpg"); await ctx.ReplyAsync(embed.Build()); }
public override async Task InvokeAsync(CommandContext ctx, string[] args) { if (args.Length < 1) { await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this)); return; } string animeName = String.Join(' ', args); if (animeName.Length < 4) { await ctx.ReplyAsync("Please have your search query be more than four characters long."); return; } MalClient m = new MalClient(ctx.Bot.Configuration.MALUsername, ctx.Bot.Configuration.MALPassword); MALAnimeEntry anime = await m.FirstAnimeAsync(animeName); if (anime == null) { await ctx.ReplyAsync("We couldn't find that anime in the MAL database. Try an alternate name."); return; } var client = new TwistClient(ctx.DbContext); TwistEntry entry = await client.GetEntryAsync(anime.Id) ?? await client.GetEntryAsync(anime.Title); EmbedBuilder embed; if (entry == null) { embed = new EmbedBuilder { Title = "Anime Not Found", Color = Util.CyanColor, ThumbnailUrl = anime.Image, Description = $"*{anime.Title}* wasn't found on twist.moe. Some possible alternate sources are listed below for your convenience." }; embed.AddField("Alternate Sources", $"[Nyaa](https://nyaa.pantsu.cat/search?c=_&userID=0&q={WebUtility.UrlEncode(anime.Title)})\n[KissAnime](http://kissanime.ru/Search/Anime?keyword={WebUtility.UrlEncode(anime.Title)})"); await ctx.ReplyAsync(embed.Build()); return; } string desc = Util.BBCodeToMarkdown(HttpUtility.HtmlDecode(Regex.Replace(anime.Synopsis, @"<(?:[^>=]|='[^']*'|=""[^""]*""|=[^'""][^\s>]*)*>", ""))); embed = new EmbedBuilder { Title = entry.Url, Url = entry.Url, ThumbnailUrl = anime.Image, Color = Util.CyanColor, Description = $"A stream was located for *{anime.Title}* on twist.moe. Click the link above to continue.\n\n[MAL Entry](https://myanimelist.net/anime/{anime.Id}/)" }; embed.AddField("Description", desc.Length > 1024 ? desc.Substring(0, 1021) + "..." : desc); embed.WithFooter("https://twist.moe", "https://twist.moe/public/icons/fav_x16.png"); await ctx.ReplyAsync(embed.Build()); }