Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
fix cq text translate
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Dec 8, 2023
1 parent adb404d commit 9064658
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/cqtool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,37 @@ pub fn make_kook_text(text:&str) -> String {
}

fn reformat_dates(before: &str) -> String {
lazy_static! {
static ref AT_REGEX : Regex = Regex::new(
r"\(met\)(?P<qq>(\d+)|(all))\(met\)"
).unwrap();

fn kook_msg_f(msg: &str) -> String {
let mut ret = String::new();
let mut is_f = false;
for ch in msg.chars() {
if is_f {
is_f = false;
ret.push(ch);
}else if ch == '\\' {
is_f = true
}else {
ret.push(ch);
}
}
return ret;
}
let after = AT_REGEX.replace_all(before, "[CQ:at,qq=$qq]").to_string();
let mut ret = String::new();
let mut is_f = false;
for ch in after.chars() {
if is_f {
is_f = false;
ret.push(ch);
}else if ch == '\\' {
is_f = true
}else {
ret.push(ch);
let sp = before.split("(met)");
let mut index = 0;
for it in sp{
if index % 2 == 0 {
ret.push_str(&cq_text_encode(&kook_msg_f(it)));
} else {
if it == "all" {
ret.push_str("[CQ:at,qq=all]");
}else{
ret.push_str(&format!("[CQ:at,qq={}]", it));
}
}
index += 1;
}
ret
}
Expand Down

0 comments on commit 9064658

Please sign in to comment.