feat: move a couple of commands to MatchToggle

This commit is contained in:
spiral 2022-01-21 00:00:54 -05:00
parent e42002b754
commit f9aba1f129
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
2 changed files with 5 additions and 31 deletions

View File

@ -534,21 +534,7 @@ public class MemberEdit
if (ctx.System == null) throw Errors.NoSystemError; if (ctx.System == null) throw Errors.NoSystemError;
if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError; if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError;
bool newValue; if (!ctx.HasNext())
// todo: MatchToggle
if (ctx.Match("on", "enabled", "true", "yes") || ctx.MatchFlag("on", "enabled", "true", "yes"))
{
newValue = true;
}
else if (ctx.Match("off", "disabled", "false", "no") || ctx.MatchFlag("off", "disabled", "false", "no"))
{
newValue = false;
}
else if (ctx.HasNext())
{
throw new PKSyntaxError("You must pass either \"on\" or \"off\".");
}
else
{ {
if (target.AllowAutoproxy) if (target.AllowAutoproxy)
await ctx.Reply( await ctx.Reply(
@ -559,7 +545,7 @@ public class MemberEdit
return; return;
} }
; var newValue = ctx.MatchToggle();
var patch = new MemberPatch { AllowAutoproxy = Partial<bool>.Present(newValue) }; var patch = new MemberPatch { AllowAutoproxy = Partial<bool>.Present(newValue) };
await _repo.UpdateMember(target.Id, patch); await _repo.UpdateMember(target.Id, patch);

View File

@ -497,21 +497,7 @@ public class SystemEdit
else else
serverText = $"the server {guild.Name.EscapeMarkdown()}"; serverText = $"the server {guild.Name.EscapeMarkdown()}";
bool newValue; if (!ctx.HasNext())
// todo: MatchToggle
if (ctx.Match("on", "enabled", "true", "yes"))
{
newValue = true;
}
else if (ctx.Match("off", "disabled", "false", "no"))
{
newValue = false;
}
else if (ctx.HasNext())
{
throw new PKSyntaxError("You must pass either \"on\" or \"off\".");
}
else
{ {
if (gs.ProxyEnabled) if (gs.ProxyEnabled)
await ctx.Reply( await ctx.Reply(
@ -522,6 +508,8 @@ public class SystemEdit
return; return;
} }
var newValue = ctx.MatchToggle();
await _repo.UpdateSystemGuild(ctx.System.Id, guild.Id, new SystemGuildPatch { ProxyEnabled = newValue }); await _repo.UpdateSystemGuild(ctx.System.Id, guild.Id, new SystemGuildPatch { ProxyEnabled = newValue });
if (newValue) if (newValue)