From 29473f1c1ed2c0d6af39c7f66a3c49a23e1203da Mon Sep 17 00:00:00 2001 From: notohh Date: Fri, 7 Jun 2024 18:51:20 -0400 Subject: [PATCH] updates --- Cargo.toml | 1 + src/client.rs | 16 ++++++++++++++++ src/main.rs | 40 ++++++++++++---------------------------- 3 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 src/client.rs diff --git a/Cargo.toml b/Cargo.toml index a6fe6b9..f1ce5f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] dotenv = "0.15.0" pretty_env_logger = "0.5.0" +sysinfo = "0.30.12" tokio = { version = "1.37.0", features = ["full"] } twitch-irc = "5.0.1" twitch_api = "0.7.0-rc.7" diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..b9d27a6 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,16 @@ +use std::env; + +use dotenv::dotenv; +use twitch_irc::login::StaticLoginCredentials; +use twitch_irc::ClientConfig; + +pub fn create_client() -> ClientConfig { + dotenv().ok(); + let twitch_id = env::var("TWITCH_ID").expect("Failed to load twitch id"); + + let twitch_oauth = env::var("TWITCH_OAUTH").expect("Failed to load oauth"); + + let login_creds = StaticLoginCredentials::new(twitch_id, Some(twitch_oauth)); + + ClientConfig::new_simple(login_creds) +} diff --git a/src/main.rs b/src/main.rs index 2bb67ba..7947ac7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,36 +1,18 @@ -use dotenv::dotenv; +use client::create_client; use std::collections::HashMap; -use std::env; use twitch_irc::login::StaticLoginCredentials; -use twitch_irc::message::ReplyToMessage; use twitch_irc::message::ServerMessage; -use twitch_irc::ClientConfig; use twitch_irc::SecureTCPTransport; use twitch_irc::TwitchIRCClient; +mod client; + #[tokio::main] pub async fn main() { - dotenv().ok(); - let twitch_id = match env::var("TWITCH_ID").to_owned() { - Ok(val) => val, - Err(_) => { - eprintln!("TWITCH_ID not found in environment variables."); - return; - } - }; + let client = create_client(); - let twitch_oauth = match env::var("TWITCH_OAUTH").to_owned() { - Ok(val) => val, - Err(_) => { - eprintln!("TWITCH_OAUTH not found in environment variables."); - return; - } - }; - - let config = - ClientConfig::new_simple(StaticLoginCredentials::new(twitch_id, Some(twitch_oauth))); let (mut incoming_messages, client) = - TwitchIRCClient::::new(config); + TwitchIRCClient::::new(client); let mut initial_channels = HashMap::new(); @@ -41,13 +23,11 @@ pub async fn main() { for (channels, _) in initial_channels.iter() { match client.join(channels.to_owned().to_string()) { - Ok(_) => println!("Joined channels {}", channels), + Ok(_) => println!("Joined channel {}", channels), Err(e) => eprintln!("Failed to join channels! {}", e), } } - let prefix = "?"; - let join_handle = tokio::spawn(async move { while let Some(message) = incoming_messages.recv().await { match message { @@ -58,14 +38,18 @@ pub async fn main() { ); if msg.sender.name == "notohh" { match msg.message_text.as_str() { - "?ping" => client + "*ping" => client .say(msg.channel_login.to_owned(), "Pong!".to_owned()) .await .unwrap(), - "?test" => client + "*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(), _ => {} } }