public async Task RemoveSubredditFromQueue(ulong channelId, string subredditName) { var subreddit = await _subRedditFactory.GetSubRedditByName(subredditName); if (subreddit is null) { return; } _queueManagerService.RemoveSubredditFromQueue(channelId, subreddit.Id); }
public async Task Subscribe(ulong channelId, string subRedditName, Sort sort) { var subReddit = await _subRedditFactory.GetSubRedditByName(subRedditName); if (!(_discord.GetChannel(channelId) is ITextChannel textChannel)) { return; } //Validation if (subReddit is null) { await textChannel.SendMessageAsync("The requested subreddit doesn't exist"); return; } if (subReddit.IsNsfw && !textChannel.IsNsfw) { await textChannel.SendMessageAsync("You can only subscribe to this subreddit in nsfw channels."); } await _channelFactory.AddIfNotExisting(channelId); var subscription = await _subscriptionAppService.AddIfNotExisting(subReddit.Id, sort); if (await IsAlreadySubscribed(subscription.Id, channelId)) { await textChannel.SendMessageAsync("This channel is already subscribed to the subreddit"); return; } await _subscriptionMapperAppService.Insert(new ChannelSubscriptionMapper(channelId, subscription.Id)); await textChannel.SendMessageAsync("Successfully subscribed"); }
public async Task <string> UnSubscribe(ulong guildId, string subredditName) { var subreddit = await _subRedditFactory.GetSubRedditByName(subredditName); if (subreddit is null) { return("subreddit doesn't exist"); } var historiesTask = _subRedditHistoryAppService.GetAll(); var histories = await historiesTask.ToListAsync(); var history = histories.FirstOrDefault(x => x.SubRedditId == subreddit.Id && x.GuildId == guildId); if (history is null) { return("No history found"); } await _subRedditHistoryAppService.Delete(histories.FirstOrDefault(x => x.SubRedditId == subreddit.Id && x.GuildId == guildId)); return("Successfully cleared the history"); }