Handle custom Discord emojis
This commit is contained in:
parent
8cadcaf9a6
commit
85c69ae433
11
src/main.rs
11
src/main.rs
|
@ -118,6 +118,7 @@ impl EventHandler for Handler {
|
|||
lazy_static! {
|
||||
static ref PING_RE_1: Regex = Regex::new(r"<@[0-9]+>").unwrap();
|
||||
static ref PING_RE_2: Regex = Regex::new(r"<@![0-9]+>").unwrap();
|
||||
static ref EMOJI_RE: Regex = Regex::new(r"<:\w+:[0-9]+>").unwrap();
|
||||
}
|
||||
|
||||
let mut id_cache: HashMap<u64, String> = HashMap::new();
|
||||
|
@ -181,6 +182,16 @@ impl EventHandler for Handler {
|
|||
}
|
||||
}
|
||||
|
||||
for mat in EMOJI_RE.find_iter(&msg.content) {
|
||||
let slice = &msg.content[mat.start()..mat.end()];
|
||||
|
||||
let parts = slice.split(':').collect::<Vec<&str>>();
|
||||
|
||||
let formatted = format!(":{}:", parts[1]); // ignore the opening bracket in [0]
|
||||
|
||||
replaced = EMOJI_RE.replace(&replaced, formatted).to_string();
|
||||
}
|
||||
|
||||
{
|
||||
use pulldown_cmark::Event::*;
|
||||
use pulldown_cmark::Tag::*;
|
||||
|
|
Loading…
Reference in a new issue