feat(bot): server config toggle for @silent proxied messages

This commit is contained in:
Iris System 2024-12-30 04:33:17 +00:00
parent 2d36b8a7cc
commit b88c1b7712
12 changed files with 50 additions and 3 deletions

View file

@ -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 <guild>", "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
};

View file

@ -614,6 +614,8 @@ public partial class CommandTree
return ctx.Execute<ServerConfig>(null, m => m.InvalidCommandResponse(ctx));
if (ctx.MatchMultiple(new[] { "require", "enforce" }, new[] { "tag", "systemtag" }) || ctx.Match("requiretag", "enforcetag"))
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" }))
return ctx.Execute<ServerConfig>(null, m => m.SetLogChannel(ctx));
if (ctx.MatchMultiple(new[] { "log" }, new[] { "blacklist" }))

View file

@ -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)}.");
}
}

View file

@ -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,
});