Compare commits

...

8 Commits

Author SHA1 Message Date
5b23a3bd70 Fix: fix and improve get_config_path function 2025-06-19 14:59:14 +03:00
c8b2c7e541 write about using as crate 2025-06-19 13:46:06 +03:00
MeexReay
80e7b8c506
Merge pull request #5 from pansangg/main
add cRACk user agent support
2025-06-19 08:36:44 +03:00
pansangg
aaee249f56
Update user_agents.md 2025-06-19 02:50:14 +07:00
pansangg
9675dfe87f
Update mod.rs 2025-06-19 02:48:50 +07:00
pansangg
32cf3839bf
Update user_agents.md 2025-06-19 02:48:29 +07:00
pansangg
5029b51cf6
Update user_agents.md 2025-06-19 02:41:33 +07:00
pansangg
c9673807d9
Update mod.rs 2025-06-19 02:39:10 +07:00
6 changed files with 104 additions and 37 deletions

View File

@ -87,6 +87,7 @@ messages starting with a slash are sent to chat only if the `--disable-commands`
- [Compiling](docs/compiling.md) - [Compiling](docs/compiling.md)
- [User agents](docs/user_agents.md) - [User agents](docs/user_agents.md)
- [Using as crate](docs/crate.md)
- [Authenticated mode](docs/auth_mode.md) - [Authenticated mode](docs/auth_mode.md)
- [WRAC protocol (v2.0)](docs/wrac.md) - [WRAC protocol (v2.0)](docs/wrac.md)
- [About RAC URL](docs/url.md) - [About RAC URL](docs/url.md)

60
docs/crate.md Normal file
View File

