From f9aba1f1298b9a9228753db1a470b9e0b4950397 Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 21 Jan 2022 00:00:54 -0500 Subject: [PATCH] feat: move a couple of commands to MatchToggle --- PluralKit.Bot/Commands/MemberEdit.cs | 18 ++---------------- PluralKit.Bot/Commands/SystemEdit.cs | 18 +++--------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/PluralKit.Bot/Commands/MemberEdit.cs b/PluralKit.Bot/Commands/MemberEdit.cs index 076b319c..f3f7a966 100644 --- a/PluralKit.Bot/Commands/MemberEdit.cs +++ b/PluralKit.Bot/Commands/MemberEdit.cs @@ -534,21 +534,7 @@ public class MemberEdit if (ctx.System == null) throw Errors.NoSystemError; if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError; - bool newValue; - // 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 (!ctx.HasNext()) { if (target.AllowAutoproxy) await ctx.Reply( @@ -559,7 +545,7 @@ public class MemberEdit return; } - ; + var newValue = ctx.MatchToggle(); var patch = new MemberPatch { AllowAutoproxy = Partial.Present(newValue) }; await _repo.UpdateMember(target.Id, patch); diff --git a/PluralKit.Bot/Commands/SystemEdit.cs b/PluralKit.Bot/Commands/SystemEdit.cs index 708af0e0..b5f1b675 100644 --- a/PluralKit.Bot/Commands/SystemEdit.cs +++ b/PluralKit.Bot/Commands/SystemEdit.cs @@ -497,21 +497,7 @@ public class SystemEdit else serverText = $"the server {guild.Name.EscapeMarkdown()}"; - bool newValue; - // 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 (!ctx.HasNext()) { if (gs.ProxyEnabled) await ctx.Reply( @@ -522,6 +508,8 @@ public class SystemEdit return; } + var newValue = ctx.MatchToggle(); + await _repo.UpdateSystemGuild(ctx.System.Id, guild.Id, new SystemGuildPatch { ProxyEnabled = newValue }); if (newValue)