feat: add command to copy a switch and add new members

This commit is contained in:
rladenson 2024-09-03 00:35:41 -06:00
parent fc18847ee1
commit d78de949af
2 changed files with 12 additions and 2 deletions

View file

@ -430,6 +430,8 @@ public partial class CommandTree
await ctx.Execute<Switch>(SwitchEdit, m => m.SwitchEdit(ctx));
else if (ctx.Match("delete", "remove", "erase", "cancel", "yeet"))
await ctx.Execute<Switch>(SwitchDelete, m => m.SwitchDelete(ctx));
else if (ctx.Match("add", "duplicate", "dupe", "copy"))
await ctx.Execute<Switch>(SwitchDelete, m => m.SwitchEdit(ctx, true));
else if (ctx.Match("commands", "help"))
await PrintCommandList(ctx, "switching", SwitchCommands);
else if (ctx.HasNext()) // there are following arguments

View file

@ -104,7 +104,7 @@ public class Switch
await ctx.Reply($"{Emojis.Success} Switch moved to <t:{newSwitchTime}> ({newSwitchDeltaStr} ago).");
}
public async Task SwitchEdit(Context ctx)
public async Task SwitchEdit(Context ctx, bool newSwitch = false)
{
ctx.CheckSystem();
@ -119,7 +119,15 @@ public class Switch
else if (ctx.MatchFlag("prepend", "p"))
newMembers = await PrependToSwitch(ctx, newMembers);
await DoEditCommand(ctx, newMembers);
if (newSwitch)
{
// if there's no edit flag, assume we're appending
if (!ctx.MatchFlag("first", "f", "remove", "r", "append", "a", "prepend", "p"))
newMembers = await AppendToSwitch(ctx, newMembers);
await DoSwitchCommand(ctx, newMembers);
}
else
await DoEditCommand(ctx, newMembers);
}
public async Task<List<PKMember>> PrependToSwitch(Context ctx, List<PKMember> members)
{