From 2a063442ead16d47788418bbc8de32a4e2cd9111 Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 15 Jan 2025 00:21:11 +0900 Subject: [PATCH] refactor(commands): remove Reset as a parameter type --- .../CommandSystem/Context/ContextParametersExt.cs | 10 ---------- PluralKit.Bot/CommandSystem/Parameters.cs | 3 --- PluralKit.Bot/Commands/Config.cs | 2 +- crates/commands/src/commands.udl | 1 - crates/commands/src/lib.rs | 1 - crates/commands/src/token.rs | 6 +++++- 6 files changed, 6 insertions(+), 17 deletions(-) diff --git a/PluralKit.Bot/CommandSystem/Context/ContextParametersExt.cs b/PluralKit.Bot/CommandSystem/Context/ContextParametersExt.cs index 754403b0..4a34a43a 100644 --- a/PluralKit.Bot/CommandSystem/Context/ContextParametersExt.cs +++ b/PluralKit.Bot/CommandSystem/Context/ContextParametersExt.cs @@ -51,14 +51,4 @@ public static class ContextParametersExt param => (param as Parameter.Toggle)?.value ); } - - // this can never really be false (either it's present and is true or it's not present) - // but we keep it nullable for consistency with the other methods - public static async Task ParamResolveReset(this Context ctx, string param_name) - { - return await ctx.Parameters.ResolveParameter( - ctx, param_name, - param => param is Parameter.Reset - ); - } } \ No newline at end of file diff --git a/PluralKit.Bot/CommandSystem/Parameters.cs b/PluralKit.Bot/CommandSystem/Parameters.cs index 87666673..263367cd 100644 --- a/PluralKit.Bot/CommandSystem/Parameters.cs +++ b/PluralKit.Bot/CommandSystem/Parameters.cs @@ -13,7 +13,6 @@ public abstract record Parameter() public record PrivacyLevel(string level): Parameter; public record Toggle(bool value): Parameter; public record Opaque(string value): Parameter; - public record Reset(): Parameter; } public class Parameters @@ -80,8 +79,6 @@ public class Parameters return new Parameter.Toggle(toggle.toggle); case uniffi.commands.Parameter.OpaqueString opaque: return new Parameter.Opaque(opaque.raw); - case uniffi.commands.Parameter.Reset _: - return new Parameter.Reset(); } return null; } diff --git a/PluralKit.Bot/Commands/Config.cs b/PluralKit.Bot/Commands/Config.cs index e4fecbdc..4acd00dc 100644 --- a/PluralKit.Bot/Commands/Config.cs +++ b/PluralKit.Bot/Commands/Config.cs @@ -230,7 +230,7 @@ public class Config public async Task EditAutoproxyTimeout(Context ctx) { var _newTimeout = await ctx.ParamResolveOpaque("timeout"); - var _reset = await ctx.ParamResolveReset("reset"); + var _reset = await ctx.ParamResolveToggle("reset"); var _toggle = await ctx.ParamResolveToggle("toggle"); Duration? newTimeout; diff --git a/crates/commands/src/commands.udl b/crates/commands/src/commands.udl index 824ec5a5..d1b5ae1c 100644 --- a/crates/commands/src/commands.udl +++ b/crates/commands/src/commands.udl @@ -14,7 +14,6 @@ interface Parameter { PrivacyLevel(string level); OpaqueString(string raw); Toggle(boolean toggle); - Reset(); }; dictionary ParsedCommand { string command_ref; diff --git a/crates/commands/src/lib.rs b/crates/commands/src/lib.rs index e7105789..abad8c0c 100644 --- a/crates/commands/src/lib.rs +++ b/crates/commands/src/lib.rs @@ -49,7 +49,6 @@ pub enum Parameter { PrivacyLevel { level: String }, OpaqueString { raw: String }, Toggle { toggle: bool }, - Reset, } #[derive(Debug)] diff --git a/crates/commands/src/token.rs b/crates/commands/src/token.rs index 594517a7..367c85b6 100644 --- a/crates/commands/src/token.rs +++ b/crates/commands/src/token.rs @@ -198,7 +198,11 @@ impl Token { Err(_) => None, }, Self::Reset(param_name) => match Reset::from_str(input) { - Ok(_) => TokenMatchValue::new_match_param(input, param_name, Parameter::Reset), + Ok(_) => TokenMatchValue::new_match_param( + input, + param_name, + Parameter::Toggle { toggle: true }, + ), Err(_) => None, }, // don't add a _ match here!