feat(commands): add cs codegen to statically use params and flags in bot code, remove Any

This commit is contained in:
dusk 2025-01-21 12:36:54 +09:00
parent 0c012e98b5
commit 07e8a4851a
No known key found for this signature in database
20 changed files with 297 additions and 417 deletions

View file

@ -1,29 +1,25 @@
use command_parser::parameter;
use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
let cfg = ["config", "cfg"];
let autoproxy = ["autoproxy", "ap"];
let ap = tokens!(["config", "cfg"], ["autoproxy", "ap"]);
let ap_account = concat_tokens!(ap, [["account", "ac"]]);
let ap_timeout = concat_tokens!(ap, [["timeout", "tm"]]);
[
command!([cfg, autoproxy, ["account", "ac"]], "cfg_ap_account_show")
command!(ap_account => "cfg_ap_account_show")
.help("Shows autoproxy status for the account"),
command!(
[cfg, autoproxy, ["account", "ac"], Toggle],
"cfg_ap_account_update"
)
.help("Toggles autoproxy for the account"),
command!([cfg, autoproxy, ["timeout", "tm"]], "cfg_ap_timeout_show")
.help("Shows the autoproxy timeout"),
command!(
[
cfg,
autoproxy,
["timeout", "tm"],
any!(Disable, Reset, ("timeout", OpaqueString::SINGLE)) // todo: we should parse duration / time values
],
"cfg_ap_timeout_update"
)
.help("Sets the autoproxy timeout"),
command!(ap_account, Toggle => "cfg_ap_account_update")
.help("Toggles autoproxy for the account"),
command!(ap_timeout => "cfg_ap_timeout_show").help("Shows the autoproxy timeout"),
command!(ap_timeout, parameter::RESET => "cfg_ap_timeout_reset")
.help("Resets the autoproxy timeout"),
command!(ap_timeout, parameter::DISABLE => "cfg_ap_timeout_off")
.help("Disables the autoproxy timeout"),
command!(ap_timeout, ("timeout", OpaqueString) => "cfg_ap_timeout_update")
.help("Sets the autoproxy timeout"),
]
.into_iter()
}

View file

@ -2,8 +2,8 @@ use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(["thunder"], "fun_thunder"),
command!(["meow"], "fun_meow"),
command!(["thunder"] => "fun_thunder"),
command!(["meow"] => "fun_meow"),
]
.into_iter()
}

View file

@ -3,9 +3,9 @@ use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
let help = ["help", "h"];
[
command!([help], "help").help("Shows the help command"),
command!([help, "commands"], "help_commands").help("help commands"),
command!([help, "proxy"], "help_proxy").help("help proxy"),
command!([help] => "help").help("Shows the help command"),
command!([help, "commands"] => "help_commands").help("help commands"),
command!([help, "proxy"] => "help_proxy").help("help proxy"),
]
.into_iter()
}

View file

@ -18,7 +18,9 @@ pub mod server_config;
pub mod switch;
pub mod system;
use command_parser::{any, command, command::Command, parameter::*};
use command_parser::{
command, command::Command, concat_tokens, parameter::ParameterKind::*, tokens,
};
pub fn all() -> impl Iterator<Item = Command> {
(help::cmds())

View file

@ -6,38 +6,27 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let privacy = ["privacy", "priv"];
let new = ["new", "n"];
let member_target = tokens!(member, MemberRef);
let member_desc = concat_tokens!(member_target, [description]);
let member_privacy = concat_tokens!(member_target, [privacy]);
[
command!([member, new, ("name", OpaqueString::SINGLE)], "member_new")
command!([member, new, ("name", OpaqueString)] => "member_new")
.help("Creates a new system member"),
command!([member, MemberRef], "member_show")
.help("Shows information about a member")
.value_flag("pt", Disable),
command!([member, MemberRef, description], "member_desc_show")
.help("Shows a member's description"),
command!(
[
member,
MemberRef,
description,
("description", OpaqueString::REMAINDER)
],
"member_desc_update"
)
.help("Changes a member's description"),
command!([member, MemberRef, privacy], "member_privacy_show")
command!(member_target => "member_show")
.flag("pt")
.help("Shows information about a member"),
command!(member_desc => "member_desc_show").help("Shows a member's description"),
command!(member_desc, ("description", OpaqueStringRemainder) => "member_desc_update")
.help("Changes a member's description"),
command!(member_privacy => "member_privacy_show")
.help("Displays a member's current privacy settings"),
command!(
[
member,
MemberRef,
privacy,
MemberPrivacyTarget,
("new_privacy_level", PrivacyLevel)
],
"member_privacy_update"
member_privacy, MemberPrivacyTarget, ("new_privacy_level", PrivacyLevel)
=> "member_privacy_update"
)
.help("Changes a member's privacy settings"),
command!([member, MemberRef, "soulscream"], "member_soulscream").show_in_suggestions(false),
command!(member_target, "soulscream" => "member_soulscream").show_in_suggestions(false),
]
.into_iter()
}

View file

@ -4,11 +4,13 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let system = ["system", "s"];
let new = ["new", "n"];
let system_new = tokens!(system, new);
[
command!([system], "system_show").help("Shows information about your system"),
command!([system, new], "system_new").help("Creates a new system"),
command!([system, new, ("name", OpaqueString::SINGLE)], "system_new")
.help("Creates a new system"),
command!([system] => "system_show").help("Shows information about your system"),
command!(system_new => "system_new").help("Creates a new system"),
command!(system_new, ("name", OpaqueString) => "system_new_name")
.help("Creates a new system (using the provided name)"),
]
.into_iter()
}