From f897ce5a45fa8a5493fac73249a5584320d120ab Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 29 Oct 2021 17:34:28 -0400 Subject: [PATCH] fix: re-enable error messages for explicit commands --- PluralKit.Bot/Bot.cs | 16 ++++++---------- PluralKit.Bot/Handlers/MessageCreated.cs | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index 1881b185..a6e65958 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -253,16 +253,12 @@ namespace PluralKit.Bot // Once we've sent it to Sentry, report it to the user (if we have permission to) var reportChannel = handler.ErrorChannelFor(evt); - if (reportChannel != null) - { - var botPerms = PermissionsIn(reportChannel.Value); - if (botPerms.HasFlag(PermissionSet.SendMessages | PermissionSet.EmbedLinks)) - { - // i'm just going to disable this for now we need to find something nicer - // await _errorMessageService.SendErrorMessage(reportChannel.Value, - // sentryEvent.EventId.ToString()); - } - } + if (reportChannel == null) + return; + + var botPerms = PermissionsIn(reportChannel.Value); + if (botPerms.HasFlag(PermissionSet.SendMessages | PermissionSet.EmbedLinks)) + await _errorMessageService.SendErrorMessage(reportChannel.Value, sentryEvent.EventId.ToString()); } } diff --git a/PluralKit.Bot/Handlers/MessageCreated.cs b/PluralKit.Bot/Handlers/MessageCreated.cs index 7f1115a9..d4be0744 100644 --- a/PluralKit.Bot/Handlers/MessageCreated.cs +++ b/PluralKit.Bot/Handlers/MessageCreated.cs @@ -19,6 +19,7 @@ namespace PluralKit.Bot public class MessageCreated: IEventHandler { private readonly Bot _bot; + private readonly Cluster _cluster; private readonly CommandTree _tree; private readonly IDiscordCache _cache; private readonly LastMessageCacheService _lastMessageCache; @@ -31,9 +32,9 @@ namespace PluralKit.Bot private readonly BotConfig _config; private readonly DiscordApiClient _rest; - public MessageCreated(LastMessageCacheService lastMessageCache, LoggerCleanService loggerClean, - IMetrics metrics, ProxyService proxy, - CommandTree tree, ILifetimeScope services, IDatabase db, BotConfig config, ModelRepository repo, IDiscordCache cache, Bot bot, DiscordApiClient rest) + public MessageCreated(LastMessageCacheService lastMessageCache, LoggerCleanService loggerClean, IMetrics metrics, ProxyService proxy, + CommandTree tree, ILifetimeScope services, IDatabase db, BotConfig config, ModelRepository repo, IDiscordCache cache, + Bot bot, Cluster cluster, DiscordApiClient rest) { _lastMessageCache = lastMessageCache; _loggerClean = loggerClean; @@ -46,10 +47,18 @@ namespace PluralKit.Bot _repo = repo; _cache = cache; _bot = bot; + _cluster = cluster; _rest = rest; } - public ulong? ErrorChannelFor(MessageCreateEvent evt) => evt.ChannelId; + // for now, only return error messages for explicit commands + public ulong? ErrorChannelFor(MessageCreateEvent evt) + { + if (!HasCommandPrefix(evt.Content, _cluster.User?.Id ?? default, out var cmdStart) || cmdStart == evt.Content.Length) + return null; + + return evt.ChannelId; + } private bool IsDuplicateMessage(Message msg) => // We consider a message duplicate if it has the same ID as the previous message that hit the gateway