feat: per-server keepproxy toggling (#574)

Merges PluralKit/PluralKit#574
This commit is contained in:
Jake Fulmine 2023-08-10 18:15:25 +12:00 committed by Iris System
parent 8a59ef5f50
commit 22ce250b56
11 changed files with 131 additions and 15 deletions

View file

@ -55,6 +55,7 @@ public partial class CommandTree
public static Command MemberAutoproxy = new Command("member autoproxy", "member <member> autoproxy [on|off]", "Sets whether a member will be autoproxied when autoproxy is set to latch or front mode.");
public static Command MemberKeepProxy = new Command("member keepproxy", "member <member> keepproxy [on|off]", "Sets whether to include a member's proxy tags when proxying");
public static Command MemberTts = new Command("member text-to-speech", "member <member> text-to-speech [on|off]", "Sets whether to send a member's messages as text-to-speech messages.");
public static Command MemberServerKeepProxy = new Command("member server keepproxy", "member <member> serverkeepproxy [on|off]", "Sets whether to include a member's proxy tags when proxying in the current server.");
public static Command MemberRandom = new Command("system random", "system [system] random", "Shows the info card of a randomly selected member in a system.");
public static Command MemberId = new Command("member id", "member [member] id", "Prints a member's id.");
public static Command MemberPrivacy = new Command("member privacy", "member <member> privacy <name|description|birthday|pronouns|metadata|visibility|all> <public|private>", "Changes a members's privacy settings");
@ -153,4 +154,4 @@ public partial class CommandTree
public static Command[] LogCommands = { LogChannel, LogChannelClear, LogEnable, LogDisable, LogShow };
public static Command[] BlacklistCommands = { BlacklistAdd, BlacklistRemove, BlacklistShow };
}
}

View file

