private ABooru GetClientFromSite(BooruSite site) { return(site switch { BooruSite.Rule34 => _r34, BooruSite.Danbooru => _danbooru, BooruSite.Gelbooru => _gelbooru, BooruSite.Safebooru => _safebooru, BooruSite.SankakuComplex => _sankakuComplex, _ => throw new NotImplementedException(), });
private async Task GetRandomImage(CommandContext ctx, BooruSite site, string tags, DiscordColor?color = null) { await ctx.TriggerTypingAsync(); var booru = ctx.Client.GetBooru(); // get string site name string siteName = booru.GetSiteName(site); // prepare embed builder var eb = new DiscordEmbedBuilder() .WithTitle($"Image from {siteName} with tags `{tags}`: "); // add color and author info if (color.HasValue) { eb.WithColor(color.Value); } if (ctx.Member != null) { eb.WithAuthorFooter(ctx.Member, "Requested by: "); // `Member` is null in DM channels } // fetch image var response = await booru.GetRandomImage(site, tags); // don't continue if no image was found if (!response.HasValue) { eb.WithDescription("No image found"); await ctx.RespondAsync(embed : eb.Build()); return; } var img = response.Value; // build response embed eb .AddField("URL", img.fileUrl.AbsoluteUri) .AddField("Tags", JoinTags(img.tags)) .WithImageUrl(img.fileUrl.AbsoluteUri); // add optional fields if (img.score.HasValue) { eb.AddField("Likes", img.score.Value.ToString(), true); } if (img.creation.HasValue) { eb.AddField("Upload date (D.M.Y)", img.creation.Value.ToString("dd.MM.yyyy"), true); } await ctx.RespondAsync(embed : eb).ConfigureAwait(false); }