mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 07:17:56 +00:00
remove command_system_macros
This commit is contained in:
parent
737d6d3216
commit
b6eec3784d
5 changed files with 93 additions and 176 deletions
|
|
@ -8,7 +8,6 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
lazy_static = { workspace = true }
|
||||
command_system_macros = { path = "../command_system_macros" }
|
||||
|
||||
uniffi = { version = "0.25" }
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ mod string;
|
|||
mod token;
|
||||
use token::*;
|
||||
|
||||
use command_system_macros::commands;
|
||||
|
||||
// todo!: move all this stuff into a different file
|
||||
// lib.rs should just have exported symbols and command definitions
|
||||
|
||||
|
|
@ -69,23 +67,105 @@ impl TreeBranch {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Command {
|
||||
tokens: Vec<Token>,
|
||||
help: String,
|
||||
cb: String,
|
||||
}
|
||||
|
||||
// todo: aliases
|
||||
// todo: categories
|
||||
commands! {
|
||||
command(help, help, "Shows the help command");
|
||||
fn command(tokens: &[&Token], help: &str, cb: &str) -> Command {
|
||||
Command {
|
||||
tokens: tokens.iter().map(|&x| x.clone()).collect(),
|
||||
help: help.to_string(),
|
||||
cb: cb.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
command(member new, member_new, "Creates a new system member");
|
||||
command(member @MemberRef, member_show, "Shows information about a member");
|
||||
command(member @MemberRef description, member_desc_show, "Shows a member's description");
|
||||
command(member @MemberRef description @FullString, member_desc_update, "Changes a member's description");
|
||||
command(member @MemberRef privacy, member_privacy_show, "Displays a member's current privacy settings");
|
||||
command(member @MemberRef privacy @MemberPrivacyTarget @PrivacyLevel, member_privacy_update, "Changes a member's privacy settings");
|
||||
mod commands {
|
||||
use super::Token;
|
||||
|
||||
use super::command;
|
||||
use super::Token::*;
|
||||
|
||||
fn cmd(value: &str) -> Token {
|
||||
Token::Value(vec![value.to_string()])
|
||||
}
|
||||
|
||||
pub fn cmd_with_alias(value: &[&str]) -> Token {
|
||||
Token::Value(value.iter().map(|x| x.to_string()).collect())
|
||||
}
|
||||
|
||||
// todo: this needs to have less ampersands -alyssa
|
||||
pub fn happy() -> Vec<super::Command> {
|
||||
let system = &cmd_with_alias(&["system", "s"]);
|
||||
let member = &cmd_with_alias(&["member", "m"]);
|
||||
let description = &cmd_with_alias(&["description", "desc"]);
|
||||
let privacy = &cmd_with_alias(&["privacy", "priv"]);
|
||||
vec![
|
||||
command(&[&cmd("help")], "help", "Shows the help command"),
|
||||
command(
|
||||
&[system],
|
||||
"system_show",
|
||||
"Shows information about your system",
|
||||
),
|
||||
command(&[system, &cmd("new")], "system_new", "Creates a new system"),
|
||||
command(
|
||||
&[member, &cmd_with_alias(&["new", "n"])],
|
||||
"member_new",
|
||||
"Creates a new system member",
|
||||
),
|
||||
command(
|
||||
&[member, &MemberRef],
|
||||
"member_show",
|
||||
"Shows information about a member",
|
||||
),
|
||||
command(
|
||||
&[member, &MemberRef, description],
|
||||
"member_desc_show",
|
||||
"Shows a member's description",
|
||||
),
|
||||
command(
|
||||
&[member, &MemberRef, description, &FullString],
|
||||
"member_desc_update",
|
||||
"Changes a member's description",
|
||||
),
|
||||
command(
|
||||
&[member, &MemberRef, privacy],
|
||||
"member_privacy_show",
|
||||
"Displays a member's current privacy settings",
|
||||
),
|
||||
command(
|
||||
&[
|
||||
member,
|
||||
&MemberRef,
|
||||
privacy,
|
||||
&MemberPrivacyTarget,
|
||||
&PrivacyLevel,
|
||||
],
|
||||
"member_privacy_update",
|
||||
"Changes a member's privacy settings",
|
||||
),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref COMMAND_TREE: TreeBranch = {
|
||||
let mut tree = TreeBranch {
|
||||
current_command_key: None,
|
||||
possible_tokens: vec![],
|
||||
branches: HashMap::new(),
|
||||
};
|
||||
|
||||
commands::happy().iter().for_each(|x| tree.register_command(x.clone()));
|
||||
|
||||
tree.sort_tokens();
|
||||
|
||||
// println!("{{tree:#?}}");
|
||||
|
||||
tree
|
||||
};
|
||||
}
|
||||
|
||||
pub enum CommandResult {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
|||
lazy_static::lazy_static! {
|
||||
// Dictionary of (left, right) quote pairs
|
||||
// Each char in the string is an individual quote, multi-char strings imply "one of the following chars"
|
||||
// Certain languages can have quote patterns that have a different character for open and close
|
||||
pub static ref QUOTE_PAIRS: HashMap<String, String> = {
|
||||
let mut pairs = HashMap::new();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue