mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): server config toggle for @silent proxied messages
This commit is contained in:
parent
2d36b8a7cc
commit
b88c1b7712
12 changed files with 50 additions and 3 deletions
|
|
@ -15,6 +15,7 @@ public record Message
|
||||||
SourceMessageDeleted = 1 << 3,
|
SourceMessageDeleted = 1 << 3,
|
||||||
Urgent = 1 << 4,
|
Urgent = 1 << 4,
|
||||||
Ephemeral = 1 << 6,
|
Ephemeral = 1 << 6,
|
||||||
|
SuppressNotifications = 1 << 12,
|
||||||
VoiceMessage = 1 << 13,
|
VoiceMessage = 1 << 13,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 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 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 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 Invite = new Command("invite", "invite", "Gets a link to invite PluralKit to other servers");
|
||||||
public static Command PermCheck = new Command("permcheck", "permcheck <guild>", "Checks whether a server's permission setup is correct");
|
public static Command PermCheck = new Command("permcheck", "permcheck <guild>", "Checks whether a server's permission setup is correct");
|
||||||
public static Command Admin = new Command("admin", "admin", "Super secret admin commands (sshhhh)");
|
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 =
|
public static Command[] ServerConfigCommands =
|
||||||
{
|
{
|
||||||
ServerConfigLogClean, ServerConfigInvalidCommandResponse, ServerConfigRequireSystemTag,
|
ServerConfigLogClean, ServerConfigInvalidCommandResponse, ServerConfigRequireSystemTag,
|
||||||
|
ServerConfigSuppressNotifications,
|
||||||
LogChannel, LogChannelClear, LogShow, LogDisable, LogEnable,
|
LogChannel, LogChannelClear, LogShow, LogDisable, LogEnable,
|
||||||
BlacklistShow, BlacklistAdd, BlacklistRemove
|
BlacklistShow, BlacklistAdd, BlacklistRemove
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -614,6 +614,8 @@ public partial class CommandTree
|
||||||
return ctx.Execute<ServerConfig>(null, m => m.InvalidCommandResponse(ctx));
|
return ctx.Execute<ServerConfig>(null, m => m.InvalidCommandResponse(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "require", "enforce" }, new[] { "tag", "systemtag" }) || ctx.Match("requiretag", "enforcetag"))
|
if (ctx.MatchMultiple(new[] { "require", "enforce" }, new[] { "tag", "systemtag" }) || ctx.Match("requiretag", "enforcetag"))
|
||||||
return ctx.Execute<ServerConfig>(null, m => m.RequireSystemTag(ctx));
|
return ctx.Execute<ServerConfig>(null, m => m.RequireSystemTag(ctx));
|
||||||
|
if (ctx.MatchMultiple(new[] { "suppress" }, new[] { "notifications" }) || ctx.Match("proxyping", "proxynotif"))
|
||||||
|
return ctx.Execute<ServerConfig>(null, m => m.SuppressNotifications(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "log" }, new[] { "channel" }))
|
if (ctx.MatchMultiple(new[] { "log" }, new[] { "channel" }))
|
||||||
return ctx.Execute<ServerConfig>(null, m => m.SetLogChannel(ctx));
|
return ctx.Execute<ServerConfig>(null, m => m.SetLogChannel(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "log" }, new[] { "blacklist" }))
|
if (ctx.MatchMultiple(new[] { "log" }, new[] { "blacklist" }))
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,13 @@ public class ServerConfig
|
||||||
"disabled"
|
"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(
|
items.Add(new(
|
||||||
"log channel",
|
"log channel",
|
||||||
"Channel to log proxied messages to",
|
"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.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.");
|
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)}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,6 +232,12 @@ public class ProxyService
|
||||||
var senderPermissions = PermissionExtensions.PermissionsFor(guild, messageChannel, trigger.Author.Id, guildMember);
|
var senderPermissions = PermissionExtensions.PermissionsFor(guild, messageChannel, trigger.Author.Id, guildMember);
|
||||||
var tts = match.Member.Tts && senderPermissions.HasFlag(PermissionSet.SendTtsMessages);
|
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
|
var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest
|
||||||
{
|
{
|
||||||
GuildId = trigger.GuildId!.Value,
|
GuildId = trigger.GuildId!.Value,
|
||||||
|
|
@ -246,7 +252,7 @@ public class ProxyService
|
||||||
Embeds = embeds.ToArray(),
|
Embeds = embeds.ToArray(),
|
||||||
Stickers = trigger.StickerItems,
|
Stickers = trigger.StickerItems,
|
||||||
AllowEveryone = allowEveryone,
|
AllowEveryone = allowEveryone,
|
||||||
Flags = trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage) ? Message.MessageFlags.VoiceMessage : null,
|
Flags = flags,
|
||||||
Tts = tts,
|
Tts = tts,
|
||||||
Poll = trigger.Poll,
|
Poll = trigger.Poll,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,6 @@ public class MessageContext
|
||||||
public bool InLogBlacklist { get; }
|
public bool InLogBlacklist { get; }
|
||||||
public bool LogCleanupEnabled { get; }
|
public bool LogCleanupEnabled { get; }
|
||||||
public bool RequireSystemTag { get; }
|
public bool RequireSystemTag { get; }
|
||||||
|
|
||||||
public bool DenyBotUsage { get; }
|
public bool DenyBotUsage { get; }
|
||||||
|
public bool SuppressNotifications { get; }
|
||||||
}
|
}
|
||||||
|
|
@ -27,6 +27,7 @@ create function message_context(account_id bigint, guild_id bigint, channel_id b
|
||||||
in_log_blacklist bool,
|
in_log_blacklist bool,
|
||||||
log_cleanup_enabled bool,
|
log_cleanup_enabled bool,
|
||||||
require_system_tag bool,
|
require_system_tag bool,
|
||||||
|
suppress_notifications bool,
|
||||||
|
|
||||||
deny_bot_usage bool
|
deny_bot_usage bool
|
||||||
)
|
)
|
||||||
|
|
@ -67,6 +68,7 @@ as $$
|
||||||
or (thread_id = any (servers.log_blacklist))) as in_log_blacklist,
|
or (thread_id = any (servers.log_blacklist))) as in_log_blacklist,
|
||||||
coalesce(servers.log_cleanup_enabled, false) as log_cleanup_enabled,
|
coalesce(servers.log_cleanup_enabled, false) as log_cleanup_enabled,
|
||||||
coalesce(servers.require_system_tag, false) as require_system_tag,
|
coalesce(servers.require_system_tag, false) as require_system_tag,
|
||||||
|
coalesce(servers.suppress_notifications, false) as suppress_notifications,
|
||||||
|
|
||||||
-- abuse_logs table
|
-- abuse_logs table
|
||||||
coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage
|
coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage
|
||||||
|
|
|
||||||
7
PluralKit.Core/Database/Migrations/51.sql
Normal file
7
PluralKit.Core/Database/Migrations/51.sql
Normal file
|
|
@ -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;
|
||||||
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
||||||
internal class DatabaseMigrator
|
internal class DatabaseMigrator
|
||||||
{
|
{
|
||||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
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;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public DatabaseMigrator(ILogger logger)
|
public DatabaseMigrator(ILogger logger)
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,5 @@ public class GuildConfig
|
||||||
public bool LogCleanupEnabled { get; }
|
public bool LogCleanupEnabled { get; }
|
||||||
public bool InvalidCommandResponseEnabled { get; }
|
public bool InvalidCommandResponseEnabled { get; }
|
||||||
public bool RequireSystemTag { get; }
|
public bool RequireSystemTag { get; }
|
||||||
|
public bool SuppressNotifications { get; }
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ public class GuildPatch: PatchObject
|
||||||
public Partial<bool> LogCleanupEnabled { get; set; }
|
public Partial<bool> LogCleanupEnabled { get; set; }
|
||||||
public Partial<bool> InvalidCommandResponseEnabled { get; set; }
|
public Partial<bool> InvalidCommandResponseEnabled { get; set; }
|
||||||
public Partial<bool> RequireSystemTag { get; set; }
|
public Partial<bool> RequireSystemTag { get; set; }
|
||||||
|
public Partial<bool> SuppressNotifications { get; set; }
|
||||||
|
|
||||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||||
.With("log_channel", LogChannel)
|
.With("log_channel", LogChannel)
|
||||||
|
|
@ -18,5 +19,6 @@ public class GuildPatch: PatchObject
|
||||||
.With("log_cleanup_enabled", LogCleanupEnabled)
|
.With("log_cleanup_enabled", LogCleanupEnabled)
|
||||||
.With("invalid_command_response_enabled", InvalidCommandResponseEnabled)
|
.With("invalid_command_response_enabled", InvalidCommandResponseEnabled)
|
||||||
.With("require_system_tag", RequireSystemTag)
|
.With("require_system_tag", RequireSystemTag)
|
||||||
|
.With("suppress_notifications", SuppressNotifications)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -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 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 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 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 <channel>` - Designates a channel to post proxied messages to
|
- `pk;serverconfig log channel <channel>` - Designates a channel to post proxied messages to
|
||||||
- `pk;serverconfig log channel -clear` - Clears the currently set log channel
|
- `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
|
- `pk;serverconfig log blacklist`- Displays the current list of channels where logging is disabled
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue