updates
This commit is contained in:
parent
79e7cc1ffa
commit
29473f1c1e
3 changed files with 29 additions and 28 deletions
|
@ -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"
|
||||
|
|
16
src/client.rs
Normal file
16
src/client.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use std::env;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use twitch_irc::login::StaticLoginCredentials;
|
||||
use twitch_irc::ClientConfig;
|
||||
|
||||
pub fn create_client() -> ClientConfig<StaticLoginCredentials> {
|
||||
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)
|
||||
}
|
40
src/main.rs
40
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::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
||||
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::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(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue