From e620e30c10d8fc7c0dbf0221991a2283ebf54b87 Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 8 Jul 2021 09:17:35 -0400 Subject: [PATCH] Fix channel checks missing GuildNews The log channel / logclean checks are left as-is; hopefully nobody is using an announcements channel for their logs? --- PluralKit.Bot/CommandSystem/ContextEntityArgumentsExt.cs | 2 +- PluralKit.Bot/Handlers/MessageEdited.cs | 2 +- PluralKit.Bot/Handlers/ReactionAdded.cs | 4 ++-- PluralKit.Bot/Proxy/ProxyService.cs | 2 +- PluralKit.Bot/Services/PeriodicStatCollector.cs | 2 +- PluralKit.Bot/Utils/DiscordUtils.cs | 3 +++ 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/CommandSystem/ContextEntityArgumentsExt.cs b/PluralKit.Bot/CommandSystem/ContextEntityArgumentsExt.cs index 9a88b4d5..2bd93da4 100644 --- a/PluralKit.Bot/CommandSystem/ContextEntityArgumentsExt.cs +++ b/PluralKit.Bot/CommandSystem/ContextEntityArgumentsExt.cs @@ -163,7 +163,7 @@ namespace PluralKit.Bot if (!ctx.Cache.TryGetChannel(id, out var channel)) return Task.FromResult(null); - if (!(channel.Type == Channel.ChannelType.GuildText || channel.Type == Channel.ChannelType.GuildNews)) + if (!DiscordUtils.IsValidGuildChannel(channel)) return Task.FromResult(null); ctx.PopArgument(); diff --git a/PluralKit.Bot/Handlers/MessageEdited.cs b/PluralKit.Bot/Handlers/MessageEdited.cs index 8a35df3a..22fe43f0 100644 --- a/PluralKit.Bot/Handlers/MessageEdited.cs +++ b/PluralKit.Bot/Handlers/MessageEdited.cs @@ -52,7 +52,7 @@ namespace PluralKit.Bot return; var channel = _cache.GetChannel(evt.ChannelId); - if (channel.Type != Channel.ChannelType.GuildText) + if (DiscordUtils.IsValidGuildChannel(channel)) return; var guild = _cache.GetGuild(channel.GuildId!.Value); var lastMessage = _lastMessageCache.GetLastMessage(evt.ChannelId); diff --git a/PluralKit.Bot/Handlers/ReactionAdded.cs b/PluralKit.Bot/Handlers/ReactionAdded.cs index 127b8e08..855238cf 100644 --- a/PluralKit.Bot/Handlers/ReactionAdded.cs +++ b/PluralKit.Bot/Handlers/ReactionAdded.cs @@ -66,8 +66,8 @@ namespace PluralKit.Bot } } - // Only proxies in guild text channels - if (channel.Type != Channel.ChannelType.GuildText) return; + // Proxied messages only exist in guild text channels, so skip checking if we're elsewhere + if (DiscordUtils.IsValidGuildChannel(channel)) return; // Ignore reactions from bots (we can't DM them anyway) if (user.Bot) return; diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 933b46cf..1548b1fa 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -91,7 +91,7 @@ namespace PluralKit.Bot if (ctx.SystemId == null) return false; // Make sure channel is a guild text channel and this is a normal message - if (channel.Type != Channel.ChannelType.GuildText && channel.Type != Channel.ChannelType.GuildNews) return false; + if (DiscordUtils.IsValidGuildChannel(channel)) return false; if (msg.Type != Message.MessageType.Default && msg.Type != Message.MessageType.Reply) return false; // Make sure author is a normal user diff --git a/PluralKit.Bot/Services/PeriodicStatCollector.cs b/PluralKit.Bot/Services/PeriodicStatCollector.cs index 032e5fed..cd9c96d5 100644 --- a/PluralKit.Bot/Services/PeriodicStatCollector.cs +++ b/PluralKit.Bot/Services/PeriodicStatCollector.cs @@ -54,7 +54,7 @@ namespace PluralKit.Bot guildCount++; foreach (var channel in _cache.GetGuildChannels(guild.Id)) { - if (channel.Type == Channel.ChannelType.GuildText) + if (DiscordUtils.IsValidGuildChannel(channel)) channelCount++; } } diff --git a/PluralKit.Bot/Utils/DiscordUtils.cs b/PluralKit.Bot/Utils/DiscordUtils.cs index bf49b42f..59f3711d 100644 --- a/PluralKit.Bot/Utils/DiscordUtils.cs +++ b/PluralKit.Bot/Utils/DiscordUtils.cs @@ -192,5 +192,8 @@ namespace PluralKit.Bot var neededPermissions = PermissionSet.AddReactions | PermissionSet.ReadMessageHistory; return ((ctx.BotPermissions & neededPermissions) == neededPermissions); } + + public static bool IsValidGuildChannel(Channel channel) => + channel.Type == Channel.ChannelType.GuildText || channel.Type == Channel.ChannelType.GuildNews; } }