From 2812e51a9b84e7a53c85bf3f5e47a977286aa748 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Sun, 9 Feb 2025 21:53:13 +0300 Subject: [PATCH] commands in readme --- README.md | 6 ++++++ src/main.rs | 29 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a2043f7..f665445 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ better RAC client - using tor proxy by default - coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc) - RACv1.99.x compatible +- cheat commands ![image](https://github.com/user-attachments/assets/a2858662-50f1-4554-949c-f55addf48fcc) @@ -48,6 +49,11 @@ regex - `<(.*?)> (.*)` \ color - cyan \ example - ` text` +### commands + +/clear - clear chat +/spam *args - spam in chat with text + ## see also - [CRAB - client & server for RAC](https://gitea.bedohswe.eu.org/pixtaded/crab) diff --git a/src/main.rs b/src/main.rs index dc1b14a..8ccb164 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,15 +179,17 @@ fn format_message(message: String) -> Option { }) } -fn on_command(host: &str, command: &str) -> Result<(), Box> { +fn on_command(host: &str, command: &str, input: Arc>) -> Result<(), Box> { let command = command.trim_start_matches("/"); let (command, args) = command.split_once(" ").unwrap_or((&command, "")); let args = args.split(" ").collect::>(); if command == "clear" { send_message(host, &format!("\r\x1B[1A{}", " ".repeat(64)).repeat(MAX_MESSAGES))?; + // *input.write().unwrap() = "/ заспамлено)))".to_string(); } else if command == "spam" { send_message(host, &format!("\r\x1B[1A{}{}", args.join(" "), " ".repeat(10)).repeat(MAX_MESSAGES))?; + // *input.write().unwrap() = "/ заспамлено)))".to_string(); } Ok(()) @@ -260,23 +262,26 @@ fn main() { match key.unwrap() { Key::Char('\n') => { let message = input.read().unwrap().clone(); + + { + let input_len = input.read().unwrap().len(); + write!(terminal.lock().unwrap(), + "{}{}{}", + cursor::Left(1).to_string().repeat(input_len), + " ".repeat(input_len), + cursor::Left(1).to_string().repeat(input_len) + ).unwrap(); + terminal.lock().unwrap().flush().unwrap(); + input.write().unwrap().clear(); + } + if !message.is_empty() { if message.starts_with("/") { - on_command(&host, &message).expect("Error on command"); + on_command(&host, &message, input.clone()).expect("Error on command"); } else { send_message(&host, &format!("{}<{}> {}", MAGIC_KEY, name, message)).expect("Error sending message"); } } - - let input_len = input.read().unwrap().len(); - write!(terminal.lock().unwrap(), - "{}{}{}", - cursor::Left(1).to_string().repeat(input_len), - " ".repeat(input_len), - cursor::Left(1).to_string().repeat(input_len) - ).unwrap(); - terminal.lock().unwrap().flush().unwrap(); - input.write().unwrap().clear(); } Key::Backspace => { if input.write().unwrap().pop().is_some() {