oicq-icalingua-plus-plus 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +73 -0
  3. package/bin/oicq +2 -0
  4. package/http-api/README.md +187 -0
  5. package/http-api/api.js +217 -0
  6. package/http-api/config.sample.js +44 -0
  7. package/http-api/core.js +480 -0
  8. package/http-api/cq-notice.js +39 -0
  9. package/http-api/filter.js +128 -0
  10. package/http-api/index.js +39 -0
  11. package/index.d.ts +1214 -0
  12. package/index.js +34 -0
  13. package/lib/algo/jce/index.js +63 -0
  14. package/lib/algo/jce/jce.js +341 -0
  15. package/lib/algo/pb.js +159 -0
  16. package/lib/algo/protobuf.min.js +8 -0
  17. package/lib/algo/tea.js +121 -0
  18. package/lib/client-ext.js +312 -0
  19. package/lib/client-net.js +147 -0
  20. package/lib/client.js +594 -0
  21. package/lib/common.js +252 -0
  22. package/lib/core/friendlist.js +415 -0
  23. package/lib/core/nessy.js +148 -0
  24. package/lib/core/ref.d.ts +1 -0
  25. package/lib/core/sysmsg.js +388 -0
  26. package/lib/core/troop.js +586 -0
  27. package/lib/device.js +181 -0
  28. package/lib/exception.js +57 -0
  29. package/lib/message/builder.js +1093 -0
  30. package/lib/message/chat.js +276 -0
  31. package/lib/message/face.js +293 -0
  32. package/lib/message/file.js +425 -0
  33. package/lib/message/history.js +73 -0
  34. package/lib/message/image.js +533 -0
  35. package/lib/message/multi.js +242 -0
  36. package/lib/message/music.js +172 -0
  37. package/lib/message/parser.js +774 -0
  38. package/lib/message/ptt.js +389 -0
  39. package/lib/oicq.js +427 -0
  40. package/lib/onlinepush.js +616 -0
  41. package/lib/ref.d.ts +177 -0
  42. package/lib/service.js +204 -0
  43. package/lib/wtlogin/ecdh.js +15 -0
  44. package/lib/wtlogin/login-password.js +215 -0
  45. package/lib/wtlogin/login-qrcode.js +249 -0
  46. package/lib/wtlogin/tlv.js +331 -0
  47. package/lib/wtlogin/writer.js +88 -0
  48. package/lib/wtlogin/wt.js +422 -0
  49. package/package.json +50 -0
  50. package/util.js +115 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ /**
3
+ * @type {import("../").Client}
4
+ */
5
+ let bot;
6
+ class NotFoundError extends Error {}
7
+
8
+ const available_actions = [
9
+ "sendPrivateMsg",
10
+ "sendGroupMsg",
11
+ "sendDiscussMsg",
12
+ "sendMsg",
13
+ "deleteMsg",
14
+ "getMsg",
15
+ "getForwardMsg",
16
+ "sendLike",
17
+ "setGroupKick",
18
+ "setGroupBan",
19
+ "setGroupAnonymousBan",
20
+ "setGroupWholeBan",
21
+ "setGroupAdmin",
22
+ "setGroupAnonymous",
23
+ "setGroupCard",
24
+ "setGroupName",
25
+ "setGroupLeave",
26
+ "sendGroupNotice",
27
+ "setGroupSpecialTitle",
28
+ "setFriendAddRequest",
29
+ "setGroupAddRequest",
30
+ "getLoginInfo",
31
+ "getStrangerInfo",
32
+ "getFriendList",
33
+ "getStrangerList",
34
+ "getGroupInfo",
35
+ "getGroupList",
36
+ "getGroupMemberInfo",
37
+ "getGroupMemberList",
38
+ // "getGroupHonorInfo", //暂无实现计划
39
+ "getCookies",
40
+ "getCsrfToken",
41
+ // "getCredentials", //暂无实现计划
42
+ // "getRecord", //暂无实现计划
43
+ // "getImage", //暂无实现计划
44
+ "canSendImage",
45
+ "canSendRecord",
46
+ "getStatus",
47
+ "getVersionInfo",
48
+ // "setRestart", //todo
49
+ "cleanCache",
50
+
51
+ //enhancement
52
+ "setOnlineStatus",
53
+ "sendGroupPoke",
54
+ "addGroup",
55
+ "addFriend",
56
+ "deleteFriend",
57
+ "inviteFriend",
58
+ "sendLike",
59
+ "setNickname",
60
+ "setDescription",
61
+ "setGender",
62
+ "setBirthday",
63
+ "setSignature",
64
+ "setPortrait",
65
+ "setGroupPortrait",
66
+
67
+ "getSystemMsg",
68
+ "getChatHistory",
69
+ "sendTempMsg",
70
+ ];
71
+
72
+ const queue = [];
73
+ let queue_running = false;
74
+ let rate_limit_interval = 500;
75
+ async function runQueue() {
76
+ if (queue_running) return;
77
+ while (queue.length > 0) {
78
+ queue_running = true;
79
+ const task = queue.shift();
80
+ const {action, param_arr} = task;
81
+ bot[action].apply(bot, param_arr);
82
+ await new Promise((resolve)=>{
83
+ setTimeout(resolve, rate_limit_interval);
84
+ });
85
+ queue_running = false;
86
+ }
87
+ }
88
+
89
+ const fn_signs = {};
90
+
91
+ /**
92
+ * @param {{import("../").Client}} client
93
+ * @param {number} rli rate_limit_interval
94
+ */
95
+ function setBot(client, rli) {
96
+ bot = client;
97
+ rli = parseInt(rli);
98
+ if (isNaN(rli) || rli < 0)
99
+ rli = 500;
100
+ rate_limit_interval = rli;
101
+ for (let fn of available_actions) {
102
+ if (bot[fn]) {
103
+ fn_signs[fn] = bot[fn].toString().match(/\(.*\)/)[0].replace("(","").replace(")","").split(",");
104
+ fn_signs[fn].forEach((v, i, arr)=>{
105
+ arr[i] = v.replace(/=.+/, "").trim();
106
+ });
107
+ }
108
+ }
109
+ }
110
+
111
+ function toHump(action) {
112
+ return action.replace(/_[\w]/g, (s)=>{
113
+ return s[1].toUpperCase();
114
+ })
115
+ }
116
+
117
+ function quickOperate(event, res) {
118
+ if (event.post_type === "message" && res.reply) {
119
+ const action = event.message_type === "private" ? "sendPrivateMsg" : "sendGroupMsg";
120
+ const id = event.message_type === "private" ? event.user_id : event.group_id;
121
+ bot[action](id, res.reply, res.auto_escape);
122
+ if (event.group_id) {
123
+ if (res.delete)
124
+ bot.deleteMsg(event.message_id);
125
+ if (res.kick && !event.anonymous)
126
+ bot.setGroupKick(event.group_id, event.user_id, res.reject_add_request);
127
+ if (res.ban)
128
+ bot.setGroupBan(event.group_id, event.user_id, res.ban_duration?res.ban_duration:1800);
129
+ }
130
+ }
131
+ if (event.post_type === "request" && res.hasOwnProperty("approve")) {
132
+ const action = event.request_type === "friend" ? "setFriendAddRequest" : "setGroupAddRequest";
133
+ bot[action](event.flag, res.approve, res.reason?res.reason:"", res.block?true:false);
134
+ }
135
+ }
136
+
137
+ function handleQuickOperation(data) {
138
+ const event = data.params.context, res = data.params.operation;
139
+ quickOperate(event, res);
140
+ }
141
+
142
+ const bool_fields = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
143
+ function toBool(v) {
144
+ if (v === "0" || v === "false")
145
+ v = false;
146
+ return Boolean(v);
147
+ }
148
+
149
+ async function apply(req) {
150
+ let {action, params, echo} = req;
151
+ let is_async = action.includes("_async");
152
+ if (is_async)
153
+ action = action.replace("_async", "");
154
+ let is_queue = action.includes("_rate_limited");
155
+ if (is_queue)
156
+ action = action.replace("_rate_limited", "");
157
+
158
+ if (action === "send_msg") {
159
+ if (["private", "group", "discuss"].includes(params.message_type))
160
+ action = "send_" + params.message_type + "_msg";
161
+ else if (params.user_id)
162
+ action = "send_private_msg";
163
+ else if (params.group_id)
164
+ action = "send_group_msg";
165
+ else if (params.discuss_id)
166
+ action = "send_discuss_msg";
167
+ }
168
+
169
+ action = toHump(action);
170
+ if (bot[action] && available_actions.includes(action)) {
171
+
172
+ const param_arr = [];
173
+ for (let k of fn_signs[action]) {
174
+ if (Reflect.has(params, k)) {
175
+ if (bool_fields.includes(k))
176
+ params[k] = toBool(params[k]);
177
+ param_arr.push(params[k]);
178
+ }
179
+ }
180
+
181
+ let ret;
182
+ if (is_queue) {
183
+ queue.push({action, param_arr});
184
+ runQueue();
185
+ ret = {
186
+ retcode: 1,
187
+ status: "async",
188
+ data: null
189
+ }
190
+ } else {
191
+ ret = bot[action].apply(bot, param_arr);
192
+ if (ret instanceof Promise) {
193
+ if (is_async)
194
+ ret = {
195
+ retcode: 1,
196
+ status: "async",
197
+ data: null
198
+ }
199
+ else
200
+ ret = await ret;
201
+ }
202
+ }
203
+
204
+ if (ret.data instanceof Map)
205
+ ret.data = [...ret.data.values()];
206
+
207
+ if (echo)
208
+ ret.echo = echo;
209
+ return JSON.stringify(ret);
210
+ } else {
211
+ throw new NotFoundError();
212
+ }
213
+ }
214
+
215
+ module.exports = {
216
+ setBot, quickOperate, handleQuickOperation, apply, NotFoundError
217
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // 此文件必须名为config.js才能生效哦
3
+
4
+ module.exports = {
5
+
6
+ //通用配置
7
+ general: {
8
+ platform: 1, //1:安卓手机 2:aPad 3:安卓手表 4:MacOS 5:iPad
9
+ log_level: "info", //trace,debug,info,warn,error,mark
10
+ use_cqhttp_notice: false, //是否使用cqhttp标准的notice事件格式
11
+
12
+ host: "0.0.0.0", //监听主机名
13
+ port: 5700, //端口
14
+ use_http: false, //启用http
15
+ use_ws: false, //启用正向ws,和http使用相同地址和端口
16
+ access_token: "", //访问api的token
17
+ secret: "", //上报数据的sha1签名密钥
18
+ post_timeout: 30, //post超时时间(秒)
19
+ post_message_format:"array", //"string"或"array"
20
+ enable_cors: false, //是否允许跨域请求
21
+ enable_heartbeat: false, //是否启用ws心跳
22
+ heartbeat_interval: 15000, //ws心跳间隔(毫秒)
23
+ rate_limit_interval:500, //使用_rate_limited后缀限速调用api的排队间隔时间(毫秒)
24
+ event_filter: "", //json格式的事件过滤器文件路径
25
+ post_url: [ //上报地址,可以添加多个url
26
+ // "http://your.address.com:80",
27
+ ],
28
+ ws_reverse_url: [ //反向ws地址,可以添加多个url
29
+ // "ws://your.address.com:8080",
30
+ ],
31
+ ws_reverse_reconnect_interval: 3000, //反向ws断线重连间隔(毫秒),设为负数直接不重连
32
+ ws_reverse_reconnect_on_code_1000: true, //反向ws是否在关闭状态码为1000的时候重连
33
+ },
34
+
35
+ //每个账号的单独配置(用于覆盖通用配置)
36
+ 147258369: {
37
+
38
+ },
39
+ };
40
+
41
+ // 安全注意:
42
+ // 监听0.0.0.0表示监听网卡上的所有地址。如果你的机器可以通过公网ip直接访问,同时你也没有设定access_token,则被认为是极不安全的。
43
+ // 你应该知道这样做会导致以下后果:任何人都可以无限制地访问你的Bot的所有API接口。
44
+ // 如果只需要在本地访问,建议将监听地址改为localhost。需要通过公网访问,你最好设定access_token。