sonicbot_matrix/essentials/on_message/
help.rs1use crate::{Instructions, MessageArgs};
2
3pub fn main(message_args: MessageArgs) -> Vec<Instructions> {
4 let message_info = message_args.message_info;
5 let mut instructions: Vec<Instructions> = Vec::new();
6 let words: Vec<String> = message_info.message.clone().split_whitespace().map(|x| x.to_string()).collect();
7 if words.len() >= 2 {
8 let command_name = words[1].clone();
9 if let Some(help_string) = get_help_for_command(command_name.clone()) {
10 instructions.push(Instructions::SendMessage(message_info.room_id.clone(), format!("{}: {}{}", message_info.sender.clone(), message_args.prefix.clone(), help_string.clone())));
11 } else {
12 instructions.push(Instructions::SendMessage(message_info.room_id.clone(), format!("{}: Couldn't find a command named '{}'", message_info.sender.clone(), command_name.clone())));
13 }
14 }
15 instructions
16}
17
18fn get_help_for_command(command_name: String) -> Option<String> {
19 for message_module in crate::essentials::on_message::get_essentials_on_message() {
20 if message_module.name == command_name.clone() {
21 return Some(message_module.help);
22 }
23 }
24 for message_module in crate::plugins::on_message::get_plugins_on_message() {
25 if command_name.clone() == message_module.name {
26 return Some(message_module.help);
27 }
28 }
29 None
30}
31
32pub fn help() -> String {
33 String::from("help <command_name>\nDisplays information on what a command does and how to use it")
34}