public async Task <bool> AddSubscriptionAsync(ulong guildId, ulong channelId, SubscriptionType type) { using (var databaseContext = new DatabaseContext()) { var fixedChannelId = channelId.ToString(); if (await databaseContext.SubscribedChannels.AnyAsync(p => p.ChannelId == fixedChannelId && p.SubscriptionType == type)) { return(false); } var subscribedChannel = new SubscribedChannel { GuildId = guildId.ToString(), ChannelId = channelId.ToString(), SubscriptionType = type }; await databaseContext.SubscribedChannels.AddAsync(subscribedChannel); await databaseContext.SaveChangesAsync(); _logger.Info($"Subscription for {type} added (guild [{guildId}], channel [{channelId}])"); } return(true); }
public async Task SubscribeChannel(ulong channel, string guildId) { var ch = new SubscribedChannel { GuildId = guildId, channelId = channel.ToString(), Type = SubscribeType.Raid }; db.Create(ch); await Attach(ch); }
public async Task SubscribeAsync(bool atEveryone, [Remainder] string message) { SubscribedChannel channelToCheck = DailySubscription.subscribedChannels.Find(x => x.ChannelID.Contains(Context.Channel.Id.ToString())); if (channelToCheck.ChannelID != null) { DailySubscription.subscribedChannels.Remove(channelToCheck); } DailySubscription.Add(Context.Channel.Id.ToString(), atEveryone, message); Generic(Color.Green, "this channel is now subscribed to daily reminders!", $"Your reminder {WillWillNot(atEveryone)} @everyone", $"Your reminder reads: {message}"); }
public async Task UnSubscribeAsync() { SubscribedChannel channelToCheck = DailySubscription.subscribedChannels.Find(x => x.ChannelID.Contains(Context.Channel.Id.ToString())); if (channelToCheck.ChannelID != null) { DailySubscription.subscribedChannels.Remove(channelToCheck); Generic(Color.Blue, "you have been unsubscribed from daily reminders!", "Sad to see you go, but you can always subscribe again!"); } else { Generic(Color.Orange, "this channel is not subscribed!", $"Use the command {Config.bot.cmdPrefix}Subscribe to subscribe a channel"); } }
private async Task SendTweetsToChannel(SubscribedChannel channelData, List <DiscordEmbed> tweetEmbeds) { try { foreach (var embed in tweetEmbeds) { var channel = await Bot.Client.GetChannelAsync(ulong.Parse(channelData.ChannelId)); await channel.SendMessageAsync(embed : embed); } } catch (UnauthorizedException ex) { var guild = await Bot.Client.GetGuildAsync(ulong.Parse(channelData.GuildId)); var guildOwner = guild.Owner; _logger.Warn($"No permissions to send message on channel [{channelData.ChannelId}], " + $"removing all subscriptions and sending message to {guildOwner.Username} [{guildOwner.Id}]"); _logger.Warn($"JSON: {ex.JsonMessage}"); await _subscriptionsService.RemoveAllSubscriptionsFromChannelAsync( ulong.Parse(channelData.ChannelId)); var ownerDm = await guildOwner.CreateDmChannelAsync(); var errorEmbed = _twitterEmbedGenerator.BuildUnauthorizedError(); await ownerDm.SendMessageAsync(embed : errorEmbed); } catch (NotFoundException ex) { _logger.Warn($"Channel [{channelData.ChannelId}] not found, removing all subscriptions"); _logger.Warn($"JSON: {ex.JsonMessage}"); await _subscriptionsService.RemoveAllSubscriptionsFromChannelAsync( ulong.Parse(channelData.ChannelId)); } catch (Exception ex) { _logger.Error(ex, $"Can't send tweet on the channel with id [{channelData.ChannelId}]"); } }