commit 7f0d90d8af820eaee1b8b9fbff684744350abd4c Author: turtel Date: Fri Feb 16 22:52:02 2024 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f49eaf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# ---> Rust +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ +.idea/ +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock +src/variables.rs +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..99ae1e0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "twitchBot" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1.27.0", features = ["full"] } +rand = "0.8.5" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a79ca26 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Just super dank twitch bot +But it's not another js bot... IT's RUST BOT! and it still doesn't change anything :) diff --git a/src/commands/aha.rs b/src/commands/aha.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..96626fc --- /dev/null +++ b/src/main.rs @@ -0,0 +1,75 @@ +use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; +use tokio::net::TcpStream; + +mod variables; +use variables::{CHANNEL, CHANNEL2, PASSWORD, USERNAME}; + +#[tokio::main] +async fn main() { + let stream = TcpStream::connect("irc.chat.twitch.tv:6667").await.unwrap(); + let (reader, mut writer) = tokio::io::split(stream); + let mut reader = BufReader::new(reader); + writer + .write_all(format!("PASS {}\r\n", PASSWORD).as_bytes()) + .await + .unwrap(); + writer + .write_all(format!("NICK {}\r\n", USERNAME).as_bytes()) + .await + .unwrap(); + writer + .write_all(format!("JOIN #{}\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + writer + .write_all(format!("JOIN #{}\r\n", CHANNEL2).as_bytes()) + .await + .unwrap(); + writer + .write_all(format!("PRIVMSG #{} :RalpherZ\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + + loop { + let mut message = String::new(); + reader.read_line(&mut message).await; + println!("{}", message); + + // Respond to PING messages to avoid being disconnected + if message.contains("PING") { + writer.write_all(b"PONG\r\n").await.unwrap(); + } + + if message.starts_with("Welcome ") { + writer + .write_all(format!("PRIVMSG #{} :huj!\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + } + if message.contains("!e") { + writer + .write_all(format!("PRIVMSG #{} :hujj!\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + } + if message.contains("!jo") { + writer + .write_all(format!("PRIVMSG #{} :jkhghjkghjkgjl!\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + } + if message.contains("!ping") { + writer + .write_all(format!("PRIVMSG #{} :pong!\r\n", CHANNEL).as_bytes()) + .await + .unwrap(); + } + + let response = "This is a response with multiple words."; + if message.contains("!ayo") { + writer.write_all(format!("PRIVMSG #{} :{}\r\n", CHANNEL, response).as_bytes()).await.unwrap(); + } + } +} + +