cargo.toml & password authentication

This commit is contained in:
legitnull 2023-02-17 03:50:15 -07:00
parent 33936366ae
commit 74e856315a
3 changed files with 42 additions and 21 deletions

View File

@ -11,4 +11,5 @@ async-openai = "0.6.1"
tokio = { version = "1.23.0", features = ["full"] }
rand = "0.8.4"
regex = "1.7.1"
config = "0.13.3"
toml = "0.7.2"
serde = "1.0.152"

View File

@ -3,13 +3,13 @@ use std::net::TcpStream;
use std::time::{Instant, Duration};
use std::fs;
use std::thread;
use toml::Value;
use std::io::{self, Write};
use regex::Regex;
use rand::{thread_rng, Rng};
use openssl::ssl::{SslMethod, SslConnector, SslStream};
use async_openai::{Client, types::{CreateCompletionRequestArgs, ResponseFormat}};
use toml::{from_str, Value};
use serde::Deserialize;
mod modules {
pub trait Command {
fn handle(&self, message: &str) -> Vec<String>;
@ -18,33 +18,53 @@ mod modules {
pub mod kill;
pub mod ai;
}
use modules::ai::Ai;
use modules::ai::Ai; // FIX THIS BS
use modules::ping::PingCommand;
use modules::kill::KillCommand;
use modules::kill::KillCommand; // ...
use crate::modules::Command;
#[derive(Deserialize)]
struct Config {
server: String,
port: u16,
nick: String,
password: String,
channels: Vec<String>,
}
fn main() {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
// PUT CONFIG IN A SEPRATE FILE IE: CONFIG.TOML
// read the contents of the config file into a string
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();
// 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
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
// PUT CONFIG IN A SEPRATE FILE IE: YAML, JSON, CONFIG, TOML12
let stream = TcpStream::connect("ircd.chat:6697").unwrap(); // setup tor & custom masking
let mut ssl_stream = connector.connect("ircd.chat", stream).unwrap();
let nick_command = "NICK g1r\r\n"; // set SASL Passwords User Nicks
let user_command = "USER g1r 0 * :g1r\r\n";
let channels = vec!["#tcpdirect", "#macros"]; // CHANNELS
let join_command = format!("JOIN {}\r\n", channels.join(","));
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
// ...
ssl_stream.write_all(nick_command.as_bytes()).unwrap();
ssl_stream.write_all(user_command.as_bytes()).unwrap();
ssl_stream.write_all(join_command.as_bytes()).unwrap();
let mut buf = [0; 512];

View File

@ -9,7 +9,7 @@ impl Command for Ai {
fn handle(&self, message: &str) -> Vec<String> {
let mut responses = Vec::new();
if message.starts_with(":") && message.contains("PRIVMSG ") && message.contains("g1r") {
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(); // 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 username = parts[0].trim_start_matches(':').split("!").next().unwrap();
@ -23,7 +23,7 @@ impl Command for Ai {
}
}
async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
let api_key = "sk-*"; // set this from config and add rotatation
let api_key = "sk-*"; // set this from config
let client = Client::new().with_api_key(api_key);
println!("[?] PROMPT: {}: {}", username, user_message);
@ -39,9 +39,9 @@ async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
.await
.unwrap();
println!("[+] RESPONSE: {}", 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*|[mM][eE]:?\s"#).unwrap();
let regex = Regex::new(r#""|[gG][1iI][rR]:\s*|[mM][eE]:?\s"#).unwrap();
let response_text = regex.replace_all(response_text, "").trim().to_string();
let response_lines = response_text.split("\n").filter(|line| !line.trim().is_empty());
let mut responses = Vec::new();