2025-01-04 07:35:04 +09:00
|
|
|
pub mod admin;
|
|
|
|
|
pub mod api;
|
|
|
|
|
pub mod autoproxy;
|
|
|
|
|
pub mod checks;
|
|
|
|
|
pub mod commands;
|
|
|
|
|
pub mod config;
|
|
|
|
|
pub mod dashboard;
|
|
|
|
|
pub mod debug;
|
|
|
|
|
pub mod fun;
|
|
|
|
|
pub mod group;
|
|
|
|
|
pub mod help;
|
|
|
|
|
pub mod import_export;
|
|
|
|
|
pub mod member;
|
|
|
|
|
pub mod message;
|
|
|
|
|
pub mod misc;
|
|
|
|
|
pub mod random;
|
|
|
|
|
pub mod server_config;
|
|
|
|
|
pub mod switch;
|
|
|
|
|
pub mod system;
|
|
|
|
|
|
2025-01-12 04:23:46 +09:00
|
|
|
use std::fmt::{Debug, Display};
|
2025-01-08 18:31:59 +09:00
|
|
|
|
2025-01-04 07:43:55 +09:00
|
|
|
use smol_str::SmolStr;
|
|
|
|
|
|
2025-01-05 00:59:59 +09:00
|
|
|
use crate::{
|
|
|
|
|
command,
|
|
|
|
|
token::{ToToken, Token},
|
|
|
|
|
};
|
2025-01-04 07:35:04 +09:00
|
|
|
|
2025-01-12 04:23:46 +09:00
|
|
|
#[derive(Debug, Clone)]
|
2025-01-04 07:35:04 +09:00
|
|
|
pub struct Command {
|
|
|
|
|
// TODO: fix hygiene
|
|
|
|
|
pub tokens: Vec<Token>,
|
2025-01-04 07:43:55 +09:00
|
|
|
pub help: SmolStr,
|
|
|
|
|
pub cb: SmolStr,
|
2025-01-11 23:05:29 +09:00
|
|
|
pub show_in_suggestions: bool,
|
2025-01-04 07:35:04 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Command {
|
|
|
|
|
pub fn new(
|
|
|
|
|
tokens: impl IntoIterator<Item = Token>,
|
2025-01-04 07:43:55 +09:00
|
|
|
help: impl Into<SmolStr>,
|
|
|
|
|
cb: impl Into<SmolStr>,
|
2025-01-11 23:05:29 +09:00
|
|
|
show_in_suggestions: bool,
|
2025-01-04 07:35:04 +09:00
|
|
|
) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
tokens: tokens.into_iter().collect(),
|
2025-01-04 07:43:55 +09:00
|
|
|
help: help.into(),
|
|
|
|
|
cb: cb.into(),
|
2025-01-11 23:05:29 +09:00
|
|
|
show_in_suggestions,
|
2025-01-04 07:35:04 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-08 18:31:59 +09:00
|
|
|
impl Display for Command {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
for (idx, token) in self.tokens.iter().enumerate() {
|
|
|
|
|
write!(f, "{}", token)?;
|
|
|
|
|
if idx < self.tokens.len() - 1 {
|
|
|
|
|
write!(f, " ")?;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-11 22:38:29 +09:00
|
|
|
Ok(())
|
2025-01-08 18:31:59 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 07:35:04 +09:00
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! command {
|
2025-01-11 23:05:29 +09:00
|
|
|
([$($v:expr),+], $cb:expr, $help:expr, suggest = $suggest:expr) => {
|
|
|
|
|
$crate::commands::Command::new([$($v.to_token()),*], $help, $cb, $suggest)
|
|
|
|
|
};
|
2025-01-04 07:35:04 +09:00
|
|
|
([$($v:expr),+], $cb:expr, $help:expr) => {
|
2025-01-11 23:05:29 +09:00
|
|
|
$crate::command!([$($v),+], $cb, $help, suggest = true)
|
2025-01-04 07:35:04 +09:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn all() -> Vec<Command> {
|
|
|
|
|
(help::cmds())
|
|
|
|
|
.chain(system::cmds())
|
|
|
|
|
.chain(member::cmds())
|
2025-01-07 23:15:18 +09:00
|
|
|
.chain(config::cmds())
|
2025-01-05 00:59:59 +09:00
|
|
|
.chain(fun::cmds())
|
2025-01-04 07:35:04 +09:00
|
|
|
.collect()
|
|
|
|
|
}
|