2024-03-08 19:36:47 -05:00
|
|
|
use std::sync::{Arc, Mutex as StdMutex};
|
|
|
|
|
|
|
|
use twitchbot_rs::{Bot, ClientQueue, Command, Context};
|
2024-03-08 16:53:26 -05:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
2024-03-08 16:53:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
#[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(
|
2024-03-08 16:53:26 -05:00
|
|
|
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;
|
2024-03-08 16:53:26 -05:00
|
|
|
|
|
|
|
bot.run().await;
|
|
|
|
}
|