added some color
This commit is contained in:
parent
1aa5c4dc66
commit
e3d403f49f
@ -14,4 +14,5 @@ regex = "1.7.1"
|
||||
toml = "0.7.2"
|
||||
serde = "1.0.152"
|
||||
tokio-openssl = "0.6.3"
|
||||
colored = "2"
|
||||
colored = "2"
|
||||
socks = "0.3.4"
|
15
src/main.rs
15
src/main.rs
@ -13,11 +13,13 @@ mod modules {
|
||||
pub mod kill;
|
||||
pub mod ai;
|
||||
pub mod invade;
|
||||
pub mod test;
|
||||
}
|
||||
|
||||
use modules::ai::Ai; // FIX THIS BS
|
||||
use modules::ping::PingCommand;
|
||||
use modules::invade::InvadeCommand;
|
||||
//use modules::test::TestCommand;
|
||||
use modules::kill::KillCommand; // ...
|
||||
use crate::modules::Command;
|
||||
|
||||
@ -70,12 +72,12 @@ fn main() {
|
||||
let message = received.trim();
|
||||
|
||||
//debug chat
|
||||
println!("{}", received); // ADD COLORS
|
||||
println!("{} {}","[%] DEBUG:".bold().green(), received.purple());
|
||||
|
||||
|
||||
// RESPOND TO PINGS
|
||||
if message.starts_with("PING") {
|
||||
println!("[%] PONG {}", config.nick.blue());
|
||||
println!("{} {}","[%] PONG:".bold().green(), config.nick.blue()); // DEBUG
|
||||
ssl_stream.write_all("PONG ircd.chat\r\n".as_bytes()).unwrap();
|
||||
continue; // skip processing the PING message further
|
||||
}
|
||||
@ -84,6 +86,7 @@ fn main() {
|
||||
let ping_command = PingCommand;
|
||||
let kill_command = KillCommand;
|
||||
let invade_command = InvadeCommand;
|
||||
//let test_command = TestCommand;
|
||||
let ai = Ai;
|
||||
|
||||
// ADMIN MODULES
|
||||
@ -91,7 +94,7 @@ fn main() {
|
||||
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.to_string()) {
|
||||
println!("[!] UNAUTHORIZED: {}", username.red());
|
||||
println!("{} {}","[!] UNAUTHORIZED:".bold().clear().on_red(), username.red().bold());
|
||||
continue; // ...
|
||||
}
|
||||
if message.contains(":%ping") {
|
||||
@ -106,7 +109,11 @@ fn main() {
|
||||
for response in invade_command.handle(message) {
|
||||
ssl_stream.write_all(response.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
} //else if message.contains(":%test") {
|
||||
// for response in test_command.handle(message) {
|
||||
// ssl_stream.write_all(response.as_bytes()).unwrap();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
// Check if the message is user and respond via ai
|
||||
|
@ -4,6 +4,8 @@ use regex::Regex;
|
||||
use crate::modules::Command;
|
||||
use toml::Value;
|
||||
use serde::Deserialize;
|
||||
use colored::*;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Config {
|
||||
nick: String,
|
||||
@ -45,7 +47,7 @@ async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
|
||||
let api_key = config.openai; // set this from config
|
||||
|
||||
let client = Client::new().with_api_key(api_key);
|
||||
println!("[?] PROMPT: {}: {}", username, user_message);
|
||||
println!("{} {} {}: {}", "[?]".on_green().bold(), "PROMPT:".green().bold(), username, user_message);
|
||||
let chat_request = CreateCompletionRequestArgs::default()
|
||||
.prompt(user_message)
|
||||
.max_tokens(40_u16)
|
||||
@ -57,10 +59,10 @@ async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
|
||||
.create(chat_request)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("[+] RESPONSE: {}", chat_response.choices.first().unwrap().text);
|
||||
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*|[mM][eE]:?\s"#).unwrap(); // THIS IS FUCKING UP EVERYTHING
|
||||
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"#,
|
||||
@ -80,7 +82,7 @@ async fn ai(user_message: &str, username: &str, channel: &str) -> Vec<String> {
|
||||
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, username, line));
|
||||
responses.push(format!("PRIVMSG {} :\x0313{}\x0f: {}\r\n", channel, username, line));
|
||||
}
|
||||
|
||||
responses
|
||||
|
@ -1,11 +1,13 @@
|
||||
use crate::modules::Command;
|
||||
|
||||
use std::io::{Write};
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::net::TcpStream;
|
||||
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
use serde::Deserialize;
|
||||
use toml::Value;
|
||||
use colored::*;
|
||||
|
||||
|
||||
#[derive(Clone, Deserialize)]
|
||||
struct Config {
|
||||
invaders: Vec<String>,
|
||||
@ -29,6 +31,7 @@ impl Command for InvadeCommand {
|
||||
let config_value = config_str.parse::<Value>().unwrap();
|
||||
let config: Config = config_value.try_into().unwrap();
|
||||
|
||||
|
||||
for invader in &config.invaders[0..num_invaders] {
|
||||
let thread_channel = invadechannel.to_string();
|
||||
let thread_invader = invader.to_string();
|
||||
@ -49,19 +52,31 @@ impl Command for InvadeCommand {
|
||||
ssl_stream.write_all(msg.as_bytes()).unwrap();
|
||||
|
||||
loop {
|
||||
let mut buffer = [0; 512];
|
||||
match ssl_stream.ssl_read(&mut buffer) {
|
||||
|
||||
|
||||
|
||||
let mut buf = [0; 512];
|
||||
match ssl_stream.ssl_read(&mut buf) {
|
||||
Ok(0) => break,
|
||||
Ok(n) => {
|
||||
let message = String::from_utf8_lossy(&buffer[..n]);
|
||||
let received = String::from_utf8_lossy(&buf[0..n]);
|
||||
let message = received.trim();
|
||||
|
||||
//debug chat
|
||||
println!("{} {} {}","[%] DEBUG:".bold().green(), thread_invader.green(), received.blue());
|
||||
|
||||
if message.starts_with("PING") {
|
||||
let response = message.replace("PING", "PONG");
|
||||
println!("[%] PONG {}", thread_invader);
|
||||
println!("{} {}","[%] PONG:".bold().green(), thread_invader.blue());
|
||||
ssl_stream.write_all(response.as_bytes()).unwrap();
|
||||
}
|
||||
if message.contains("PRIVMSG") && message.contains(":%%fuck") {
|
||||
let response = format!("PRIVMSG {} :FUCKFUCKFUCK\r\n", thread_channel);
|
||||
ssl_stream.write_all(response.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error reading from server: {}", e);
|
||||
eprintln!("{} {}","[!] ERROR FROM SERVER:".on_red(), e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -69,7 +84,7 @@ impl Command for InvadeCommand {
|
||||
});
|
||||
}
|
||||
|
||||
response.push(format!("PRIVMSG {} :INVADING WITH {} INVADERS...\r\n", channel, num_invaders));
|
||||
response.push(format!("PRIVMSG {} :\x0304,01[!] INVADING {} WITH {} INVADERS...\x0f\r\n", channel, invadechannel, num_invaders));
|
||||
}
|
||||
|
||||
response
|
||||
|
0
src/modules/test.rs
Normal file
0
src/modules/test.rs
Normal file
Loading…
Reference in New Issue
Block a user