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, } #[derive(Deserialize, Debug)] struct Config { #[serde(rename = "command")] commands: Vec>, } lazy_static! { static ref RAW_CONFIG: String = super::file::read_file("config.toml").join("\n"); static ref COMMANDS: Vec> = { toml::from_str::(&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!() } }