modified ai to be in config for prompt shit
This commit is contained in:
parent
74e856315a
commit
0eed57a000
25
src/main.rs
25
src/main.rs
@ -31,6 +31,8 @@ struct Config {
|
|||||||
nick: String,
|
nick: String,
|
||||||
password: String,
|
password: String,
|
||||||
channels: Vec<String>,
|
channels: Vec<String>,
|
||||||
|
admin_users: Vec<String>,
|
||||||
|
ignore_users: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -39,31 +41,26 @@ fn main() {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// PUT CONFIG IN A SEPRATE FILE IE: CONFIG.TOML
|
// LOAD CONFIG
|
||||||
// read the contents of the config file into a string
|
|
||||||
let config_str = std::fs::read_to_string("config.toml").unwrap();
|
let config_str = std::fs::read_to_string("config.toml").unwrap();
|
||||||
|
|
||||||
// parse the string into a toml::Value
|
|
||||||
let config_value = config_str.parse::<Value>().unwrap();
|
let config_value = config_str.parse::<Value>().unwrap();
|
||||||
|
|
||||||
// deserialize the value into a Config struct
|
|
||||||
let config: Config = config_value.try_into().unwrap();
|
let config: Config = config_value.try_into().unwrap();
|
||||||
|
// GIVE THE SERVER A SLOPPPY SPAM OF RETARDEDNESS
|
||||||
let stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).unwrap();; // DONT DO DRUGS YOU WILL END UP LIKE ME
|
let stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).unwrap();
|
||||||
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
|
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 mut ssl_stream = connector.connect(&config.server, stream).unwrap();
|
||||||
let nick_command = format!("NICK {}_\r\n", config.nick); //setup passwords
|
let nick_command = format!("NICK {}_\r\n", config.nick); //setup passwords
|
||||||
let user_command = format!("USER {} 0 * :{}\r\n", config.nick, config.nick);
|
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(nick_command.as_bytes()).unwrap();
|
||||||
ssl_stream.write_all(user_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);
|
let identify_command = format!("PRIVMSG NickServ :IDENTIFY {} {}\r\n", config.nick, config.password);
|
||||||
ssl_stream.write(identify_command.as_bytes()).unwrap();
|
ssl_stream.write(identify_command.as_bytes()).unwrap();
|
||||||
let channels = config.channels.join(",");
|
let channels = config.channels.join(",");
|
||||||
let join_command = format!("JOIN {}\r\n", channels);
|
let join_command = format!("JOIN {}\r\n", channels);
|
||||||
|
|
||||||
let admin_users = vec!["s4d", "s4d[m]"]; // ADMINS
|
let admin_users = config.admin_users; // ADMINS
|
||||||
let ignored_users = vec!["maple", "aibird", "proffesserOak"]; // IGNORED
|
let ignored_users = config.ignore_users; // IGNORED
|
||||||
// ...
|
// ...
|
||||||
ssl_stream.write_all(join_command.as_bytes()).unwrap();
|
ssl_stream.write_all(join_command.as_bytes()).unwrap();
|
||||||
|
|
||||||
@ -95,7 +92,7 @@ fn main() {
|
|||||||
if message.starts_with(":") && message.contains(" :%") {
|
if message.starts_with(":") && message.contains(" :%") {
|
||||||
let parts: Vec<&str> = message.splitn(2, ' ').collect(); // Check if user is admin_user
|
let parts: Vec<&str> = message.splitn(2, ' ').collect(); // Check if user is admin_user
|
||||||
let username = parts[0].trim_start_matches(':').split("!").next().unwrap();
|
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);
|
println!("[!] UNAUTHORIZED: {}", username);
|
||||||
continue; // ...
|
continue; // ...
|
||||||
}
|
}
|
||||||
@ -111,7 +108,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the message is user and respond via ai
|
// 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();
|
let channel = message.split("PRIVMSG ").nth(1).and_then(|s| s.splitn(2, ' ').next()).unwrap();
|
||||||
if !channels.contains(&channel) {
|
if !channels.contains(&channel) {
|
||||||
continue;
|
continue;
|
||||||
@ -119,7 +116,7 @@ fn main() {
|
|||||||
// extract the username from the first part and check if ignored
|
// 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 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();
|
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);
|
println!("[!] IGNORED: {}", username);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,32 @@
|
|||||||
use async_openai::{Client, types::{CreateCompletionRequestArgs}};
|
use async_openai::{Client, types::{CreateCompletionRequestArgs}};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use crate::modules::Command;
|
use crate::modules::Command;
|
||||||
|
use toml::{from_str, Value};
|
||||||
|
use serde::Deserialize;
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Config {
|
||||||
|
nick: String,
|
||||||
|
channels: Vec<String>,
|
||||||
|
openai: String,
|
||||||
|
accents: String,
|
||||||
|
personalities: String,
|
||||||
|
}
|
||||||
pub struct Ai;
|
pub struct Ai;
|
||||||
|
|
||||||
impl Command for Ai {
|
impl Command for Ai {
|
||||||
fn handle(&self, message: &str) -> Vec<String> {
|
fn handle(&self, message: &str) -> Vec<String> {
|
||||||
let mut responses = Vec::new();
|
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::<Value>().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 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 user_message = format!("The following is a chat log:\n{}\nRespond {} as you are chatting as {}: \n\n",
|
||||||
let parts: Vec<&str> = message.splitn(2, ' ').collect();
|
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 username = parts[0].trim_start_matches(':').split("!").next().unwrap();
|
||||||
|
|
||||||
let rt = tokio::runtime::Runtime::new().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<String> {
|
async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
|
||||||
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::<Value>().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);
|
let client = Client::new().with_api_key(api_key);
|
||||||
println!("[?] PROMPT: {}: {}", username, user_message);
|
println!("[?] PROMPT: {}: {}", username, user_message);
|
||||||
|
Loading…
Reference in New Issue
Block a user