Add src/main.rs
This commit is contained in:
parent
f01e19542a
commit
1cd7a1920a
1 changed files with 232 additions and 0 deletions
232
src/main.rs
Normal file
232
src/main.rs
Normal file
|
@ -0,0 +1,232 @@
|
|||
use twitch_irc::login::StaticLoginCredentials;
|
||||
use twitch_irc::TwitchIRCClient;
|
||||
use twitch_irc::{ClientConfig, SecureTCPTransport};
|
||||
use twitch_irc::message::ServerMessage;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
/*
|
||||
NOTE: This project is a mess, because I have literally zero idea on how to code
|
||||
in Rust. Just take the good stuff and fix the messy things lul
|
||||
*/
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
|
||||
// Load all lines from .env
|
||||
dotenv().ok();
|
||||
|
||||
// Temp variables for loading .env
|
||||
let mut fetch_login_name = String::from("");
|
||||
let mut fetch_oauth = String::from("");
|
||||
|
||||
// Read env keys
|
||||
match env::var("TWITCH_LOGIN_NAME") {
|
||||
Ok(value) => {
|
||||
println!("TWITCH_LOGIN_NAME value is: {}", value);
|
||||
fetch_login_name.push_str(value.as_str());
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("TWITCH_LOGIN_NAME is not set or is an invalid UTF-8 string.");
|
||||
}
|
||||
}
|
||||
match env::var("TWITCH_OAUTH_TOKEN") {
|
||||
Ok(value) => {
|
||||
println!("TWITCH_OAUTH_TOKEN value is: {}", value);
|
||||
fetch_oauth.push_str(value.as_str());
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("TWITCH_OAUTH_TOKEN is not set or is an invalid UTF-8 string");
|
||||
}
|
||||
}
|
||||
|
||||
// default configuration is to join chat as anonymous.
|
||||
//let config = ClientConfig::default();
|
||||
|
||||
// Login with oauth + display name
|
||||
let login_name = fetch_login_name.to_owned();
|
||||
let oauth_token = fetch_oauth.to_owned();
|
||||
let config = ClientConfig::new_simple(
|
||||
StaticLoginCredentials::new(login_name, Some(oauth_token))
|
||||
);
|
||||
|
||||
// uuh wtf is this
|
||||
let (mut incoming_messages, client) =
|
||||
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
||||
|
||||
// join a channel
|
||||
// This function only returns an error if the passed channel login name is malformed,
|
||||
// so in this simple case where the channel name is hardcoded we can ignore the potential
|
||||
// error with `unwrap`.
|
||||
let join_channel = "notohh".to_owned();
|
||||
client.join(join_channel.to_owned()).unwrap();
|
||||
|
||||
let mut allow_all = true.to_owned();
|
||||
let mut enable = true.to_owned();
|
||||
|
||||
//client.say(join_channel.to_owned(), "wokege".to_owned()).await.unwrap();
|
||||
|
||||
// first thing you should do: start consuming incoming messages,
|
||||
// otherwise they will back up.
|
||||
let join_handle = tokio::spawn(async move {
|
||||
while let Some(message) = incoming_messages.recv().await {
|
||||
match message {
|
||||
ServerMessage::Privmsg(msg) => {
|
||||
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
|
||||
if msg.sender.name == "T3neppa" {
|
||||
if msg.message_text.contains("!allow") {
|
||||
if msg.message_text.contains("everyone") {
|
||||
allow_all = true;
|
||||
client.say(join_channel.to_owned(), "allow -> everyone".to_owned()).await.unwrap();
|
||||
}
|
||||
if msg.message_text.contains("limited") {
|
||||
allow_all = false;
|
||||
client.say(join_channel.to_owned(), "allow -> neppa".to_owned()).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if msg.message_text.starts_with("!e") {
|
||||
enable = true;
|
||||
client.say(join_channel.to_owned(), "pogs freedom".to_owned()).await.unwrap();
|
||||
}
|
||||
if msg.message_text.starts_with("!d") {
|
||||
enable = false;
|
||||
client.say(join_channel.to_owned(), "sadg".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
let words: Vec<&str> = msg.message_text.split_whitespace().collect();
|
||||
|
||||
for word in words {
|
||||
println!("{}", word);
|
||||
}
|
||||
}
|
||||
|
||||
if msg.sender.name == "T3neppa" || (allow_all && enable) {
|
||||
println!("(#{}) {}: {}", msg.channel_login,msg.sender.name, msg.message_text);
|
||||
|
||||
match msg.message_text.find("!cmd") {
|
||||
Some(index) => {
|
||||
if index == 0 {
|
||||
if msg.sender.name == "T3neppa" {
|
||||
client.say(join_channel.to_owned(), "unimplemented".to_owned()).await.unwrap();
|
||||
}else{
|
||||
let cmd_response = "tuckk {msg.sender.name}";
|
||||
client.say(join_channel.to_owned(), cmd_response.to_owned()).await.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
match msg.message_text.find("uuh") {
|
||||
Some(index) => {
|
||||
client.say(join_channel.to_owned(), "uuh".to_owned()).await.unwrap();
|
||||
}
|
||||
None => {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
match msg.message_text.find("cum") {
|
||||
Some(index) => {
|
||||
client.say(join_channel.to_owned(), "sadE".to_owned()).await.unwrap();
|
||||
}
|
||||
None => {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if msg.message_text.starts_with("test") && msg.channel_login == "notohh" {
|
||||
client.say(join_channel.to_owned(), "I'll test yourmom tonight".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.to_lowercase().contains("tuck") && msg.message_text.to_lowercase().contains("smug") {
|
||||
client.say(join_channel.to_owned(), "Bedge".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("hmm") {
|
||||
client.say(join_channel.to_owned(), "think faster idiot".to_owned()).await.unwrap();
|
||||
}
|
||||
if msg.message_text.contains("cock") {
|
||||
client.say(join_channel.to_owned(), "YEP".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("actually") {
|
||||
client.say(join_channel.to_owned(), "lol Nerdge".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("pwd") {
|
||||
client.say(join_channel.to_owned(), "yourmom".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("thread") {
|
||||
client.say(join_channel.to_owned(), "what".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("femboy") {
|
||||
client.say(join_channel.to_owned(), format!("AREYOUAFEMBOY {}", msg.sender.name).to_owned()).await.unwrap();
|
||||
}
|
||||
/*
|
||||
if msg.message_text.contains("rm") {
|
||||
if msg.message_text.contains("-") {
|
||||
client.say("notohh".to_owned(), "oopsie".to_owned()).await.unwrap();
|
||||
}else{
|
||||
client.say("notohh".to_owned(), "no permission".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
if let Some(index) = msg.message_text.find("ping") {
|
||||
if index == 0 {
|
||||
client.say(join_channel.to_owned(), "kok".to_owned()).await.unwrap();
|
||||
}
|
||||
}
|
||||
if msg.message_text.contains("KannaLost") {
|
||||
client.say(join_channel.to_owned(), "KannaLost PETPET".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if (msg.message_text.contains("femboy") || msg.message_text.to_lowercase().contains("pog")) && msg.message_text.contains("friday") {
|
||||
client.say(join_channel.to_owned(), "dinkDonk femboy friday dinkDonk ".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("fuck") && msg.message_text.contains("this") {
|
||||
client.say(join_channel.to_owned(), "AAA".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("ls") {
|
||||
if msg.message_text.contains("-") {
|
||||
client.say(join_channel.to_owned(), "Homework Downloads Pictures Gacchi".to_owned()).await.unwrap();
|
||||
}else{
|
||||
client.say(join_channel.to_owned(), "Erm".to_owned()).await.unwrap();
|
||||
}
|
||||
}
|
||||
if msg.message_text.contains("POGCRAZY") {
|
||||
client.say(join_channel.to_owned(), "POGCRAZY yayy".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
if msg.message_text.contains("rust") {
|
||||
client.say(join_channel.to_owned(), "Scared".to_owned()).await.unwrap();
|
||||
}
|
||||
if msg.message_text.starts_with("smug") {
|
||||
client.say(join_channel.to_owned(), "yo".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
ServerMessage::Whisper(msg) => {
|
||||
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// keep the tokio executor alive.
|
||||
// If you return instead of waiting the background task will exit.
|
||||
join_handle.await.unwrap();
|
||||
}
|
Loading…
Reference in a new issue