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

Commit

Permalink
支持onebot协议的缓存机制
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Oct 24, 2023
1 parent 0e47f86 commit a3de7d4
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 73 deletions.
17 changes: 15 additions & 2 deletions src/cqtool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ pub fn cq_params_encode(data:&str) -> String {
return ret_str;
}

pub fn to_json_str(val:&serde_json::Value) -> String {
if val.is_i64() {
return val.as_i64().unwrap().to_string();
}
if val.is_u64() {
return val.as_u64().unwrap().to_string();
}
if val.is_string() {
return val.as_str().unwrap().to_string();
}
return "".to_owned();
}

pub fn arr_to_cq_str(msg_json: & serde_json::Value) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
let mut ret:String = String::new();
if msg_json.is_string() {
Expand All @@ -60,10 +73,10 @@ pub fn arr_to_cq_str(msg_json: & serde_json::Value) -> Result<String, Box<dyn st
if nodes.is_object() {
for j in nodes.as_object().ok_or("msg nodes 不是object")? {
let k = j.0;
let v = j.1.as_str().ok_or("j.1.as_str() err")?;
let v = to_json_str(j.1);
cqcode.push_str(k);
cqcode.push('=');
cqcode.push_str(cq_params_encode(v).as_str());
cqcode.push_str(cq_params_encode(&v).as_str());
cqcode.push(',');
}
}
Expand Down
Loading

0 comments on commit a3de7d4

Please sign in to comment.