@ -0,0 +1,60 @@
# Using as crate
This article describes how to use the client as rust crate
## Installation
To use exact version:
```toml
[dependencies.bRAC]
git = "https://github.com/MeexReay/bRAC"
tag = "0.1.2+2.0"
default-features = false
```
To use with latest changes:
```toml
[dependencies.bRAC]
git = "https://github.com/MeexReay/bRAC"
default-features = false
```
`default-features = false` here removes GTK4 gui from installation.
## Usage
As the code structure was changed like about gazillion times,
you need to explore it yourself, if you are using an old version.
Here is example of usage on commit [80e7b8c](https://github.com/MeexReay/bRAC/commit/80e7b8c50642f9b76be06980305ed03253858d0c)
```rust
use bRAC::proto::*;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut conn = connect("rac://meex.lol", None)?; // read docs/url.md
send_message(&mut conn, "<dude> hi RAC-loving kikes!")?;
register_user(&mut conn, "dude", "password")?;
send_message_auth(&mut conn, "dude", "password", "my auth message")?;
send_message_spoof_auth(&mut conn, "<dude> this message totally fucks auth system")?;
let (mut all_messages, last_size) = read_messages(&mut conn, 10, 0, false)?.unwrap(); // limits with 10 messages
/* imagine that new messages were written here */
let (mut new_messages, last_size) = read_messages(&mut conn, 10, last_size, true)?.unwrap(); // chunked reading!
all_messages.append(&mut new_messages);
println!("all_messages: {all_messages:?}. last_size: {last_size}");
Ok(())
}
```
## See more
- [rac-rs - A Rust client library for RAC protocol. (with async support)](https://github.com/kostya-zero/rac-rs)

View File

@ -11,6 +11,7 @@ Here are listed the most common clients, and their name colors in the chat.
| [bRAC](https://github.com/MeexReay/bRAC) | 리㹰<{name}> {text} | `\uB9AC\u3E70<(.*?)> (.*)` | green | [bRAC](https://github.com/MeexReay/bRAC) | 리㹰<{name}> {text} | `\uB9AC\u3E70<(.*?)> (.*)` | green
| [CRAB](https://gitea.bedohswe.eu.org/pixtaded/crab) | ═══<{name}> {text} | `\u2550\u2550\u2550<(.*?)> (.*)` | light red | [CRAB](https://gitea.bedohswe.eu.org/pixtaded/crab) | ═══<{name}> {text} | `\u2550\u2550\u2550<(.*?)> (.*)` | light red
| [Mefidroniy](https://github.com/OctoBanon-Main/mefedroniy-client) | °ʘ<{name}> {text} | `\u00B0\u0298<(.*?)> (.*)` | light magenta | [Mefidroniy](https://github.com/OctoBanon-Main/mefedroniy-client) | °ʘ<{name}> {text} | `\u00B0\u0298<(.*?)> (.*)` | light magenta
| [cRACk](https://github.com/pansangg/cRACk) | ⁂<{name}> {text} | `\u2042<(.*?)> (.*)` | gold
| clRAC | <{name}> {text} | `<(.*?)> (.*)` | cyan | clRAC | <{name}> {text} | `<(.*?)> (.*)` | cyan
## developer notes ## developer notes

23
examples/protocol.rs Normal file
View File

@ -0,0 +1,23 @@
use bRAC::proto::*;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut conn = connect("rac://meex.lol", None)?;
send_message(&mut conn, "<dude> hi RAC-loving kikes!")?;
register_user(&mut conn, "dude", "password")?;
send_message_auth(&mut conn, "dude", "password", "my auth message")?;
send_message_spoof_auth(&mut conn, "<dude> this message totally fucks auth system")?;
let (mut all_messages, last_size) = read_messages(&mut conn, 10, 0, false)?.unwrap(); // limits with 10 messages
/* imagine that new messages were written here */
let (mut new_messages, last_size) = read_messages(&mut conn, 10, last_size, true)?.unwrap(); // chunked reading!
all_messages.append(&mut new_messages);
println!("all_messages: {all_messages:?}. last_size: {last_size}");
Ok(())
}

View File

@ -66,44 +66,25 @@ pub struct Config {
pub debug_logs: bool, pub debug_logs: bool,
} }
pub fn get_config_path() -> PathBuf {
let mut config_dir = PathBuf::from_str(".").unwrap();
#[cfg(not(target_os = "windows"))]
if let Some(dir) = {
let home_dir = {
use homedir::my_home;
my_home().ok().flatten()
};
#[cfg(target_os = "linux")]
let config_dir = {
let home_dir = home_dir.map(|o| o.join("bRAC"));
home_dir.map(|o| o.join(".config"))
};
#[cfg(target_os = "macos")]
let config_dir = {
let home_dir = home_dir.map(|o| o.join("bRAC"));
home_dir.map(|o| o.join(".config"))
};
config_dir
} {
config_dir = dir;
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
if let Some(dir) = { pub fn get_config_path() -> PathBuf {
use std::env; use std::env;
env::var("APPDATA") env::var("APPDATA")
.ok() .ok()
.and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC"))) .and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC")))
} { .unwrap_or("bRAC/config.yml".into())
config_dir = dir;
} }
config_dir.join("config.yml") #[cfg(any(target_os = "macos", target_os = "linux"))]
pub fn get_config_path() -> PathBuf {
use homedir::my_home;
my_home()
.ok()
.flatten()
.map(|o| o.join(".config"))
.map(|o| o.join("bRAC"))
.unwrap_or("bRAC".into())
.join("config.yml")
} }
pub fn load_config(path: PathBuf) -> Config { pub fn load_config(path: PathBuf) -> Config {

View File

@ -41,6 +41,7 @@ lazy_static! {
(Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), "#70fa7a".to_string()), // bRAC (Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), "#70fa7a".to_string()), // bRAC
(Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), "#fa7070".to_string()), // CRAB (Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), "#fa7070".to_string()), // CRAB
(Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), "#da70fa".to_string()), // Mefidroniy (Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), "#da70fa".to_string()), // Mefidroniy
(Regex::new(r"\u{2042}<(.*?)> (.*)").unwrap(), "#f5f543".to_string()), // cRACk
(Regex::new(r"<(.*?)> (.*)").unwrap(), "#70fadc".to_string()), // clRAC (Regex::new(r"<(.*?)> (.*)").unwrap(), "#70fadc".to_string()), // clRAC
]; ];