diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..e41378f --- /dev/null +++ b/src/commands.rs @@ -0,0 +1,27 @@ +use crate::client::create_client; + +use twitch_irc::{ + login::StaticLoginCredentials, message::PrivmsgMessage, SecureTCPTransport, TwitchIRCClient, +}; + +pub async fn ping(m: &PrivmsgMessage) { + let client = create_client(); + + let (mut _incoming_messages, client) = + TwitchIRCClient::::new(client); + + let s = format!("Pong!"); + + let _message = client.say(m.channel_login.to_owned(), s.to_owned()).await; +} + +pub async fn test(m: &PrivmsgMessage) { + let client = create_client(); + + let (mut _incoming_messages, client) = + TwitchIRCClient::::new(client); + + let _message = client + .say(m.channel_login.to_owned(), "test".to_owned()) + .await; +} diff --git a/src/main.rs b/src/main.rs index 7947ac7..b3d2d33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,13 @@ use client::create_client; +use commands::*; use std::collections::HashMap; -use twitch_irc::login::StaticLoginCredentials; -use twitch_irc::message::ServerMessage; -use twitch_irc::SecureTCPTransport; -use twitch_irc::TwitchIRCClient; + +use twitch_irc::{ + login::StaticLoginCredentials, message::ServerMessage, SecureTCPTransport, TwitchIRCClient, +}; mod client; +mod commands; #[tokio::main] pub async fn main() { @@ -28,7 +30,7 @@ pub async fn main() { } } - let join_handle = tokio::spawn(async move { + let message_handler = tokio::spawn(async move { while let Some(message) = incoming_messages.recv().await { match message { ServerMessage::Privmsg(msg) => { @@ -38,18 +40,8 @@ pub async fn main() { ); if msg.sender.name == "notohh" { match msg.message_text.as_str() { - "*ping" => client - .say(msg.channel_login.to_owned(), "Pong!".to_owned()) - .await - .unwrap(), - "*test" => client - .say(msg.channel_login.to_owned(), "test".to_owned()) - .await - .unwrap(), - "*uptime" => client - .say(msg.channel_login.to_owned(), "aaa".to_owned()) - .await - .unwrap(), + "*ping" => ping(&msg).await, + "*test" => test(&msg).await, _ => {} } } @@ -62,5 +54,5 @@ pub async fn main() { } }); - join_handle.await.unwrap(); + message_handler.await.unwrap(); }