@ -338,6 +338,8 @@ public partial class CommandTree
await ctx.Execute<MemberEdit>(MemberKeepProxy, m => m.KeepProxy(ctx, target));
else if (ctx.Match("texttospeech", "text-to-speech", "tts"))
await ctx.Execute<MemberEdit>(MemberTts, m => m.Tts(ctx, target));
else if (ctx.Match("serverkeepproxy", "servershowtags", "guildshowtags", "guildkeeptags", "serverkeeptags", "skp"))
await ctx.Execute<MemberEdit>(MemberServerKeepProxy, m => m.ServerKeepProxy(ctx, target));
else if (ctx.Match("id"))
await ctx.Execute<Member>(MemberId, m => m.DisplayId(ctx, target));
else if (ctx.Match("privacy"))
@ -538,4 +540,4 @@ public partial class CommandTree
// todo: maybe add the list of configuration keys here?
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands config` for the list of possible config settings.");
}
}
}

View file

@ -494,6 +494,7 @@ public class MemberEdit
public async Task KeepProxy(Context ctx, PKMember target)
{
ctx.CheckSystem().CheckOwnMember(target);
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
bool newValue;
if (ctx.Match("on", "enabled", "true", "yes"))
@ -510,12 +511,19 @@ public class MemberEdit
}
else
{
string keepProxyStatusMessage = "";
if (target.KeepProxy)
await ctx.Reply(
"This member has keepproxy **enabled**, which means proxy tags will be **included** in the resulting message when proxying.");
keepProxyStatusMessage += "This member has keepproxy **enabled**. Proxy tags will be **included** in the resulting message when proxying.";
else
await ctx.Reply(
"This member has keepproxy **disabled**, which means proxy tags will **not** be included in the resulting message when proxying.");
keepProxyStatusMessage += "This member has keepproxy **disabled**. Proxy tags will **not** be included in the resulting message when proxying.";
if (memberGuildConfig.KeepProxy.HasValue && memberGuildConfig.KeepProxy.Value)
keepProxyStatusMessage += $"\n{Emojis.Warn} This member has keepproxy **enabled in this server**, which means proxy tags will **always** be included when proxying in this server, regardless of the global keepproxy.";
else if (memberGuildConfig.KeepProxy.HasValue && !memberGuildConfig.KeepProxy.Value)
keepProxyStatusMessage += $"\n{Emojis.Warn} This member has keepproxy **disabled in this server**, which means proxy tags will **never** be included when proxying in this server, regardless of the global keepproxy.";
await ctx.Reply(keepProxyStatusMessage);
return;
}
@ -524,12 +532,88 @@ public class MemberEdit
var patch = new MemberPatch { KeepProxy = Partial<bool>.Present(newValue) };
await ctx.Repository.UpdateMember(target.Id, patch);
string keepProxyUpdateMessage = "";
if (newValue)
await ctx.Reply(
$"{Emojis.Success} Member proxy tags will now be included in the resulting message when proxying.");
keepProxyUpdateMessage += $"{Emojis.Success} this member now has keepproxy **enabled**. Member proxy tags will be **included** in the resulting message when proxying.";
else
await ctx.Reply(
$"{Emojis.Success} Member proxy tags will now not be included in the resulting message when proxying.");
keepProxyUpdateMessage += $"{Emojis.Success} this member now has keepproxy **disabled**. Member proxy tags will be **included** in the resulting message when proxying.";
if (memberGuildConfig.KeepProxy.HasValue && memberGuildConfig.KeepProxy.Value)
keepProxyUpdateMessage += $"\n{Emojis.Warn} This member has keepproxy **enabled in this server**, which means proxy tags will **always** be included when proxying in this server, regardless of the global keepproxy.";
else if (memberGuildConfig.KeepProxy.HasValue && !memberGuildConfig.KeepProxy.Value)
keepProxyUpdateMessage += $"\n{Emojis.Warn} This member has keepproxy **disabled in this server**, which means proxy tags will **never** be included when proxying in this server, regardless of the global keepproxy.";
await ctx.Reply(keepProxyUpdateMessage);
}
public async Task ServerKeepProxy(Context ctx, PKMember target)
{
ctx.CheckGuildContext();
ctx.CheckSystem().CheckOwnMember(target);
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
bool? newValue;
if (ctx.Match("on", "enabled", "true", "yes"))
{
newValue = true;
}
else if (ctx.Match("off", "disabled", "false", "no"))
{
newValue = false;
}
else if (ctx.MatchClear())
{
newValue = null;
}
else if (ctx.HasNext())
{
throw new PKSyntaxError("You must pass either \"on\" or \"off\".");
}
else
{
if (memberGuildConfig.KeepProxy.HasValue)
if (memberGuildConfig.KeepProxy.Value)
await ctx.Reply(
"This member has keepproxy **enabled** in the current server, which means proxy tags will be **included** in the resulting message when proxying.");
else
await ctx.Reply(
"This member has keepproxy **disabled** in the current server, which means proxy tags will **not** be included in the resulting message when proxying.");
else
{
var noServerKeepProxySetMessage = "This member does not have a server keepproxy override set.";
if (target.KeepProxy)
noServerKeepProxySetMessage += " The global keepproxy is **enabled**, which means proxy tags will be **included** when proxying.";
else
noServerKeepProxySetMessage += " The global keepproxy is **disabled**, which means proxy tags will **not** be included when proxying.";
await ctx.Reply(noServerKeepProxySetMessage);
}
return;
}
var patch = new MemberGuildPatch { KeepProxy = Partial<bool?>.Present(newValue) };
await ctx.Repository.UpdateMemberGuild(target.Id, ctx.Guild.Id, patch);
if (newValue.HasValue)
if (newValue.Value)
await ctx.Reply(
$"{Emojis.Success} Member proxy tags will now be **included** in the resulting message when proxying **in the current server**.");
else
await ctx.Reply(
$"{Emojis.Success} Member proxy tags will now **not** be included in the resulting message when proxying **in the current server**.");
else
{
var serverKeepProxyClearedMessage = $"{Emojis.Success} Cleared server keepproxy settings for this member.";
if (target.KeepProxy)
serverKeepProxyClearedMessage += " Member proxy tags will now be **included** in the resulting message when proxying.";
else
serverKeepProxyClearedMessage += " Member proxy tags will now **not** be included in the resulting message when proxying.";
await ctx.Reply(serverKeepProxyClearedMessage);
}
}
public async Task Tts(Context ctx, PKMember target)

View file

@ -9,13 +9,22 @@ public struct ProxyMatch
public string? Content;
public ProxyTag? ProxyTags;
private bool ShouldKeepProxy()
{
if (Member.ServerKeepProxy != null && Member.ServerKeepProxy.Value)
return true;
else if (Member.KeepProxy && !(Member.ServerKeepProxy != null && !Member.ServerKeepProxy.Value))
return true;
else return false;
}
public string? ProxyContent
{
get
{
// Add the proxy tags into the proxied message if that option is enabled
// Also check if the member has any proxy tags - some cases autoproxy can return a member with no tags
if (Member.KeepProxy && Content != null && ProxyTags != null)
if (ShouldKeepProxy() && ProxyTags != null && Content != null)
return $"{ProxyTags.Value.Prefix}{Content}{ProxyTags.Value.Suffix}";
return Content;