mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 21:48:03 +03:00
more library tricks
This commit is contained in:
parent
e548d85841
commit
17b2511217
19
src/chat.rs
19
src/chat.rs
@ -8,13 +8,24 @@ use colored::{Color, Colorize};
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
proto::{connect, read_messages, send_message, send_message_spoof_auth},
|
proto::{connect, read_messages, send_message, send_message_spoof_auth},
|
||||||
IP_REGEX,
|
|
||||||
util::sanitize_text,
|
util::sanitize_text,
|
||||||
COLORED_USERNAMES,
|
|
||||||
DATE_REGEX,
|
|
||||||
config::Context
|
config::Context
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref DATE_REGEX: Regex = Regex::new(r"\[(.*?)\] (.*)").unwrap();
|
||||||
|
pub static ref IP_REGEX: Regex = Regex::new(r"\{(.*?)\} (.*)").unwrap();
|
||||||
|
pub static ref COLORED_USERNAMES: Vec<(Regex, Color)> = vec![
|
||||||
|
(Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), Color::Green), // bRAC
|
||||||
|
(Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), Color::BrightRed), // CRAB
|
||||||
|
(Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), Color::Magenta), // Mefidroniy
|
||||||
|
(Regex::new(r"<(.*?)> (.*)").unwrap(), Color::Cyan), // clRAC
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "pretty"))]
|
#[cfg(not(feature = "pretty"))]
|
||||||
pub mod minimal_tui;
|
pub mod minimal_tui;
|
||||||
#[cfg(not(feature = "pretty"))]
|
#[cfg(not(feature = "pretty"))]
|
||||||
@ -249,7 +260,7 @@ pub fn format_message(ctx: Arc<Context>, message: String) -> Option<String> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_username_color(message: &str) -> Option<(String, String, Color)> {
|
pub fn find_username_color(message: &str) -> Option<(String, String, Color)> {
|
||||||
for (re, color) in COLORED_USERNAMES.iter() {
|
for (re, color) in COLORED_USERNAMES.iter() {
|
||||||
if let Some(captures) = re.captures(message) {
|
if let Some(captures) = re.captures(message) {
|
||||||
return Some((captures[1].to_string(), captures[2].to_string(), color.clone()))
|
return Some((captures[1].to_string(), captures[2].to_string(), color.clone()))
|
||||||
|
@ -17,7 +17,9 @@ use std::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::{
|
super::{
|
||||||
config::Context, proto::{connect, read_messages}, util::{char_index_to_byte_index, string_chunks}
|
config::Context,
|
||||||
|
proto::{connect, read_messages},
|
||||||
|
util::{char_index_to_byte_index, string_chunks}
|
||||||
}, format_message, on_send_message
|
}, format_message, on_send_message
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
mod proto;
|
pub mod config;
|
||||||
|
pub mod chat;
|
||||||
pub use proto::*;
|
pub mod util;
|
||||||
|
pub mod proto;
|
27
src/main.rs
27
src/main.rs
@ -1,30 +1,9 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use colored::Color;
|
use bRAC::config::{configure, get_config_path, load_config, Args, Context};
|
||||||
use config::{configure, get_config_path, load_config, Args, Context};
|
use bRAC::proto::{connect, read_messages, send_message};
|
||||||
use proto::{connect, read_messages, send_message};
|
use bRAC::chat::run_main_loop;
|
||||||
use regex::Regex;
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use chat::run_main_loop;
|
|
||||||
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref DATE_REGEX: Regex = Regex::new(r"\[(.*?)\] (.*)").unwrap();
|
|
||||||
static ref IP_REGEX: Regex = Regex::new(r"\{(.*?)\} (.*)").unwrap();
|
|
||||||
static ref COLORED_USERNAMES: Vec<(Regex, Color)> = vec![
|
|
||||||
(Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), Color::Green), // bRAC
|
|
||||||
(Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), Color::BrightRed), // CRAB
|
|
||||||
(Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), Color::Magenta), // Mefidroniy
|
|
||||||
(Regex::new(r"<(.*?)> (.*)").unwrap(), Color::Cyan), // clRAC
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
mod config;
|
|
||||||
mod chat;
|
|
||||||
mod proto;
|
|
||||||
mod util;
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user