From 546a287c28a7176f49aa9bd21f1786ce89d19fec Mon Sep 17 00:00:00 2001 From: Petal Ladenson Date: Tue, 13 Jan 2026 19:26:10 -0700 Subject: [PATCH] feat: add more options for when to make proxied messages silent --- PluralKit.Bot/CommandMeta/CommandHelp.cs | 2 +- PluralKit.Bot/Commands/ServerConfig.cs | 37 ++++++++++++++++--- PluralKit.Bot/Proxy/ProxyService.cs | 10 ++++- .../Database/Functions/MessageContext.cs | 2 +- PluralKit.Core/Models/GuildConfig.cs | 15 +++++++- PluralKit.Core/Models/Patch/GuildPatch.cs | 2 +- crates/migrate/data/functions.sql | 4 +- crates/migrate/data/migrations/54.sql | 11 ++++++ docs/content/command-list.md | 2 +- 9 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 crates/migrate/data/migrations/54.sql diff --git a/PluralKit.Bot/CommandMeta/CommandHelp.cs b/PluralKit.Bot/CommandMeta/CommandHelp.cs index 65fa79b6..a2ed4998 100644 --- a/PluralKit.Bot/CommandMeta/CommandHelp.cs +++ b/PluralKit.Bot/CommandMeta/CommandHelp.cs @@ -112,7 +112,7 @@ public partial class CommandTree public static Command ServerConfigLogClean = new Command("serverconfig log cleanup", "serverconfig log cleanup [on|off]", "Toggles whether to clean up other bots' log channels"); public static Command ServerConfigInvalidCommandResponse = new Command("serverconfig invalid command error", "serverconfig invalid command error [on|off]", "Sets whether to show an error message when an unknown command is sent"); public static Command ServerConfigRequireSystemTag = new Command("serverconfig require tag", "serverconfig require tag [on|off]", "Sets whether server users are required to have a system tag on proxied messages"); - public static Command ServerConfigSuppressNotifications = new Command("serverconfig suppress notifications", "serverconfig suppress notifications [on|off]", "Sets whether all proxied messages will have notifications suppressed (sent as `@silent` messages)"); + public static Command ServerConfigSuppressNotifications = new Command("serverconfig suppress notifications", "serverconfig suppress notifications [always|never|match|invert]", "Sets when proxied messages will have notifications suppressed (sent as `@silent` messages)"); public static Command Invite = new Command("invite", "invite", "Gets a link to invite PluralKit to other servers"); public static Command PermCheck = new Command("permcheck", "permcheck ", "Checks whether a server's permission setup is correct"); public static Command Admin = new Command("admin", "admin", "Super secret admin commands (sshhhh)"); diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index ef648438..171c76b2 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -49,9 +49,9 @@ public class ServerConfig items.Add(new( "suppress notifications", - "Whether all proxied messages will have notifications suppressed (sent as `@silent` messages)", - EnabledDisabled(ctx.GuildConfig!.SuppressNotifications), - "disabled" + "When proxied messages will have notifications suppressed (sent as `@silent` messages)", + ctx.GuildConfig!.SuppressNotifications.ToUserString(), + "never" )); items.Add(new( @@ -438,13 +438,38 @@ public class ServerConfig if (!ctx.HasNext()) { - var msg = $"Suppressing notifications for proxied messages is currently **{EnabledDisabled(ctx.GuildConfig!.SuppressNotifications)}**."; + var msg = $"Suppressing notifications for proxied messages is currently set to **{ctx.GuildConfig!.SuppressNotifications.ToUserString()}**. Proxied messages will "; + switch (ctx.GuildConfig!.SuppressNotifications) + { + case GuildConfig.SuppressCondition.Never: + msg += "never be marked as silent."; + break; + case GuildConfig.SuppressCondition.Always: + msg += "always be marked as silent."; + break; + case GuildConfig.SuppressCondition.Match: + msg += "be marked as silent if the trigger message was marked as silent."; + break; + case GuildConfig.SuppressCondition.Invert: + msg += "be marked as silent if the trigger message was **not** marked as silent."; + break; + } await ctx.Reply(msg); return; } - var newVal = ctx.MatchToggle(false); + var newVal = GuildConfig.SuppressCondition.Never; + if (ctx.Match("on", "always", "silent", "suppress")) + newVal = GuildConfig.SuppressCondition.Always; + else if (ctx.Match("match", "same", "inherit")) + newVal = GuildConfig.SuppressCondition.Match; + else if (ctx.Match("invert", "opposite")) + newVal = GuildConfig.SuppressCondition.Invert; + else if (!ctx.Match("off", "never", "disable", "disabled")) + { + throw new PKError("You must pass one of \"always\", \"never\", \"match\", or \"invert\" to this command."); + } await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { SuppressNotifications = newVal }); - await ctx.Reply($"Suppressing notifications for proxied messages is now {EnabledDisabled(newVal)}."); + await ctx.Reply($"Suppressing notifications for proxied messages is now set to {newVal.ToUserString()}."); } } \ No newline at end of file diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index ee6108af..d7e0c7d6 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -242,7 +242,15 @@ public class ProxyService var tts = match.Member.Tts && senderPermissions.HasFlag(PermissionSet.SendTtsMessages); Message.MessageFlags flags = 0; - if (ctx.SuppressNotifications) + // If the guild suppress notifications condition is set to Always + if (ctx.SuppressNotifications == GuildConfig.SuppressCondition.Always || + // OR if it is set to Match and the trigger message was silent + (ctx.SuppressNotifications == GuildConfig.SuppressCondition.Match && + trigger.Flags.HasFlag(Message.MessageFlags.SuppressNotifications)) || + // OR if it is set to Invert and the trigger message wasn't silent + (ctx.SuppressNotifications == GuildConfig.SuppressCondition.Invert && + !trigger.Flags.HasFlag(Message.MessageFlags.SuppressNotifications))) + // Make the proxied message silent flags |= Message.MessageFlags.SuppressNotifications; if (trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage)) flags |= Message.MessageFlags.VoiceMessage; diff --git a/PluralKit.Core/Database/Functions/MessageContext.cs b/PluralKit.Core/Database/Functions/MessageContext.cs index 78fa4cb3..b040b01f 100644 --- a/PluralKit.Core/Database/Functions/MessageContext.cs +++ b/PluralKit.Core/Database/Functions/MessageContext.cs @@ -37,5 +37,5 @@ public class MessageContext public bool LogCleanupEnabled { get; } public bool RequireSystemTag { get; } public bool DenyBotUsage { get; } - public bool SuppressNotifications { get; } + public GuildConfig.SuppressCondition SuppressNotifications { get; } } \ No newline at end of file diff --git a/PluralKit.Core/Models/GuildConfig.cs b/PluralKit.Core/Models/GuildConfig.cs index a71dee45..a15d58fe 100644 --- a/PluralKit.Core/Models/GuildConfig.cs +++ b/PluralKit.Core/Models/GuildConfig.cs @@ -9,5 +9,18 @@ public class GuildConfig public bool LogCleanupEnabled { get; } public bool InvalidCommandResponseEnabled { get; } public bool RequireSystemTag { get; } - public bool SuppressNotifications { get; } + public SuppressCondition SuppressNotifications { get; } + + public enum SuppressCondition + { + Never = 0, + Always = 1, + Match = 2, + Invert = 3, + } +} + +public static class GuildConfigExt +{ + public static string ToUserString(this GuildConfig.SuppressCondition val) => val.ToString().ToLower(); } \ No newline at end of file diff --git a/PluralKit.Core/Models/Patch/GuildPatch.cs b/PluralKit.Core/Models/Patch/GuildPatch.cs index ae75e835..70006e6a 100644 --- a/PluralKit.Core/Models/Patch/GuildPatch.cs +++ b/PluralKit.Core/Models/Patch/GuildPatch.cs @@ -10,7 +10,7 @@ public class GuildPatch: PatchObject public Partial LogCleanupEnabled { get; set; } public Partial InvalidCommandResponseEnabled { get; set; } public Partial RequireSystemTag { get; set; } - public Partial SuppressNotifications { get; set; } + public Partial SuppressNotifications { get; set; } public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper .With("log_channel", LogChannel) diff --git a/crates/migrate/data/functions.sql b/crates/migrate/data/functions.sql index 16be5519..0df86505 100644 --- a/crates/migrate/data/functions.sql +++ b/crates/migrate/data/functions.sql @@ -27,7 +27,7 @@ create function message_context(account_id bigint, guild_id bigint, channel_id b in_log_blacklist bool, log_cleanup_enabled bool, require_system_tag bool, - suppress_notifications bool, + suppress_notifications int, deny_bot_usage bool ) @@ -68,7 +68,7 @@ as $$ or (thread_id = any (servers.log_blacklist))) as in_log_blacklist, coalesce(servers.log_cleanup_enabled, false) as log_cleanup_enabled, coalesce(servers.require_system_tag, false) as require_system_tag, - coalesce(servers.suppress_notifications, false) as suppress_notifications, + coalesce(servers.suppress_notifications, 0) as suppress_notifications, -- abuse_logs table coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage diff --git a/crates/migrate/data/migrations/54.sql b/crates/migrate/data/migrations/54.sql new file mode 100644 index 00000000..2b668deb --- /dev/null +++ b/crates/migrate/data/migrations/54.sql @@ -0,0 +1,11 @@ +-- database version 54 +-- change suppress notifications server config to an enum + +alter table servers + alter column suppress_notifications drop default, + alter column suppress_notifications type int + using case when suppress_notifications then 1 else 0 end, + alter column suppress_notifications set default 0, + add constraint suppress_notifications_check check (suppress_notifications = ANY (ARRAY[0,1,2,3])); + +update info set schema_version = 54; \ No newline at end of file diff --git a/docs/content/command-list.md b/docs/content/command-list.md index 80abf707..62864be8 100644 --- a/docs/content/command-list.md +++ b/docs/content/command-list.md @@ -158,7 +158,7 @@ You can have a space after `pk;`, e.g. `pk;system` and `pk; system` will do the - `pk;serverconfig log cleanup [on|off]` - Toggles whether to clean up other bots' log channels - `pk;serverconfig invalid command error [on|off]` - Sets whether to show an error message when an unknown command is sent - `pk;serverconfig require tag [on|off]` - Sets whether server users are required to have a system tag on proxied messages -- `pk;serverconfig suppress notifications [on|off]` - Sets whether all proxied messages have push notifications suppressed (sent as `@silent` messages) +- `pk;serverconfig suppress notifications [always|never|match|invert]` - Sets when proxied messages have push notifications suppressed (sent as `@silent` messages) - `pk;serverconfig log channel ` - Designates a channel to post proxied messages to - `pk;serverconfig log channel -clear` - Clears the currently set log channel - `pk;serverconfig log blacklist`- Displays the current list of channels where logging is disabled