mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-07-01 05:53:02 +03:00
refactor: change the avatar regex and documentate it
This commit is contained in:
parent
5eca8e66b6
commit
98ec925d1e
@ -86,6 +86,7 @@ messages starting with a slash are sent to chat only if the `--disable-commands`
|
||||
## docs
|
||||
|
||||
- [Compiling](docs/compiling.md)
|
||||
- [Avatars](docs/avatars.md)
|
||||
- [User agents](docs/user_agents.md)
|
||||
- [Using as crate](docs/crate.md)
|
||||
- [Authenticated mode](docs/auth_mode.md)
|
||||
|
9
docs/avatars.md
Normal file
9
docs/avatars.md
Normal file
@ -0,0 +1,9 @@
|
||||
# avatars
|
||||
|
||||
Client just adds this to the end of every message:
|
||||
```
|
||||
\x06!!AR!!<avatar url>
|
||||
```
|
||||
|
||||
`\x06` is the control char for ACK \
|
||||
`<avatar url>` is the url that leads to the raw image for avatar
|
@ -934,15 +934,15 @@ fn on_add_message(ctx: Arc<Context>, ui: &UiModel, message: String, notify: bool
|
||||
|
||||
let formatting_enabled = ctx.config(|c| c.formatting_enabled);
|
||||
|
||||
let Some(message) = (if formatting_enabled {
|
||||
sanitize_message(message)
|
||||
let Some(sanitized) = (if formatting_enabled {
|
||||
sanitize_message(message.clone())
|
||||
} else {
|
||||
Some(message)
|
||||
Some(message.clone())
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if message.is_empty() {
|
||||
if sanitized.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ 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 AVATAR_REGEX: Regex = Regex::new(r"(.*) !!AR!!(.*)").unwrap();
|
||||
pub static ref AVATAR_REGEX: Regex = Regex::new(r"(.*) \x06!!AR!!(.*)").unwrap();
|
||||
|
||||
pub static ref DEFAULT_USER_AGENT: Regex = Regex::new(r"<(.*?)> (.*)").unwrap();
|
||||
|
||||
@ -271,6 +271,17 @@ pub fn parse_message(
|
||||
return None;
|
||||
}
|
||||
|
||||
let (message, avatar) = if let Some(message) = AVATAR_REGEX.captures(&message) {
|
||||
(
|
||||
message.get(1)?.as_str().to_string(),
|
||||
Some(message.get(2)?.as_str().to_string()),
|
||||
)
|
||||
} else {
|
||||
(message, None)
|
||||
};
|
||||
|
||||
let message = sanitize_message(message)?;
|
||||
|
||||
let date = DATE_REGEX.captures(&message)?;
|
||||
let (date, message) = (
|
||||
date.get(1)?.as_str().to_string(),
|
||||
@ -304,15 +315,6 @@ pub fn parse_message(
|
||||
(message, None)
|
||||
};
|
||||
|
||||
let (message, avatar) = if let Some(message) = AVATAR_REGEX.captures(&message) {
|
||||
(
|
||||
message.get(1)?.as_str().to_string(),
|
||||
Some(message.get(2)?.as_str().to_string()),
|
||||
)
|
||||
} else {
|
||||
(message, None)
|
||||
};
|
||||
|
||||
Some((date, ip, message, nick, avatar))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user