From 0eed57a000110ca06061211a10d5de2d4997ef5a Mon Sep 17 00:00:00 2001 From: legitnull Date: Fri, 17 Feb 2023 04:58:25 -0700 Subject: [PATCH] modified ai to be in config for prompt shit --- src/main.rs | 25 +++++++++++-------------- src/modules/ai.rs | 29 ++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 201194d..718f587 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,8 @@ struct Config { nick: String, password: String, channels: Vec, + admin_users: Vec, + ignore_users: Vec, } fn main() { @@ -39,31 +41,26 @@ fn main() { .build() .unwrap(); -// PUT CONFIG IN A SEPRATE FILE IE: CONFIG.TOML - // read the contents of the config file into a string + // LOAD CONFIG let config_str = std::fs::read_to_string("config.toml").unwrap(); - - // parse the string into a toml::Value let config_value = config_str.parse::().unwrap(); - - // deserialize the value into a Config struct let config: Config = config_value.try_into().unwrap(); - - let stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).unwrap();; // DONT DO DRUGS YOU WILL END UP LIKE ME + // GIVE THE SERVER A SLOPPPY SPAM OF RETARDEDNESS + let stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).unwrap(); let connector = SslConnector::builder(SslMethod::tls()).unwrap().build(); + // DONT DO DRUGS YOU WILL END UP LIKE ME let mut ssl_stream = connector.connect(&config.server, stream).unwrap(); let nick_command = format!("NICK {}_\r\n", config.nick); //setup passwords let user_command = format!("USER {} 0 * :{}\r\n", config.nick, config.nick); ssl_stream.write_all(nick_command.as_bytes()).unwrap(); ssl_stream.write_all(user_command.as_bytes()).unwrap(); - let identify_command = format!("PRIVMSG NickServ :IDENTIFY {} {}\r\n", config.nick, config.password); ssl_stream.write(identify_command.as_bytes()).unwrap(); let channels = config.channels.join(","); let join_command = format!("JOIN {}\r\n", channels); - let admin_users = vec!["s4d", "s4d[m]"]; // ADMINS - let ignored_users = vec!["maple", "aibird", "proffesserOak"]; // IGNORED + let admin_users = config.admin_users; // ADMINS + let ignored_users = config.ignore_users; // IGNORED // ... ssl_stream.write_all(join_command.as_bytes()).unwrap(); @@ -95,7 +92,7 @@ fn main() { if message.starts_with(":") && message.contains(" :%") { let parts: Vec<&str> = message.splitn(2, ' ').collect(); // Check if user is admin_user let username = parts[0].trim_start_matches(':').split("!").next().unwrap(); - if !admin_users.contains(&username) { + if !admin_users.contains(&username.to_string()) { println!("[!] UNAUTHORIZED: {}", username); continue; // ... } @@ -111,7 +108,7 @@ fn main() { } // Check if the message is user and respond via ai - else if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains("g1r") { //modify for on mention + else if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains(&config.nick) { //modify for on mention let channel = message.split("PRIVMSG ").nth(1).and_then(|s| s.splitn(2, ' ').next()).unwrap(); if !channels.contains(&channel) { continue; @@ -119,7 +116,7 @@ fn main() { // extract the username from the first part and check if ignored let parts: Vec<&str> = message.splitn(2, ' ').collect(); // split the message into two parts at the first space let username = parts[0].trim_start_matches(':').split("!").next().unwrap(); - if ignored_users.contains(&username) { + if ignored_users.contains(&username.to_string()) { println!("[!] IGNORED: {}", username); continue; } diff --git a/src/modules/ai.rs b/src/modules/ai.rs index d06b091..e223225 100644 --- a/src/modules/ai.rs +++ b/src/modules/ai.rs @@ -2,16 +2,32 @@ use async_openai::{Client, types::{CreateCompletionRequestArgs}}; use regex::Regex; use crate::modules::Command; - +use toml::{from_str, Value}; +use serde::Deserialize; +#[derive(Deserialize)] +struct Config { + nick: String, + channels: Vec, + openai: String, + accents: String, + personalities: String, +} pub struct Ai; impl Command for Ai { fn handle(&self, message: &str) -> Vec { let mut responses = Vec::new(); - if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains("g1r") { + let config_str = std::fs::read_to_string("config.toml").unwrap(); + let config_value = config_str.parse::().unwrap(); + let config: Config = config_value.try_into().unwrap(); + if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains(&config.nick) { let channel = message.split("PRIVMSG ").nth(1).and_then(|s| s.splitn(2, ' ').next()).unwrap(); // set the response to varible - let user_message = "The following is a chat log:\n".to_owned() + message.split(&format!("PRIVMSG {} :", channel.to_string())).nth(1).unwrap() + "\nRespond funny, completely insane, and hyperactive as you are chatting as GIR from Invader Zim: \n\n"; - let parts: Vec<&str> = message.splitn(2, ' ').collect(); + let user_message = format!("The following is a chat log:\n{}\nRespond {} as you are chatting as {}: \n\n", + message.split(&format!("PRIVMSG {} :", channel.to_string())).nth(1).unwrap(), + config.accents, + config.personalities + ); + let parts: Vec<&str> = message.splitn(2, ' ').collect(); let username = parts[0].trim_start_matches(':').split("!").next().unwrap(); let rt = tokio::runtime::Runtime::new().unwrap(); @@ -23,7 +39,10 @@ impl Command for Ai { } } async fn ai(user_message: &str, username: &str, channel: &str) -> Vec { - let api_key = "sk-*"; // set this from config + let config_str = std::fs::read_to_string("config.toml").unwrap(); + let config_value = config_str.parse::().unwrap(); + let config: Config = config_value.try_into().unwrap(); + let api_key = config.openai; // set this from config let client = Client::new().with_api_key(api_key); println!("[?] PROMPT: {}: {}", username, user_message);