feat: alternate proxy switch mode "add"

This commit is contained in:
rladenson 2024-11-18 00:30:16 -07:00
parent 2555f7922c
commit 82b57de3e3
9 changed files with 65 additions and 17 deletions

View file

@ -126,8 +126,8 @@ public class Config
items.Add(new(
"Proxy Switch",
"Whether using a proxy tag logs a switch",
EnabledDisabled(ctx.Config.ProxySwitch),
"disabled"
ctx.Config.ProxySwitch.ToUserString(),
"off"
));
items.Add(new(
@ -555,14 +555,29 @@ public class Config
{
if (!ctx.HasNext())
{
var msg = $"Logging a switch every time a proxy tag is used is currently **{EnabledDisabled(ctx.Config.ProxySwitch)}**.";
string msg = ctx.Config.ProxySwitch switch
{
SystemConfig.ProxySwitchAction.Off => "Currently, when you proxy as a member, no switches are logged or changed.",
SystemConfig.ProxySwitchAction.New => "When you proxy as a member, currently it makes a new switch.",
SystemConfig.ProxySwitchAction.Add => "When you proxy as a member, currently it adds them to the current switch.",
_ => throw new Exception("unreachable"),
};
await ctx.Reply(msg);
return;
}
var newVal = ctx.MatchToggle(false);
// toggle = false means off, toggle = true means on, otherwise if they said add that means add. If none of those, error
var toggle = ctx.MatchToggleOrNull(false);
var newVal = toggle == false ? SystemConfig.ProxySwitchAction.Off : toggle == true ? SystemConfig.ProxySwitchAction.New : ctx.Match("add", "a") ? SystemConfig.ProxySwitchAction.Add : throw new PKError("You must pass either \"on\" or \"off\" to this command.");
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { ProxySwitch = newVal });
await ctx.Reply($"Logging a switch every time a proxy tag is used is now {EnabledDisabled(newVal)}.");
switch (newVal)
{
case SystemConfig.ProxySwitchAction.Off: await ctx.Reply("Now when you proxy as a member, no switches are logged or changed."); break;
case SystemConfig.ProxySwitchAction.New: await ctx.Reply("When you proxy as a member, it now makes a new switch."); break;
case SystemConfig.ProxySwitchAction.Add: await ctx.Reply("When you proxy as a member, it now adds them to the current switch."); break;
default: throw new Exception("unreachable");
}
}
public async Task NameFormat(Context ctx)