From e133bd657d441142834c58ec3e6ed8c5890668c6 Mon Sep 17 00:00:00 2001 From: Ske Date: Fri, 1 May 2020 16:36:21 +0200 Subject: [PATCH] Remove log channels if they don't exist --- PluralKit.Bot/Services/LogChannelService.cs | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Services/LogChannelService.cs b/PluralKit.Bot/Services/LogChannelService.cs index 3eaa0136..82c30e29 100644 --- a/PluralKit.Bot/Services/LogChannelService.cs +++ b/PluralKit.Bot/Services/LogChannelService.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using DSharpPlus; using DSharpPlus.Entities; +using DSharpPlus.Exceptions; using PluralKit.Core; @@ -30,8 +31,20 @@ namespace PluralKit.Bot { if (guildCfg.Value.LogBlacklist.Contains(originalChannel.Id)) return; // Bail if we can't find the channel - var channel = await client.GetChannelAsync(guildCfg.Value.LogChannel.Value); - if (channel == null || channel.Type != ChannelType.Text) return; + DiscordChannel channel; + try + { + channel = await client.GetChannelAsync(guildCfg.Value.LogChannel.Value); + } + catch (NotFoundException) + { + // If it doesn't exist, remove it from the DB + await RemoveLogChannel(guildCfg.Value); + return; + } + + // Bail if it's not a text channel + if (channel.Type != ChannelType.Text) return; // Bail if we don't have permission to send stuff here var neededPermissions = Permissions.SendMessages | Permissions.EmbedLinks; @@ -44,5 +57,11 @@ namespace PluralKit.Bot { await channel.SendMessageAsync(content: url, embed: embed); } + + private async Task RemoveLogChannel(GuildConfig cfg) + { + cfg.LogChannel = null; + await _data.SaveGuildConfig(cfg); + } } } \ No newline at end of file