twitchbot-rs/tests/integration_test.rs

73 lines
1.6 KiB
Rust
Raw Normal View History

2024-03-08 19:36:47 -05:00
use std::sync::{Arc, Mutex as StdMutex};
use twitchbot_rs::{Bot, ClientQueue, Command, Context};
use twitchbot_rs::bot::ClientAM;
pub struct Payload {
content: String,
}
2024-03-08 19:36:47 -05:00
pub struct PingCommand;
impl Command for PingCommand {
type CommandPayLoad = Payload;
fn execute(&self, pl_am: Arc<StdMutex<Self::CommandPayLoad>>, ctx: Context) -> ClientQueue {
let mut queue = ClientQueue::new();
let pl = pl_am.lock().unwrap();
queue.say("mzntori".to_string(), format!("Pong! {} {}", pl.content, ctx.sender.name));
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<StdMutex<Self::CommandPayLoad>>, 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();
2024-03-08 19:36:47 -05:00
let mut bot = Bot::new(
login.as_str(),
oauth.as_str(),
Payload { content: String::new() },
);
2024-03-08 19:36:47 -05:00
bot.add_command("!ping".to_owned(), Box::new(PingCommand {})).await;
bot.add_command("!urm".to_owned(), Box::new(UrmCommand {})).await;
bot.run().await;
}