commands in readme

This commit is contained in:
MeexReay 2025-02-09 21:53:13 +03:00
parent b2f11ca60a
commit 2812e51a9b
2 changed files with 23 additions and 12 deletions

View File

@ -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 - `<nick> 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)

View File

@ -179,15 +179,17 @@ fn format_message(message: String) -> Option<String> {
})
}
fn on_command(host: &str, command: &str) -> Result<(), Box<dyn Error>> {
fn on_command(host: &str, command: &str, input: Arc<RwLock<String>>) -> Result<(), Box<dyn Error>> {
let command = command.trim_start_matches("/");
let (command, args) = command.split_once(" ").unwrap_or((&command, ""));
let args = args.split(" ").collect::<Vec<&str>>();
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() {