public static async Task <bool> SendFeedUpdateAsync(TheGodfatherBot shard, RssSubscription sub, SyndicationItem latest) { DiscordChannel?chn; try { chn = await shard.Client.GetShard(sub.GuildId).GetChannelAsync(sub.ChannelId); } catch (NotFoundException) { return(false); } if (chn is null) { return(false); } var emb = new LocalizedEmbedBuilder(shard.Services.GetRequiredService <LocalizationService>(), sub.GuildId); emb.WithTitle(latest.Title.Text); emb.WithUrl(sub.Feed.LastPostUrl); emb.WithColor(DiscordColor.Gold); emb.WithLocalizedTimestamp(latest.LastUpdatedTime > latest.PublishDate ? latest.LastUpdatedTime : latest.PublishDate); if (latest.Content is TextSyndicationContent content) { string?imageUrl = RedditService.GetImageUrl(content); if (imageUrl is { })
private Task SearchAndSendResultsAsync(CommandContext ctx, string sub, RedditCategory category) { if (string.IsNullOrWhiteSpace(sub)) { throw new InvalidCommandUsageException(ctx, "cmd-err-sub-none"); } string?url = RedditService.GetFeedURLForSubreddit(sub, category, out string?rsub); if (url is null || rsub is null) { if (rsub is null) { throw new CommandFailedException(ctx, "cmd-err-sub-format"); } else { throw new CommandFailedException(ctx, "cmd-err-sub-404", rsub); } } IReadOnlyList <SyndicationItem>?res = RssFeedsService.GetFeedResults(url); if (res is null) { throw new CommandFailedException(ctx, "cmd-err-sub-fail", rsub); } if (!res.Any()) { return(ctx.FailAsync("cmd-err-res-none")); } return(ctx.PaginateAsync(res, (emb, r) => { emb.WithTitle(r.Title.Text); emb.WithDescription(r.Summary, unknown: false); emb.WithUrl(r.Links.First().Uri); if (r.Content is TextSyndicationContent content) { string?url = RedditService.GetImageUrl(content); if (url is { }) { emb.WithImageUrl(url); } }