From 63cb570402dffb06bceefb92990c61dfb8430397 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Thu, 21 Nov 2024 03:15:33 -0600 Subject: [PATCH] Better argument handling --- Commands/Arguments/BaseArgument.cs | 4 ++-- Commands/Arguments/BoolArgument.cs | 4 +--- Commands/Arguments/PlayerArgument.cs | 3 +-- Commands/Arguments/StringArgument.cs | 4 +--- Commands/KickCommand.cs | 4 +--- Commands/RemovePlayerCommand.cs | 3 +-- Commands/RoleCommand.cs | 3 +-- Commands/SetPrefixCommand.cs | 3 +-- Commands/SetRoleCommand.cs | 3 +-- 9 files changed, 10 insertions(+), 21 deletions(-) diff --git a/Commands/Arguments/BaseArgument.cs b/Commands/Arguments/BaseArgument.cs index 4428b14..6720e32 100644 --- a/Commands/Arguments/BaseArgument.cs +++ b/Commands/Arguments/BaseArgument.cs @@ -1,9 +1,9 @@ namespace BetterAmongUs.Commands { - public abstract class BaseArgument(BaseCommand? command) + public abstract class BaseArgument(BaseCommand? command, string argInfo) { public BaseCommand? Command { get; } = command; - public abstract string ArgInfo { get; } + public string ArgInfo { get; } = argInfo; public string Arg { get; set; } = string.Empty; protected virtual string[] ArgSuggestions => GetArgSuggestions.Invoke(); public Func GetArgSuggestions { get; set; } = () => { return []; }; diff --git a/Commands/Arguments/BoolArgument.cs b/Commands/Arguments/BoolArgument.cs index 7e9f005..4e228f3 100644 --- a/Commands/Arguments/BoolArgument.cs +++ b/Commands/Arguments/BoolArgument.cs @@ -1,9 +1,7 @@ namespace BetterAmongUs.Commands; -public class BoolArgument(BaseCommand? command) : BaseArgument(command) +public class BoolArgument(BaseCommand? command, string argInfo = "{bool}") : BaseArgument(command, argInfo) { - public override string ArgInfo => suggestion; - public string suggestion = "{bool}"; protected override string[] ArgSuggestions => ["true", "false"]; public bool? GetBool() { diff --git a/Commands/Arguments/PlayerArgument.cs b/Commands/Arguments/PlayerArgument.cs index 528e63a..b81aeeb 100644 --- a/Commands/Arguments/PlayerArgument.cs +++ b/Commands/Arguments/PlayerArgument.cs @@ -2,10 +2,9 @@ namespace BetterAmongUs.Commands; -public class PlayerArgument(BaseCommand? command) : BaseArgument(command) +public class PlayerArgument(BaseCommand? command, string argInfo = "{player}") : BaseArgument(command, argInfo) { protected override string[] ArgSuggestions => Main.AllPlayerControls.OrderBy(pc => pc.PlayerId).Select(pc => pc.Data.PlayerName.Replace(' ', '_')).ToArray(); - public override string ArgInfo => "{Player}"; public PlayerControl? TryGetTarget() { var player = Main.AllPlayerControls.FirstOrDefault(pc => pc.Data.PlayerName.ToLower().Replace(' ', '_') == Arg.ToLower()); diff --git a/Commands/Arguments/StringArgument.cs b/Commands/Arguments/StringArgument.cs index 3499ada..463298d 100644 --- a/Commands/Arguments/StringArgument.cs +++ b/Commands/Arguments/StringArgument.cs @@ -1,7 +1,5 @@ namespace BetterAmongUs.Commands; -public class StringArgument(BaseCommand? command) : BaseArgument(command) +public class StringArgument(BaseCommand? command, string argInfo = "{String}") : BaseArgument(command, argInfo) { - public override string ArgInfo => suggestion; - public string suggestion = "{String}"; } \ No newline at end of file diff --git a/Commands/KickCommand.cs b/Commands/KickCommand.cs index e31ea51..aa26955 100644 --- a/Commands/KickCommand.cs +++ b/Commands/KickCommand.cs @@ -12,10 +12,8 @@ public class KickCommand : BaseCommand _arguments = new Lazy(() => new BaseArgument[] { new PlayerArgument(this), - new BoolArgument(this), + new BoolArgument(this, "{ban}"), }); - - boolArgument.suggestion = "{Ban}"; } private readonly Lazy _arguments; public override BaseArgument[]? Arguments => _arguments.Value; diff --git a/Commands/RemovePlayerCommand.cs b/Commands/RemovePlayerCommand.cs index 32deb02..7d1da41 100644 --- a/Commands/RemovePlayerCommand.cs +++ b/Commands/RemovePlayerCommand.cs @@ -13,9 +13,8 @@ public class RemovePlayerCommand : BaseCommand { _arguments = new Lazy(() => new BaseArgument[] { - new StringArgument(this), + new StringArgument(this, "{identifier}"), }); - identifierArgument.suggestion = "{Identifier}"; identifierArgument.GetArgSuggestions = AntiCheat.GatherAllData; } private readonly Lazy _arguments; diff --git a/Commands/RoleCommand.cs b/Commands/RoleCommand.cs index e80477a..db5646a 100644 --- a/Commands/RoleCommand.cs +++ b/Commands/RoleCommand.cs @@ -15,9 +15,8 @@ public class RoleCommand : BaseCommand { _arguments = new Lazy(() => new BaseArgument[] { - new StringArgument(this), + new StringArgument(this, "{role}"), }); - roleArgument.suggestion = "{Role}"; roleArgument.GetArgSuggestions = () => { return RoleManager.Instance.AllRoles.Select(role => role.NiceName.ToLower()).ToArray(); }; } private readonly Lazy _arguments; diff --git a/Commands/SetPrefixCommand.cs b/Commands/SetPrefixCommand.cs index dee8db9..0134a68 100644 --- a/Commands/SetPrefixCommand.cs +++ b/Commands/SetPrefixCommand.cs @@ -9,9 +9,8 @@ public class SetPrefixCommand : BaseCommand { _arguments = new Lazy(() => new BaseArgument[] { - new StringArgument(this), + new StringArgument(this, "{prefix}"), }); - prefixArgument.suggestion = "{Prefix}"; } private readonly Lazy _arguments; public override BaseArgument[]? Arguments => _arguments.Value; diff --git a/Commands/SetRoleCommand.cs b/Commands/SetRoleCommand.cs index 6007d26..7855491 100644 --- a/Commands/SetRoleCommand.cs +++ b/Commands/SetRoleCommand.cs @@ -16,9 +16,8 @@ public class SetRoleCommand : BaseCommand _arguments = new Lazy(() => new BaseArgument[] { new PlayerArgument(this), - new StringArgument(this), + new StringArgument(this, "{role}"), }); ; - roleArgument.suggestion = "{Name}"; roleArgument.GetArgSuggestions = () => { return RoleManager.Instance.AllRoles.Select(role => role.NiceName.ToLower()).ToArray(); }; } private readonly Lazy _arguments;