servers/src/commands/help.rs

46 lines
1020 B
Rust
Raw Normal View History

use crate::plugins::prelude::*;
2022-06-04 11:58:21 +00:00
pub struct Help;
2022-06-04 11:58:21 +00:00
#[async_trait]
impl Command for Help {
2022-06-04 11:58:21 +00:00
fn name(&self) -> &'static str {
"/help"
}
fn aliases(&self) -> Vec<&'static str> {
vec!["/h", "/?", "?"]
}
2022-06-04 11:58:21 +00:00
fn help(&self) -> &'static str {
"Show commands help menu"
2022-06-04 11:58:21 +00:00
}
fn usage(&self) -> &'static str {
"/help"
}
async fn execute(&self, client: &Client, _args: Vec<&str>) -> anyhow::Result<()> {
let mut msg = Vec::new();
for cmd in client.plugins_manager.commands.iter() {
let aliases = cmd.aliases();
let aliases = if !aliases.is_empty() {
cmd.aliases().join(", ")
} else {
"none".to_string()
};
msg.push(format!(
"{name} - {help} (Aliases: {aliases})",
name = cmd.name(),
help = cmd.help(),
aliases = aliases,
))
2022-06-04 11:58:21 +00:00
}
client.send(msg.join("\n"))
2022-06-04 11:58:21 +00:00
}
}