updated async /

updated openai to gpt4 comp /
changed completeions to chat/completions
This commit is contained in:
legitnull 2023-03-17 21:25:22 -06:00
parent be85cd2cad
commit eaea7f6c3a
6 changed files with 184 additions and 69 deletions

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
openssl = "0.10.45"
async-openai = "0.6.1"
async-openai = "0.9.3"
tokio = { version = "1.23.0", features = ["full"] }
rand = "0.8.4"
regex = "1.7.1"
@ -19,3 +19,6 @@ tokio-socks = "0.5.1"
socks = "0.3.4"
random_word = "0.3.0"
#leetspeak = "0.2.0"
irc = "0.15.0"
futures = "0.3.27"
futures-util = "0.3.27"

View File

@ -2,11 +2,11 @@ nick = "g1r"
server = "ircd.chat"
port = 6697
password = ""
channels = [ "#tcpdirect", "#macros", "#b0tsh0p" ] #add key access
admin_users = ["s4d", "s4d[m]", "g"] # add host identification
channels = [ "#s4d", "#emo", "#tcpdirect", "#macros", "#b0tsh0p" ] #add key access
admin_users = ["s4d", "sad", "g", "d", "h3x", "kayos", "moony"] # add host identification
ignore_users = ["maple", "aibird", "professorOak", "van"]
openai = "sk-"
model = "text-davinci-003"
model = "gpt-3.5-turbo"
accents = "funny, completely insane, and hyperactive"
personalities = "GIR from Invader Zim"
@ -14,5 +14,4 @@ proxy_server = "127.0.0.1"
proxy_port = 9050
# INVADER SETTINGS
invaders = ["d1b", "z1m", "t4k", "m3mbr4n3", "g4z", "4l4n", "m1yuk1", "purpl3", "r3d", "5p0rk", "t3nn", "l4rb", "ch1nn", "d00ky", "3l", "fl0rb3", "g00ch", "gr4p4", "gr00t", "k00t", "k1m", "krunk", "l4dn4r", "n3n", "p3st0", "p00t"]
proxy_list = "./proxies.txt"

View File

