use std::fmt::Display; use std::str::FromStr; use enum_iterator::IntoEnumIterator; macro_rules! import_command { ($( $command:tt ),* $(,)?) => { $( mod $command; pub use $command::$command; )* }; } import_command!(help, ping, source, uwuify); #[derive(IntoEnumIterator)] pub enum BotCommand { Help, Source, Uwu, Ping, } impl BotCommand { pub const fn help_text(&self) -> &'static str { match self { Self::Source => "Links to the source code for this bot.", Self::Uwu => "Uwuifies your message.", Self::Ping => "Pong!", Self::Help => "Prints this help.", } } } impl FromStr for BotCommand { type Err = (); fn from_str(s: &str) -> std::result::Result { match s.to_lowercase().as_str() { "source" => Ok(Self::Source), "uwu" => Ok(Self::Uwu), "ping" => Ok(Self::Ping), "help" => Ok(Self::Help), _ => Err(()), } } } impl Display for BotCommand { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { BotCommand::Source => write!(f, "source"), BotCommand::Uwu => write!(f, "uwu"), BotCommand::Ping => write!(f, "ping"), BotCommand::Help => write!(f, "help"), } } }