diff --git a/Myriad/Types/Message.cs b/Myriad/Types/Message.cs index 70013ecc..1b8f723e 100644 --- a/Myriad/Types/Message.cs +++ b/Myriad/Types/Message.cs @@ -15,6 +15,7 @@ public record Message SourceMessageDeleted = 1 << 3, Urgent = 1 << 4, Ephemeral = 1 << 6, + SuppressNotifications = 1 << 12, VoiceMessage = 1 << 13, } diff --git a/PluralKit.Bot/CommandMeta/CommandHelp.cs b/PluralKit.Bot/CommandMeta/CommandHelp.cs index 157b7edb..a0e17710 100644 --- a/PluralKit.Bot/CommandMeta/CommandHelp.cs +++ b/PluralKit.Bot/CommandMeta/CommandHelp.cs @@ -112,6 +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 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)"); @@ -157,6 +158,7 @@ public partial class CommandTree public static Command[] ServerConfigCommands = { ServerConfigLogClean, ServerConfigInvalidCommandResponse, ServerConfigRequireSystemTag, + ServerConfigSuppressNotifications, LogChannel, LogChannelClear, LogShow, LogDisable, LogEnable, BlacklistShow, BlacklistAdd, BlacklistRemove }; diff --git a/PluralKit.Bot/CommandMeta/CommandTree.cs b/PluralKit.Bot/CommandMeta/CommandTree.cs index 51f8f449..23715dc2 100644 --- a/PluralKit.Bot/CommandMeta/CommandTree.cs +++ b/PluralKit.Bot/CommandMeta/CommandTree.cs @@ -614,6 +614,8 @@ public partial class CommandTree return ctx.Execute(null, m => m.InvalidCommandResponse(ctx)); if (ctx.MatchMultiple(new[] { "require", "enforce" }, new[] { "tag", "systemtag" }) || ctx.Match("requiretag", "enforcetag")) return ctx.Execute(null, m => m.RequireSystemTag(ctx)); + if (ctx.MatchMultiple(new[] { "suppress" }, new[] { "notifications" }) || ctx.Match("proxyping", "proxynotif")) + return ctx.Execute(null, m => m.SuppressNotifications(ctx)); if (ctx.MatchMultiple(new[] { "log" }, new[] { "channel" })) return ctx.Execute(null, m => m.SetLogChannel(ctx)); if (ctx.MatchMultiple(new[] { "log" }, new[] { "blacklist" })) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index 922adcf7..34c13290 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -49,6 +49,13 @@ public class ServerConfig "disabled" )); + items.Add(new( + "suppress notifications", + "Whether all proxied messages will have notifications suppressed (sent as `@silent` messages)", + EnabledDisabled(ctx.GuildConfig!.SuppressNotifications), + "disabled" + )); + items.Add(new( "log channel", "Channel to log proxied messages to", @@ -426,4 +433,20 @@ public class ServerConfig await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { RequireSystemTag = newVal }); await ctx.Reply($"System tags are now **{(newVal ? "required" : "not required")}** for PluralKit users in this server."); } + + public async Task SuppressNotifications(Context ctx) + { + await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server"); + + if (!ctx.HasNext()) + { + var msg = $"Suppressing notifications for proxied messages is currently **{EnabledDisabled(ctx.GuildConfig!.SuppressNotifications)}**."; + await ctx.Reply(msg); + return; + } + + var newVal = ctx.MatchToggle(false); + await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { SuppressNotifications = newVal }); + await ctx.Reply($"Suppressing notifications for proxied messages is now {EnabledDisabled(newVal)}."); + } } \ No newline at end of file diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index f7ce4073..1183c05b 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -232,6 +232,12 @@ public class ProxyService var senderPermissions = PermissionExtensions.PermissionsFor(guild, messageChannel, trigger.Author.Id, guildMember); var tts = match.Member.Tts && senderPermissions.HasFlag(PermissionSet.SendTtsMessages); + Message.MessageFlags flags = 0; + if (ctx.SuppressNotifications) + flags |= Message.MessageFlags.SuppressNotifications; + if (trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage)) + flags |= Message.MessageFlags.VoiceMessage; + var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest { GuildId = trigger.GuildId!.Value, @@ -246,7 +252,7 @@ public class ProxyService Embeds = embeds.ToArray(), Stickers = trigger.StickerItems, AllowEveryone = allowEveryone, - Flags = trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage) ? Message.MessageFlags.VoiceMessage : null, + Flags = flags, Tts = tts, Poll = trigger.Poll, }); diff --git a/PluralKit.Core/Database/Functions/MessageContext.cs b/PluralKit.Core/Database/Functions/MessageContext.cs index 7c0fdbdc..78fa4cb3 100644 --- a/PluralKit.Core/Database/Functions/MessageContext.cs +++ b/PluralKit.Core/Database/Functions/MessageContext.cs @@ -36,6 +36,6 @@ public class MessageContext public bool InLogBlacklist { get; } public bool LogCleanupEnabled { get; } public bool RequireSystemTag { get; } - public bool DenyBotUsage { get; } + public bool SuppressNotifications { get; } } \ No newline at end of file diff --git a/PluralKit.Core/Database/Functions/functions.sql b/PluralKit.Core/Database/Functions/functions.sql index 895d064d..16be5519 100644 --- a/PluralKit.Core/Database/Functions/functions.sql +++ b/PluralKit.Core/Database/Functions/functions.sql @@ -27,6 +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, deny_bot_usage bool ) @@ -67,6 +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, -- abuse_logs table coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage diff --git a/PluralKit.Core/Database/Migrations/51.sql b/PluralKit.Core/Database/Migrations/51.sql new file mode 100644 index 00000000..881494fa --- /dev/null +++ b/PluralKit.Core/Database/Migrations/51.sql @@ -0,0 +1,7 @@ +-- database version 51 +-- +-- add guild setting for SUPPRESS_NOTIFICATIONS message flag on proxied messages + +alter table servers add column suppress_notifications bool not null default false; + +update info set schema_version = 51; \ No newline at end of file diff --git a/PluralKit.Core/Database/Utils/DatabaseMigrator.cs b/PluralKit.Core/Database/Utils/DatabaseMigrator.cs index 6db95ae5..11c6e2a9 100644 --- a/PluralKit.Core/Database/Utils/DatabaseMigrator.cs +++ b/PluralKit.Core/Database/Utils/DatabaseMigrator.cs @@ -9,7 +9,7 @@ namespace PluralKit.Core; internal class DatabaseMigrator { private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files - private const int TargetSchemaVersion = 50; + private const int TargetSchemaVersion = 51; private readonly ILogger _logger; public DatabaseMigrator(ILogger logger) diff --git a/PluralKit.Core/Models/GuildConfig.cs b/PluralKit.Core/Models/GuildConfig.cs index 7e6b7501..a71dee45 100644 --- a/PluralKit.Core/Models/GuildConfig.cs +++ b/PluralKit.Core/Models/GuildConfig.cs @@ -9,4 +9,5 @@ public class GuildConfig public bool LogCleanupEnabled { get; } public bool InvalidCommandResponseEnabled { get; } public bool RequireSystemTag { get; } + public bool SuppressNotifications { get; } } \ No newline at end of file diff --git a/PluralKit.Core/Models/Patch/GuildPatch.cs b/PluralKit.Core/Models/Patch/GuildPatch.cs index df146859..ae75e835 100644 --- a/PluralKit.Core/Models/Patch/GuildPatch.cs +++ b/PluralKit.Core/Models/Patch/GuildPatch.cs @@ -10,6 +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 override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper .With("log_channel", LogChannel) @@ -18,5 +19,6 @@ public class GuildPatch: PatchObject .With("log_cleanup_enabled", LogCleanupEnabled) .With("invalid_command_response_enabled", InvalidCommandResponseEnabled) .With("require_system_tag", RequireSystemTag) + .With("suppress_notifications", SuppressNotifications) ); } \ No newline at end of file diff --git a/docs/content/command-list.md b/docs/content/command-list.md index 0398f414..9de59f6f 100644 --- a/docs/content/command-list.md +++ b/docs/content/command-list.md @@ -157,6 +157,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 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