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]
name = "kmsbot"
name = "g1r"
version = "0.1.0"
edition = "2021"
@ -14,4 +14,3 @@ regex = "1.7.1"
toml = "0.7.2"
serde = "1.0.152"
tokio-openssl = "0.6.3"
webpki = "0.22.0"

View File

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

View File

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

View File

@ -1,9 +1,7 @@
use crate::modules::Command;
use std::cell::RefCell;
use std::io::{Write};
use std::net::TcpStream;
use std::rc::Rc;
use openssl::ssl::{SslConnector, SslMethod};
use serde::Deserialize;
@ -24,7 +22,7 @@ impl Command for InvadeCommand {
if message.contains("PRIVMSG") && message.contains(":%invade") {
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 invadechannel = parts[5];
let scream = parts[6];
@ -32,7 +30,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_bots] {
for invader in &config.invaders[0..num_invaders] {
let thread_channel = invadechannel.to_string();
let thread_invader = invader.to_string();
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

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
}
}