Join multiple channels defined in env variables
This commit is contained in:
parent
2e07297600
commit
4d52772010
2 changed files with 50 additions and 4 deletions
|
@ -8,3 +8,5 @@ test ModulatingForceBot
|
|||
Set the following environment variables
|
||||
|
||||
`access_token = <oath token>`
|
||||
|
||||
`bot_channels = <chnl1>,<chnl2>`
|
50
src/main.rs
50
src/main.rs
|
@ -2,6 +2,7 @@ use twitch_irc::login::StaticLoginCredentials;
|
|||
use twitch_irc::ClientConfig;
|
||||
use twitch_irc::SecureTCPTransport;
|
||||
use twitch_irc::TwitchIRCClient;
|
||||
use twitch_irc::message::ServerMessage;
|
||||
use std::env;
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -9,6 +10,24 @@ pub async fn main() {
|
|||
let login_name = "modulatingforcebot".to_owned();
|
||||
let oauth_token = env::var("access_token").unwrap().to_owned();
|
||||
|
||||
|
||||
/*
|
||||
Vector of channels to join
|
||||
*/
|
||||
|
||||
let mut botchannels = Vec::new();
|
||||
/* botchannels.push(String::from("modulatingforcebot"));
|
||||
botchannels.push(String::from("notohh"));
|
||||
botchannels.push(String::from("modulatingforce"));
|
||||
botchannels.push(String::from("secondsocksan"));
|
||||
*/
|
||||
|
||||
for chnl in env::var("bot_channels").unwrap().split(',') {
|
||||
// println!("(Env Var # {})",chnl);
|
||||
botchannels.push(String::from(chnl));
|
||||
}
|
||||
|
||||
|
||||
let config = ClientConfig::new_simple(
|
||||
StaticLoginCredentials::new(login_name, Some(oauth_token))
|
||||
);
|
||||
|
@ -17,12 +36,37 @@ pub async fn main() {
|
|||
|
||||
let join_handle = tokio::spawn(async move {
|
||||
while let Some(message) = incoming_messages.recv().await {
|
||||
println!("Received message: {:?}", message);
|
||||
// Below can be used to debug if I want to capture all messages
|
||||
// println!("Received message: {:?}", message);
|
||||
|
||||
match message {
|
||||
ServerMessage::Privmsg(msg) => {
|
||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
},
|
||||
ServerMessage::Whisper(msg) => {
|
||||
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
},
|
||||
ServerMessage::Join(msg) => {
|
||||
println!("JOINED: {}", msg.channel_login);
|
||||
},
|
||||
ServerMessage::Part(msg) => {
|
||||
println!("PARTED: {}", msg.channel_login);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.join("modulatingforcebot".to_owned()).unwrap();
|
||||
client.say("modulatingforcebot".to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
|
||||
// client.join("modulatingforcebot".to_owned()).unwrap();
|
||||
// client.say("modulatingforcebot".to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
|
||||
for chnl in botchannels {
|
||||
client.join(chnl.to_owned()).unwrap();
|
||||
// client.say(chnl.to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
client.say(chnl.to_owned(), "annytfLurk".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
|
||||
join_handle.await.unwrap();
|
||||
}
|
Loading…
Reference in a new issue