public async Task CNNUnsubscribe() { using (SubDBContext DBContext = DBFactory.Create <SubDBContext>()) { string channelId = Context.Channel.Id.ToString(); string userId = Context.User.Id.ToString(); var existingSub = DBContext.CNNSubscribers.FromSql("SELECT * FROM CNNSubscribers WHERE Id = {0} AND Subscriber = {1} LIMIT 1", Context.Channel.Id.ToString(), Context.User.Id.ToString()).AsNoTracking().FirstOrDefault(); if (existingSub == null) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("This channel is not subscribed to CNN or you weren't the subscriber."), lifeTime : Config.FeedbackMessageLifeTime); return; } DBContext.CNNSubscribers.Remove(existingSub); await DBContext.SaveChangesAsync(); CNNService.TextChannnels.Remove(Context.Channel as SocketTextChannel); await ReplyAsync("", embed : EmbedService.MakeSuccessFeedbackEmbed($"You have unsubscribed the channel {Context.Channel.Name.Bold()} from CNN breaking news!")); } }
public async Task RedditUnsubscribe([Summary("The desired subreddit")] string subreddit) { using (SubDBContext DBContext = DBFactory.Create <SubDBContext>()) { string channelId = Context.Channel.Id.ToString(); string userId = Context.User.Id.ToString(); var subExists = DBContext.RedditSubscribers.FromSql("SELECT * FROM RedditSubscribers WHERE Id = {0} AND Subscriber = {1} AND Subreddit = {2} LIMIT 1", Context.Channel.Id.ToString(), Context.User.Id.ToString(), subreddit).AsNoTracking().FirstOrDefault(); if (subExists == null) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("This channel is not subscribed to that subreddit or you weren't the subscriber."), lifeTime : Config.FeedbackMessageLifeTime); return; } DBContext.RedditSubscribers.Remove(subExists); await DBContext.SaveChangesAsync(); RedditService.RemoveRedditStream(Context.Channel as SocketTextChannel, Context.User as SocketGuildUser, subreddit); await ReplyAsync("", embed : EmbedService.MakeSuccessFeedbackEmbed($"You have unsubscribed the channel {Context.Channel.Name.Bold()} from the subreddit {subreddit.Bold()}!")); } }
public async Task CNNSubscribe() { using (SubDBContext DBContext = DBFactory.Create <SubDBContext>()) { string channelId = Context.Channel.Id.ToString(); string userId = Context.User.Id.ToString(); var subExists = (DBContext.CNNSubscribers.FromSql("SELECT * FROM CNNSubscribers WHERE Id = {0} AND Subscriber = {1} LIMIT 1", Context.Channel.Id.ToString(), Context.User.Id.ToString()).AsNoTracking().FirstOrDefault() != null); if (subExists) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("This channel is already subscribed to CNN."), lifeTime : Config.FeedbackMessageLifeTime); return; } var newUser = new CNNSubscriber(channelId, userId, DateTime.Now); await DBContext.CNNSubscribers.AddAsync(newUser); await DBContext.SaveChangesAsync(); CNNService.TextChannnels.Add(Context.Channel as SocketTextChannel); await ReplyAsync("", embed : EmbedService.MakeSuccessFeedbackEmbed($"You have subscribed the channel {Context.Channel.Name.Bold()} to CNN breaking news!")); } }
public async Task RedditSubscribe([Summary("The interval between each check, in minutes.")] int minutes, [Summary("The name of the subreddit.")] string subreddit) { if (minutes < 5) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("Your check interval cannot be shorter than five minutes."), lifeTime : Config.FeedbackMessageLifeTime); return; } if (minutes > 1440) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("Your check interval cannot be longer than a day."), lifeTime : Config.FeedbackMessageLifeTime); return; } using (SubDBContext DBContext = DBFactory.Create <SubDBContext>()) { string channelId = Context.Channel.Id.ToString(); string userId = Context.User.Id.ToString(); var subExists = (DBContext.RedditSubscribers.FromSql("SELECT * FROM RedditSubscribers WHERE Id = {0} AND Subscriber = {1} AND Subreddit = {2} LIMIT 1", Context.Channel.Id.ToString(), Context.User.Id.ToString(), subreddit).AsNoTracking().FirstOrDefault() != null); if (subExists) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed("This channel is already subscribed to the specified subreddit."), lifeTime : Config.FeedbackMessageLifeTime); return; } var newUser = new RedditSubscriber(channelId, userId, subreddit, "Text", minutes, DateTime.Now); await DBContext.RedditSubscribers.AddAsync(newUser); await DBContext.SaveChangesAsync(); RedditService.AddRedditStream(Context.Channel as SocketTextChannel, subreddit, minutes, Context.User.Id); await ReplyAsync("", embed : EmbedService.MakeSuccessFeedbackEmbed($"You have subscribed the channel {Context.Channel.Name.Bold()} to the subreddit {subreddit.Bold()}!")); } }