Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Change array message format
Browse files Browse the repository at this point in the history
  • Loading branch information
stdrc committed Jun 12, 2017
1 parent 447d883 commit 4c3f422
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions io.github.richardchien.coolqhttpapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"ret": 1, // 返回码,固定为 1
"apiver": 9, // Api 版本
"name": "HTTP API", // 应用名称
"version": "1.1.6 beta", // 应用版本
"version_id": 16, // 应用顺序版本(每次发布时需增加)
"version": "1.1.6", // 应用版本
"version_id": 17, // 应用顺序版本(每次发布时需增加)
"author": "Richard Chien", // 应用作者
"description": "使酷 Q 支持通过 HTTP 上报事件信息及调用接口",
"event": [ // 事件列表,同一事件类型可重复定义
Expand Down
2 changes: 1 addition & 1 deletion src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#define CQAPPID "io.github.richardchien.coolqhttpapi"
#define CQAPPINFO CQAPIVERTEXT "," CQAPPID
#define CQAPPNAME "CoolQ HTTP API Plugin"
#define CQAPPVER "v1.1.6 beta"
#define CQAPPVER "v1.1.6"
#define CQAPPFULLNAME CQAPPNAME " " CQAPPVER
16 changes: 12 additions & 4 deletions src/appmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ static json_t *convert_to_msg_array_if_needed(string &msg /* utf-8 */) {
while (regex_search(search_iter, msg.cend(), match, exp)) {
auto tmp = string(search_iter, search_iter + match.position()); // normal message before this current CQ code
if (tmp.length() > 0) {
json_array_append_new(result, json_pack("[s,s]", "plain", message_unescape(tmp).c_str())); // ["plain", "the plain text message"]
// {"type": "text", "data": {"text": "the plain text message"}}
json_array_append_new(result, json_pack("{s:s, s:o}",
"type", "text",
"data", json_pack("{s:s}", "text", message_unescape(tmp).c_str())));
}
search_iter += match.position() + match.length(); // move to next

Expand Down Expand Up @@ -313,12 +316,17 @@ static json_t *convert_to_msg_array_if_needed(string &msg /* utf-8 */) {
}
}

json_array_append_new(result, json_pack("[s,o?]", function.c_str(), params_json));

json_array_append_new(result, json_pack("{s:s, s:o?}",
"type", function.c_str(),
"data", params_json));

}
auto tmp = string(search_iter, msg.cend()); // add the rest plain text
if (tmp.length() > 0) {
json_array_append_new(result, json_pack("[s,s]", "plain", message_unescape(tmp).c_str()));
// {"type": "text", "data": {"text": "the plain text message"}}
json_array_append_new(result, json_pack("{s:s, s:o}",
"type", "text",
"data", json_pack("{s:s}", "text", message_unescape(tmp).c_str())));
}

return result;
Expand Down

0 comments on commit 4c3f422

Please sign in to comment.