twitchbot-rs/tests/integration_test.rs

74 lines
1.7 KiB
Rust
Raw Permalink 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();
2024-03-23 14:50:45 -04:00
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));
2024-03-08 19:36:47 -05:00
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;
}