use std::sync::{Arc, Mutex as StdMutex}; use twitchbot_rs::{Bot, ClientQueue, Command, Context}; use twitchbot_rs::bot::ClientAM; pub struct Payload { content: String, } pub struct PingCommand; impl Command for PingCommand { type CommandPayLoad = Payload; fn execute(&self, pl_am: Arc>, ctx: Context) -> ClientQueue { let mut queue = ClientQueue::new(); let pl = pl_am.lock().unwrap(); queue.say(ctx.channel_login.to_owned(), format!("Pong! {} {}", pl.content, ctx.sender.name)); queue.say("gaygebot".to_string(), format!("Ponged in {}", ctx.channel_login)); println!("Pong executed! {}", pl.content); queue } fn help(&self) -> String { "pongs".to_owned() } fn info(&self) -> String { "do be ponging".to_owned() } } pub struct UrmCommand; impl Command for UrmCommand { type CommandPayLoad = Payload; fn execute(&self, pl_am: Arc>, ctx: Context) -> ClientQueue { let mut pl = pl_am.lock().unwrap(); pl.content.push('1'); ClientQueue::new() } fn help(&self) -> String { "pongs".to_owned() } fn info(&self) -> String { "do be ponging".to_owned() } } #[tokio::test] async fn main() { let login = std::env::var("LOGIN").unwrap(); let oauth = std::env::var("OAUTH").unwrap(); let mut bot = Bot::new( login.as_str(), oauth.as_str(), Payload { content: String::new() }, ); bot.add_command("!ping".to_owned(), Box::new(PingCommand {})).await; bot.add_command("!urm".to_owned(), Box::new(UrmCommand {})).await; bot.run().await; }