public async Task UnsubscribeAsync(CommandContext ctx, [Description("Channel URL or subscription name.")] string name_url) { if (string.IsNullOrWhiteSpace(name_url)) { throw new InvalidCommandUsageException("Channel URL missing."); } using (DatabaseContext db = this.Database.CreateContext()) { db.RssSubscriptions.RemoveRange(db.RssSubscriptions.Where(s => s.GuildId == ctx.Guild.Id && s.ChannelId == ctx.Channel.Id && s.Name == name_url)); await db.SaveChangesAsync(); } string chid = await ctx.Services.GetService <YtService>().ExtractChannelIdAsync(name_url); if (!(chid is null)) { string feedurl = YtService.GetRssUrlForChannel(chid); using (DatabaseContext db = this.Database.CreateContext()) { DatabaseRssSubscription sub = db.RssSubscriptions .SingleOrDefault(s => s.ChannelId == ctx.Channel.Id && s.DbRssFeed.Url == feedurl); if (!(sub is null)) { db.RssSubscriptions.Remove(sub); await db.SaveChangesAsync(); } } } await this.InformAsync(ctx, "Unsubscribed!", important : false); }
public async Task ExecuteGroupAsync(CommandContext ctx, [RemainingText, Description("Name of the subscription.")] string name) { using (DatabaseContext db = this.Database.CreateContext()) { DatabaseRssSubscription sub = db.RssSubscriptions.SingleOrDefault(s => s.GuildId == ctx.Guild.Id && s.ChannelId == ctx.Channel.Id && s.Name == name); if (sub == null) { throw new CommandFailedException("Not subscribed to a feed with that name!"); } db.RssSubscriptions.Remove(sub); await db.SaveChangesAsync(); } await this.InformAsync(ctx, $"Unsubscribed from feed with name {Formatter.Bold(name)}", important : false); }