echo.rs (872B)
1 use std::{ 2 collections::HashMap, 3 sync::{Arc, Mutex}, 4 }; 5 6 use failure::Fallible; 7 use ruma_bot::{command_handler, Bot, BotBuilder, MsgContent, State}; 8 9 type AppState = Arc<Mutex<HashMap<String, String>>>; 10 11 #[command_handler] 12 async fn help(bot: Bot, msg_content: MsgContent, state: State<AppState>) -> Fallible<()> { 13 println!("help called!"); 14 15 Ok(()) 16 } 17 18 //#[command_handler(commands = ["x", "y", "z"])] 19 //async fn test(state: State<AppState>) -> Fallible<()> { 20 // Ok(()) 21 //} 22 23 //#[reaction_handler] 24 //async fn handle_reaction(state: State<AppState>) -> Fallible<()> { 25 // Ok(()) 26 //} 27 28 #[tokio::main] 29 async fn main() { 30 let bot = BotBuilder::new() 31 .state(Arc::new(Mutex::new(HashMap::<String, String>::new()))) 32 .register(help) 33 .build() 34 .unwrap(); 35 36 if let Err(e) = bot.run().await { 37 eprintln!("{}", e); 38 } 39 }