private async Task ChannelDestroyed(SocketChannel channel) { SocketGuildChannel guildChannel = (SocketGuildChannel)channel; if (guildChannel != null) { _guildSettingsTracker.RemoveAllFiltersForGuildChannel(guildChannel.Guild.Id, channel.Id); } await _guildSettingsTracker.FlushSettingsAsync(); }
private async Task CommandViewActiveFilters(IMessageChannel channel) { StringBuilder stringBuilder = new StringBuilder(); ulong guildId = ((SocketGuildChannel)channel).Guild.Id; List <GuildSettingsTracker.SettingsToTrack.ChannelMessageCombo> activeFilters = _settingsTracker.GetActiveFiltersForGuild(guildId); if (activeFilters == null || activeFilters.Count <= 0) { stringBuilder.Append("You currently have no filters active."); } else if (activeFilters.Count >= 1) { if (activeFilters.Count == 1) { stringBuilder.Append("You only have **one** filter active:\n"); } else { stringBuilder.Append("These are your active filters:\n"); } SocketGuild guild = _routerBot.Client.GetGuild(guildId); List <ulong> oldChannelIds = new List <ulong>(); foreach (var filter in activeFilters) { // Text channel can be null if we loaded from previously saved settings, and the channel added has been deleted. SocketTextChannel textChannel = guild.GetTextChannel(filter._channelId); if (textChannel != null) { stringBuilder.Append(" - Reroute messages containing *" + filter._messageToTrack + "* to channel *" + textChannel.Name + "*.\n"); } else { oldChannelIds.Add(filter._channelId); stringBuilder.Append(" - **Warning:** The message filter \"*" + filter._messageToTrack + "*\" targets an old channel, and was **removed**!\n"); } } if (oldChannelIds.Count > 0) { foreach (ulong channelId in oldChannelIds) { _settingsTracker.RemoveAllFiltersForGuildChannel(guildId, channelId); } Task flushTask = _settingsTracker.FlushSettingsAsync().ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted); } } Task msgTask = channel.SendMessageAsync(stringBuilder.ToString()).ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted); }