73 lines
No EOL
1.6 KiB
Rust
73 lines
No EOL
1.6 KiB
Rust
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<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();
|
|
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;
|
|
} |