fix some bs

This commit is contained in:
legitnull 2023-02-18 16:55:51 -07:00
parent 9f1a92d1b3
commit 4e580d0304
5 changed files with 77 additions and 10 deletions

View File

@ -1,5 +1,5 @@
[package] [package]
name = "kmsbot" name = "g1r"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
@ -14,4 +14,3 @@ regex = "1.7.1"
toml = "0.7.2" toml = "0.7.2"
serde = "1.0.152" serde = "1.0.152"
tokio-openssl = "0.6.3" tokio-openssl = "0.6.3"
webpki = "0.22.0"

View File

@ -4,10 +4,11 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
# TODO # TODO
- multi server - multi server
- add bots
- proxy support - proxy support
- ident rand - ident rand
- bridging
- user log - user log
- user clone - user clone
- console - console
- colors
- scan - scan

View File

@ -105,7 +105,7 @@ fn main() {
for response in invade_command.handle(message) { for response in invade_command.handle(message) {
ssl_stream.write_all(response.as_bytes()).unwrap(); ssl_stream.write_all(response.as_bytes()).unwrap();
} }
} }
} }
// Check if the message is user and respond via ai // Check if the message is user and respond via ai

View File

@ -1,9 +1,7 @@
use crate::modules::Command; use crate::modules::Command;
use std::cell::RefCell;
use std::io::{Write}; use std::io::{Write};
use std::net::TcpStream; use std::net::TcpStream;
use std::rc::Rc;
use openssl::ssl::{SslConnector, SslMethod}; use openssl::ssl::{SslConnector, SslMethod};
use serde::Deserialize; use serde::Deserialize;
@ -24,7 +22,7 @@ impl Command for InvadeCommand {
if message.contains("PRIVMSG") && message.contains(":%invade") { if message.contains("PRIVMSG") && message.contains(":%invade") {
let parts: Vec<&str> = message.split_whitespace().collect(); let parts: Vec<&str> = message.split_whitespace().collect();
let num_bots = parts[4].parse::<u32>().unwrap_or(1) as usize; let num_invaders = parts[4].parse::<u32>().unwrap_or(1) as usize;
let channel = parts[2]; let channel = parts[2];
let invadechannel = parts[5]; let invadechannel = parts[5];
let scream = parts[6]; let scream = parts[6];
@ -32,7 +30,7 @@ impl Command for InvadeCommand {
let config_value = config_str.parse::<Value>().unwrap(); let config_value = config_str.parse::<Value>().unwrap();
let config: Config = config_value.try_into().unwrap(); let config: Config = config_value.try_into().unwrap();
for invader in &config.invaders[0..num_bots] { for invader in &config.invaders[0..num_invaders] {
let thread_channel = invadechannel.to_string(); let thread_channel = invadechannel.to_string();
let thread_invader = invader.to_string(); let thread_invader = invader.to_string();
let config_clone = config.clone(); let config_clone = config.clone();
@ -72,7 +70,7 @@ impl Command for InvadeCommand {
}); });
} }
response.push(format!("PRIVMSG {} :INVADING with {} bots..\r\n", channel, num_bots)); response.push(format!("PRIVMSG {} :INVADING WITH {} INVADERS...\r\n", channel, num_invaders));
} }
response response

69
src/modules/invaders.rs Normal file
View File

@ -0,0 +1,69 @@
use crate::modules::Command;
use std::io::{Write};
use std::net::TcpStream;
use openssl::ssl::{SslConnector, SslMethod};
use serde::Deserialize;
use toml::Value;
use std::thread;
#[derive(Clone, Deserialize)]
struct Config {
invaders: Vec<String>,
server: String,
port: u16,
}
pub struct InvadersCommand;
impl Command for InvadersCommand {
fn handle(&self, message: &str) -> Vec<String> {
let mut response = vec![];
if message.contains("PRIVMSG") && message.contains(":%invaders") {
let parts: Vec<&str> = message.split_whitespace().collect();
let scream = parts[1];
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();
for invader in &config.invaders {
let thread_channel = parts[2].to_string();
let thread_invader = invader.to_string();
let screaming = scream.to_string();
std::thread::spawn(move || {
let stream = TcpStream::connect((config.server.as_str(), config.port)).unwrap();
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
let mut ssl_stream = connector.connect(config.server.as_str(), stream).unwrap();
let msg = format!("PRIVMSG {} :{}\r\n", thread_channel, screaming);
ssl_stream.write_all(msg.as_bytes()).unwrap();
loop {
let mut buffer = [0; 512];
match ssl_stream.ssl_read(&mut buffer) {
Ok(0) => break,
Ok(n) => {
let message = String::from_utf8_lossy(&buffer[..n]);
if message.starts_with("PING") {
let response = message.replace("PING", "PONG");
println!("[%] PONG {}", thread_invader);
ssl_stream.write_all(response.as_bytes()).unwrap();
}
}
Err(e) => {
eprintln!("Error reading from server: {}", e);
break;
}
}
}
});
}
response.push(format!("PRIVMSG {} :Screaming \"{}\" through {} invaders..\r\n", parts[2], scream, config.invaders.len()));
}
response
}
}