cqtool 0.1.0

A tool for converting between CQ strings and message segment arrays
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 15.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 22s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • super1207/cqtool-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • super1207

CQ码工具

可以完成CQ字符串与消息段数组之间的互相转换

安装

cargo add cqtool

使用

将消息转为消息段数组格式

let cqstr = "你好[CQ:at,qq=123456]";
let cqjson:serde_json::Value = cqtool::to_arr_msg(cqstr).unwrap();
println!("{}",serde_json::to_string_pretty(&cqjson).unwrap());

输出:

[
  {
    "data": {
      "text": "你好"
    },
    "type": "text"
  },
  {
    "data": {
      "qq": "123456"
    },
    "type": "at"
  }
]

将消息转为CQ字符串格式

let json_arr:serde_json::Value = serde_json::json!([{"data": {"text": "你好"},"type": "text"},{"data": {"qq": "123456"},"type": "at"}]);
let cqstr = cqtool::to_str_msg(&json_arr).unwrap();
println!("{}", cqstr);

输出:

你好[CQ:at,qq=123456]

构造CQ码参数

let cqstr = format!("你好[CQ:at,qq={}]",cqtool::cq_params_encode("123456"));
println!("{}",cqstr);

输出:

你好[CQ:at,qq=123456]

构造CQ文本

let cqstr = format!("{}[CQ:at,qq=123456]",cqtool::cq_text_encode("你好"));
println!("{}",cqstr);

输出:

你好[CQ:at,qq=123456]