42 lines
1.0 KiB
Rust
42 lines
1.0 KiB
Rust
|
use itertools::Itertools;
|
||
|
use lazy_static;
|
||
|
use serde::Deserialize;
|
||
|
use serenity::model::channel::Message;
|
||
|
|
||
|
#[derive(Deserialize, Debug)]
|
||
|
pub struct Command<'a> {
|
||
|
trigger: &'a str,
|
||
|
command: &'a str,
|
||
|
users: Vec<u64>,
|
||
|
}
|
||
|
|
||
|
#[derive(Deserialize, Debug)]
|
||
|
struct Config {
|
||
|
#[serde(rename = "command")]
|
||
|
commands: Vec<Command<'static>>,
|
||
|
}
|
||
|
|
||
|
lazy_static! {
|
||
|
static ref RAW_CONFIG: String = super::file::read_file("config.toml").join("\n");
|
||
|
static ref COMMANDS: Vec<Command<'static>> = {
|
||
|
toml::from_str::<Config>(&RAW_CONFIG).expect("Error in config").commands
|
||
|
};
|
||
|
}
|
||
|
|
||
|
pub fn print_commands() {
|
||
|
COMMANDS.iter().for_each(|c| println!("{:?}", c));
|
||
|
}
|
||
|
|
||
|
pub fn find_matching(message: &str) -> Option<&Command> {
|
||
|
COMMANDS.iter().find(|&c| message.starts_with(&c.trigger))
|
||
|
}
|
||
|
|
||
|
impl<'a> Command<'a> {
|
||
|
pub fn execute(&self, msg: &Message) -> Result<(), &'static str> {
|
||
|
if !self.users.contains(&msg.author.id.0) {
|
||
|
return Err("You don’t have the permissions to execute this command.");
|
||
|
}
|
||
|
unimplemented!()
|
||
|
}
|
||
|
}
|