public async Task RedditAsync(CommandContext ctx, [Description("Subreddit.")] string sub) { string url = RedditService.GetFeedUrlForSubreddit(sub, RedditCategory.New, out string rsub); if (url is null) { throw new CommandFailedException("That subreddit doesn't exist."); } await this.Database.SubscribeAsync(ctx.Guild.Id, ctx.Channel.Id, url, rsub); await this.InformAsync(ctx, $"Subscribed to {Formatter.Bold(rsub)}", important : false); }
public async Task RedditAsync(CommandContext ctx, [Description("Subreddit.")] string sub) { if (RedditService.GetFeedUrlForSubreddit(sub, RedditCategory.New, out string rsub) is null) { throw new CommandFailedException("That subreddit doesn't exist."); } using (var dc = this.Database.CreateContext()) { dc.RssSubscriptions.RemoveRange(dc.RssSubscriptions.Where(s => s.GuildId == ctx.Guild.Id && s.ChannelId == ctx.Channel.Id && s.Name == rsub)); await dc.SaveChangesAsync(); } await this.InformAsync(ctx, $"Unsubscribed from {Formatter.Bold(rsub)}", important : false); }
private async Task SearchAndSendResultsAsync(CommandContext ctx, string sub, RedditCategory category) { string url = RedditService.GetFeedUrlForSubreddit(sub, category, out string rsub); if (url is null) { throw new CommandFailedException("That subreddit doesn't exist."); } var res = RssService.GetFeedResults(url); if (res is null) { throw new CommandFailedException($"Failed to get the data from that subreddit ({Formatter.Bold(rsub)})."); } await RssService.SendFeedResultsAsync(ctx.Channel, res); }