@ -6,6 +6,9 @@ use toml::Value;
use serde::Deserialize;
use colored::*;
use crate::modules::Command;
mod modules {
pub trait Command {
@ -16,15 +19,14 @@ mod modules {
pub mod ai;
pub mod invade;
pub mod test;
//pub mod ai_invade;
pub mod aicode;
}
use modules::ai::Ai; // FIX THIS BS
use modules::ping::PingCommand;
use modules::invade::InvadeCommand;
//use modules::ai_invade::AiInvadeCommand;
use modules::aicode::AiCode;
use modules::kill::KillCommand; // ...
use crate::modules::Command;
#[derive(Deserialize)]
struct Config {
@ -37,7 +39,6 @@ struct Config {
ignore_users: Vec<String>,
}
fn main() {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
@ -48,10 +49,11 @@ fn main() {
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();
// 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);
@ -90,7 +92,7 @@ fn main() {
let ping_command = PingCommand;
let kill_command = KillCommand;
let invade_command = InvadeCommand;
//let ai_invade_command = AiInvadeCommand;
let aicode = AiCode;
//let test_command = TestCommand;
let ai = Ai;
@ -115,11 +117,11 @@ fn main() {
for response in invade_command.handle(message) {
ssl_stream.write_all(response.as_bytes()).unwrap();
}
} //else if message.contains(":%aiinvade") {
// for response in ai_invade_command.handle(message) {
// ssl_stream.write_all(response.as_bytes()).unwrap();
// }
//}
} else if message.contains(":%code") {
for response in aicode.handle(message) {
ssl_stream.write_all(response.as_bytes()).unwrap();
}
}
}
// Check if the message is user and respond via ai

View File

@ -1,10 +1,8 @@
// Check if the message is user and respond via ai
use async_openai::{Client, types::{CreateCompletionRequestArgs}};
use regex::Regex;
use async_openai::{Client, types::{CreateChatCompletionRequestArgs, ChatCompletionRequestMessageArgs, Role}};
use crate::modules::Command;
use toml::Value;
use serde::Deserialize;
use colored::*;
use regex::Regex;
#[derive(Deserialize)]
struct Config {
@ -14,76 +12,96 @@ struct Config {
accents: String,
personalities: String,
}
pub struct Ai;
// setup a prompt and respnse log for training other bots
impl Command for Ai {
fn handle(&self, message: &str) -> Vec<String> {
let mut responses = Vec::new();
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(); // respond to name with and without leet VVV
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 = 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 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();
let cleaned_message = message.replace(&format!("{} ", config.nick), "");
println!("{}", cleaned_message);
let user_message = cleaned_message.split(&format!("PRIVMSG {} :", channel.to_string())).nth(1).unwrap();
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();
let result = rt.block_on(ai(&user_message, &username, &channel));
let result = rt.block_on(ai(&user_message, &username, &channel, &config));
responses.extend(result);
}
responses
}
}
async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
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
async fn ai(user_message: &str, username: &str, channel: &str, config: &Config) -> Vec<String> {
let api_key = &config.openai;
let client = Client::new().with_api_key(api_key);
println!("{} {} {}: {}", "[?]".on_green().bold(), "PROMPT:".green().bold(), username, user_message);
let chat_request = CreateCompletionRequestArgs::default()
.prompt(user_message)
.max_tokens(40_u16)
.model(config.model)
let request = CreateChatCompletionRequestArgs::default()
.model(&config.model)
.messages([
ChatCompletionRequestMessageArgs::default()
.role(Role::System)
.content(format!("Respond {} as you are chatting as {}, The following is a chat message to you from {} dont mention that you are who you are they can see that:", config.accents, config.personalities, username))
.build()
.unwrap(),
ChatCompletionRequestMessageArgs::default()
.role(Role::User)
.content(user_message.to_string())
.build()
.unwrap(),
])
.max_tokens(256_u16)
.build()
.unwrap();
let chat_response = client
.completions()
.create(chat_request)
.await
.unwrap();
println!("{} {} {}","[+]".on_green().bold(), "RESPONSE:".green().bold(), chat_response.choices.first().unwrap().text);
//modify regex for varible username ie G1R g1r GIR gir but as handle nick for bots
let response_text = &chat_response.choices.first().unwrap().text;
let regex = Regex::new(r#""|[gG][1iI][rR]:\s"#).unwrap(); // THIS IS FUCKING UP EVERYTHING
//let nick = &config.nick;
//let regex_str = format!(
// r#""|[{}{}{}]|\b[gG][1iI][rR]:\s*|\b[mM][eE]:?\s"#,
// nick.to_lowercase(),
// nick.to_uppercase(),
// nick.chars().map(|c| match c { /// regex magic nick removal in progress
// 'a' => '4',
// 'e' => '3',
// 'i' => '1',
// 'o' => '0',
// 's' => '5',
// _ => c,
// }).collect::<String>(),
//);
//let regex = Regex::new(&regex_str).unwrap();
let response_text = regex.replace_all(response_text, "").trim().to_string();
let response = client.chat().create(request).await.unwrap();
let response_text = response.choices.first().unwrap().message.content.trim().to_string();
let regex = Regex::new(r#""|[gG][1iI][rR]\s"#).unwrap(); // THIS IS FUCKING UP EVERYTHING
let response_text = regex.replace_all(&response_text, "").trim().to_string();
println!("{}", response_text);
let response_lines = response_text.split("\n").filter(|line| !line.trim().is_empty());
let mut responses = Vec::new();
let mut line_count = 0;
for line in response_lines {
responses.push(format!("PRIVMSG {} :\x0313{}\x0f: {}\r\n", channel, username, line));
if line.contains("*") {
let parts: Vec<&str> = line.split("*").collect();
for (i, part) in parts.iter().enumerate() {
if i % 2 == 1 {
let action = part.to_lowercase();
responses.push(format!("PRIVMSG {} :\x01ACTION {}\x01\r\n", channel, action));
} else {
let message = part.trim().to_string();
responses.push(format!("PRIVMSG {} :{}\r\n", channel, message));
}
}
} else {
let response_line = if line_count == 0 && !line.contains(&username) {
format!("PRIVMSG {} :\x0313{}\x0f: {}\r\n", channel, username, line)
} else {
format!("PRIVMSG {} :{}\r\n", channel, line)
};
responses.push(response_line);
}
line_count += 1;
}
responses
}
}

89
src/modules/aicode.rs Normal file
View File

@ -0,0 +1,89 @@
// Check if the message is user and respond via ai
use async_openai::{Client, types::{CreateCompletionRequestArgs}};
use regex::Regex;
use crate::modules::Command;
use toml::Value;
use serde::Deserialize;
use colored::*;
#[derive(Deserialize)]
struct Config {
nick: String,
openai: String,
}
pub struct AiCode;
// setup a prompt and respnse log for training other bots
impl Command for AiCode {
fn handle(&self, message: &str) -> Vec<String> {
let mut responses = Vec::new();
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(); // respond to name with and without leet VVV
if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains("%code") {
let channel = message.split("PRIVMSG ").nth(1).and_then(|s| s.splitn(2, ' ').next()).unwrap(); // set the response to varible
let user_message = format!("{}\n\n",
message.split(&format!("PRIVMSG {} :%code ", channel.to_string())).nth(1).unwrap(),
);
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();
let result = rt.block_on(ai(&user_message, &username, &channel));
responses.extend(result);
}
responses
}
}
async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
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);
println!("{} {} {}: {}", "[?]".on_green().bold(), "PROMPT:".green().bold(), username, user_message);
let chat_request = CreateCompletionRequestArgs::default()
.prompt(user_message)
.max_tokens(256_u16)
.model("code-davinci-002")
.temperature(0.0)
.top_p(1.0)
.best_of(1)
.logprobs(1)
.frequency_penalty(1.0)
.presence_penalty(1.0)
.build()
.unwrap();
let chat_response = client
.completions()
.create(chat_request)
.await
.unwrap();
println!("{} {} {}","[+]".on_green().bold(), "RESPONSE:".green().bold(), chat_response.choices.first().unwrap().text);
//modify regex for varible username ie G1R g1r GIR gir but as handle nick for bots
let response_text = &chat_response.choices.first().unwrap().text;
//let nick = &config.nick;
//let regex_str = format!(
// r#""|[{}{}{}]|\b[gG][1iI][rR]:\s*|\b[mM][eE]:?\s"#,
// nick.to_lowercase(),
// nick.to_uppercase(),
// nick.chars().map(|c| match c { /// regex magic nick removal in progress
// 'a' => '4',
// 'e' => '3',
// 'i' => '1',
// 'o' => '0',
// 's' => '5',
// _ => c,
// }).collect::<String>(),
//);
//let regex = Regex::new(&regex_str).unwrap();
let response_lines = response_text.split("\n").filter(|line| !line.trim().is_empty());
let mut responses = Vec::new();
for line in response_lines {
responses.push(format!("PRIVMSG {} : {}\r\n", channel, line));
}
responses
}

View File

@ -6,7 +6,11 @@ use openssl::ssl::{SslConnector, SslMethod};
use serde::Deserialize;
use toml::{Value, to_string};
use colored::*;
use socks::*;
//use anyhow::Result;
//use socks5_proxy::{client, Addr};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
// add better error handling
// add ai invasion
// add proxy support