mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Merge 7643051829 into 4a947c01fc
This commit is contained in:
commit
d2f55117b5
9 changed files with 89 additions and 14 deletions
|
|
@ -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 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 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 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)");
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ public class ServerConfig
|
||||||
|
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
"suppress notifications",
|
"suppress notifications",
|
||||||
"Whether all proxied messages will have notifications suppressed (sent as `@silent` messages)",
|
"Under what conditions proxied messages will have notifications suppressed (sent as `@silent` messages)",
|
||||||
EnabledDisabled(ctx.GuildConfig!.SuppressNotifications),
|
ctx.GuildConfig!.SuppressNotifications.ToUserString(),
|
||||||
"disabled"
|
"never"
|
||||||
));
|
));
|
||||||
|
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
|
|
@ -438,13 +438,56 @@ public class ServerConfig
|
||||||
|
|
||||||
if (!ctx.HasNext())
|
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 are ";
|
||||||
|
switch (ctx.GuildConfig!.SuppressNotifications)
|
||||||
|
{
|
||||||
|
case GuildConfig.SuppressCondition.Never:
|
||||||
|
msg += "never marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Always:
|
||||||
|
msg += "always marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Match:
|
||||||
|
msg += "marked as silent if the trigger message was marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Invert:
|
||||||
|
msg += "marked as silent if the trigger message was **not** marked as silent.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
await ctx.Reply(msg);
|
await ctx.Reply(msg);
|
||||||
return;
|
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.Repository.UpdateGuild(ctx.Guild.Id, new() { SuppressNotifications = newVal });
|
||||||
await ctx.Reply($"Suppressing notifications for proxied messages is now {EnabledDisabled(newVal)}.");
|
|
||||||
|
var changeMsg = $"Suppressing notifications for proxied messages is now set to {newVal.ToUserString()}. Proxied messages will ";
|
||||||
|
switch (newVal)
|
||||||
|
{
|
||||||
|
case GuildConfig.SuppressCondition.Never:
|
||||||
|
changeMsg += "never be marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Always:
|
||||||
|
changeMsg += "always be marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Match:
|
||||||
|
changeMsg += "be marked as silent if the trigger message was marked as silent.";
|
||||||
|
break;
|
||||||
|
case GuildConfig.SuppressCondition.Invert:
|
||||||
|
changeMsg += "be marked as silent if the trigger message was **not** marked as silent.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
await ctx.Reply(changeMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,7 +242,15 @@ public class ProxyService
|
||||||
var tts = match.Member.Tts && senderPermissions.HasFlag(PermissionSet.SendTtsMessages);
|
var tts = match.Member.Tts && senderPermissions.HasFlag(PermissionSet.SendTtsMessages);
|
||||||
|
|
||||||
Message.MessageFlags flags = 0;
|
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;
|
flags |= Message.MessageFlags.SuppressNotifications;
|
||||||
if (trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage))
|
if (trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage))
|
||||||
flags |= Message.MessageFlags.VoiceMessage;
|
flags |= Message.MessageFlags.VoiceMessage;
|
||||||
|
|
|
||||||
|
|
@ -37,5 +37,5 @@ public class MessageContext
|
||||||
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; }
|
public GuildConfig.SuppressCondition SuppressNotifications { get; }
|
||||||
}
|
}
|
||||||
|
|
@ -9,5 +9,18 @@ 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; }
|
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();
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +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 Partial<GuildConfig.SuppressCondition> 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)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +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,
|
suppress_notifications int,
|
||||||
|
|
||||||
deny_bot_usage bool
|
deny_bot_usage bool
|
||||||
)
|
)
|
||||||
|
|
@ -68,7 +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,
|
coalesce(servers.suppress_notifications, 0) 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
|
||||||
|
|
|
||||||
11
crates/migrate/data/migrations/54.sql
Normal file
11
crates/migrate/data/migrations/54.sql
Normal file
|
|
@ -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;
|
||||||
|
|
@ -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 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 suppress notifications [always|never|match|invert]` - Sets under which conditions proxied messages have push notifications suppressed (sent as `@silent` messages). If set to `match` it will match the trigger message, and if set to `invert` it will be suppressed if the trigger message is not suppressed and vice versa.
|
||||||
- `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