onebots 0.0.1

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/lib/bin.d.ts +2 -0
  4. package/lib/bin.js +5 -0
  5. package/lib/config.sample.yaml +31 -0
  6. package/lib/db.d.ts +19 -0
  7. package/lib/db.js +91 -0
  8. package/lib/index.d.ts +5 -0
  9. package/lib/index.js +21 -0
  10. package/lib/onebot.d.ts +43 -0
  11. package/lib/onebot.js +85 -0
  12. package/lib/server/app.d.ts +52 -0
  13. package/lib/server/app.js +232 -0
  14. package/lib/server/router.d.ts +9 -0
  15. package/lib/server/router.js +32 -0
  16. package/lib/service/V11/action/common.d.ts +64 -0
  17. package/lib/service/V11/action/common.js +115 -0
  18. package/lib/service/V11/action/friend.d.ts +38 -0
  19. package/lib/service/V11/action/friend.js +44 -0
  20. package/lib/service/V11/action/group.d.ts +104 -0
  21. package/lib/service/V11/action/group.js +138 -0
  22. package/lib/service/V11/action/index.d.ts +9 -0
  23. package/lib/service/V11/action/index.js +10 -0
  24. package/lib/service/V11/config.d.ts +10 -0
  25. package/lib/service/V11/config.js +2 -0
  26. package/lib/service/V11/index.d.ts +95 -0
  27. package/lib/service/V11/index.js +481 -0
  28. package/lib/service/V12/action/common.d.ts +32 -0
  29. package/lib/service/V12/action/common.js +105 -0
  30. package/lib/service/V12/action/friend.d.ts +13 -0
  31. package/lib/service/V12/action/friend.js +15 -0
  32. package/lib/service/V12/action/group.d.ts +104 -0
  33. package/lib/service/V12/action/group.js +138 -0
  34. package/lib/service/V12/action/guild.d.ts +2 -0
  35. package/lib/service/V12/action/guild.js +6 -0
  36. package/lib/service/V12/action/index.d.ts +10 -0
  37. package/lib/service/V12/action/index.js +11 -0
  38. package/lib/service/V12/config.d.ts +17 -0
  39. package/lib/service/V12/config.js +2 -0
  40. package/lib/service/V12/index.d.ts +102 -0
  41. package/lib/service/V12/index.js +530 -0
  42. package/lib/types.d.ts +3 -0
  43. package/lib/types.js +2 -0
  44. package/lib/utils.d.ts +13 -0
  45. package/lib/utils.js +139 -0
  46. package/package.json +58 -0
@@ -0,0 +1,481 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.V11 = void 0;
7
+ const action_1 = require("./action");
8
+ const ws_1 = require("ws");
9
+ const url_1 = require("url");
10
+ const utils_1 = require("../../utils");
11
+ const icqq_cq_enable_1 = require("icqq-cq-enable");
12
+ const onebot_1 = require("../../onebot");
13
+ const http_1 = __importDefault(require("http"));
14
+ const https_1 = __importDefault(require("https"));
15
+ const events_1 = require("events");
16
+ class V11 extends events_1.EventEmitter {
17
+ constructor(oneBot, client, config) {
18
+ super();
19
+ this.oneBot = oneBot;
20
+ this.client = client;
21
+ this.config = config;
22
+ this.version = 'V11';
23
+ this.timestamp = Date.now();
24
+ this._queue = [];
25
+ this.queue_running = false;
26
+ this.wsr = new Set();
27
+ this.action = new action_1.Action();
28
+ this.logger = this.oneBot.app.getLogger(this.client.uin, this.version);
29
+ }
30
+ start(path) {
31
+ this.path = `/${this.client.uin}`;
32
+ if (path)
33
+ this.path += path;
34
+ if (this.config.use_http)
35
+ this.startHttp();
36
+ if (this.config.use_ws)
37
+ this.startWs();
38
+ this.config.http_reverse.forEach(config => {
39
+ if (typeof config === 'string') {
40
+ config = {
41
+ url: config,
42
+ access_token: this.config.access_token,
43
+ secret: this.config.secret
44
+ };
45
+ }
46
+ else {
47
+ config = {
48
+ access_token: this.config.access_token,
49
+ secret: this.config.secret,
50
+ ...config
51
+ };
52
+ }
53
+ this.startHttpReverse(config);
54
+ });
55
+ this.config.ws_reverse.forEach(config => {
56
+ this.startWsReverse(config);
57
+ });
58
+ if (this.config.heartbeat) {
59
+ this.heartbeat = setInterval(() => {
60
+ this.dispatch({
61
+ self_id: this.client.uin,
62
+ time: Math.floor(Date.now() / 1000),
63
+ post_type: "meta_event",
64
+ meta_event_type: "heartbeat",
65
+ interval: this.config.heartbeat * 1000,
66
+ });
67
+ }, this.config.heartbeat * 1000);
68
+ }
69
+ }
70
+ startHttp() {
71
+ this.oneBot.app.router.all(new RegExp(`^${this.path}/(.*)$`), this._httpRequestHandler.bind(this));
72
+ this.logger.mark(`开启http服务器成功,监听:http://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
73
+ }
74
+ startHttpReverse(config) {
75
+ this.on('dispatch', (unserialized) => {
76
+ const serialized = JSON.stringify(unserialized);
77
+ const options = {
78
+ method: "POST",
79
+ timeout: this.config.post_timeout * 1000,
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ "Content-Length": Buffer.byteLength(serialized),
83
+ "X-Self-ID": String(this.client.uin),
84
+ "User-Agent": "OneBot",
85
+ },
86
+ };
87
+ if (this.config.secret) {
88
+ //@ts-ignore
89
+ options.headers["X-Signature"] = "sha1=" + crypto.createHmac("sha1", String(this.config.secret)).update(serialized).digest("hex");
90
+ }
91
+ const protocol = config.url.startsWith("https") ? https_1.default : http_1.default;
92
+ try {
93
+ protocol.request(config.url, options, (res) => {
94
+ if (res.statusCode !== 200)
95
+ return this.logger.warn(`POST(${config.url})上报事件收到非200响应:` + res.statusCode);
96
+ let data = "";
97
+ res.setEncoding("utf-8");
98
+ res.on("data", (chunk) => data += chunk);
99
+ res.on("end", () => {
100
+ this.logger.debug(`收到HTTP响应 ${res.statusCode} :` + data);
101
+ if (!data)
102
+ return;
103
+ try {
104
+ this._quickOperate(unserialized, JSON.parse(data));
105
+ }
106
+ catch (e) {
107
+ this.logger.error(`快速操作遇到错误:` + e.message);
108
+ }
109
+ });
110
+ }).on("error", (err) => {
111
+ this.logger.error(`POST(${config.url})上报事件失败:` + err.message);
112
+ }).end(serialized, () => {
113
+ this.logger.debug(`POST(${config.url})上报事件成功: ` + serialized);
114
+ });
115
+ }
116
+ catch (e) {
117
+ this.logger.error(`POST(${config.url})上报失败:` + e.message);
118
+ }
119
+ });
120
+ }
121
+ startWs() {
122
+ this.wss = this.oneBot.app.router.ws(this.path, this.oneBot.app.httpServer);
123
+ this.logger.mark(`开启ws服务器成功,监听:ws://127.0.0.1:${this.oneBot.app.config.port}${this.path}`);
124
+ this.wss.on("error", (err) => {
125
+ this.logger.error(err.message);
126
+ });
127
+ this.wss.on("connection", (ws, req) => {
128
+ this.logger.info(`ws客户端(${req.headers.origin})已连接`);
129
+ ws.on("error", (err) => {
130
+ this.logger.error(`ws客户端(${req.headers.origin})报错:${err.message}`);
131
+ });
132
+ ws.on("close", (code, reason) => {
133
+ this.logger.warn(`ws客户端(${req.headers.origin})连接关闭,关闭码${code},关闭理由:` + reason);
134
+ });
135
+ if (this.config.access_token) {
136
+ const url = new url_1.URL(req.url, "http://127.0.0.1");
137
+ const token = url.searchParams.get('access_token');
138
+ if (token)
139
+ req.headers["authorization"] = `Bearer ${token}`;
140
+ if (!req.headers["authorization"] || req.headers["authorization"] !== `Bearer ${this.config.access_token}`)
141
+ return ws.close(1002, "wrong access token");
142
+ }
143
+ this._webSocketHandler(ws);
144
+ });
145
+ this.on('dispatch', (serialized) => {
146
+ for (const ws of this.wss.clients) {
147
+ ws.send(serialized, (err) => {
148
+ if (err)
149
+ this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
150
+ else
151
+ this.logger.debug(`正向WS(${ws.url})上报事件成功: ` + serialized);
152
+ });
153
+ }
154
+ });
155
+ }
156
+ startWsReverse(url) {
157
+ const ws = this._createWsr(url);
158
+ this.on('dispatch', (unserialized) => {
159
+ if (this.wsr.has(ws)) {
160
+ ws.send(JSON.stringify(unserialized));
161
+ }
162
+ });
163
+ }
164
+ stop() {
165
+ this.client.logout();
166
+ }
167
+ dispatch(data) {
168
+ if (!data.post_type)
169
+ data.post_type = 'system';
170
+ if (data.post_type === 'system') {
171
+ }
172
+ if (data.message && data.post_type === 'message') {
173
+ data.message = this.config.post_message_format === 'array' ? (0, icqq_cq_enable_1.toSegment)(data.message) : (0, icqq_cq_enable_1.toCqcode)(data);
174
+ }
175
+ this.emit('dispatch', JSON.stringify(data));
176
+ }
177
+ async _httpRequestHandler(ctx) {
178
+ if (ctx.method === 'OPTIONS') {
179
+ return ctx.writeHead(200, {
180
+ 'Access-Control-Allow-Origin': '*',
181
+ 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
182
+ 'Access-Control-Allow-Headers': 'Content-Type, authorization'
183
+ }).end();
184
+ }
185
+ const url = new url_1.URL(ctx.url, `http://127.0.0.1`);
186
+ if (this.config.access_token) {
187
+ if (ctx.headers["authorization"]) {
188
+ if (ctx.headers["authorization"] !== `Bearer ${this.config.access_token}`)
189
+ return ctx.res.writeHead(403).end();
190
+ }
191
+ else {
192
+ const access_token = url.searchParams.get("access_token");
193
+ if (!access_token)
194
+ return ctx.res.writeHead(401).end();
195
+ else if (access_token !== this.config.access_token)
196
+ return ctx.res.writeHead(403).end();
197
+ }
198
+ }
199
+ ctx.res.setHeader("Content-Type", "application/json; charset=utf-8");
200
+ if (this.config.enable_cors)
201
+ ctx.res.setHeader("Access-Control-Allow-Origin", "*");
202
+ const action = url.pathname.replace(`${this.path}`, '').slice(1);
203
+ if (ctx.method === "GET") {
204
+ try {
205
+ const ret = await this.apply({ action, params: ctx.query });
206
+ ctx.res.writeHead(200).end(ret);
207
+ }
208
+ catch (e) {
209
+ ctx.res.writeHead(500).end(e.message);
210
+ }
211
+ }
212
+ else if (ctx.method === "POST") {
213
+ try {
214
+ const params = { ...ctx.query, ...ctx.request.body };
215
+ const ret = await this.apply({ action, params });
216
+ ctx.res.writeHead(200).end(ret);
217
+ }
218
+ catch (e) {
219
+ ctx.res.writeHead(500).end(e.message);
220
+ }
221
+ }
222
+ else {
223
+ ctx.res.writeHead(405).end();
224
+ }
225
+ }
226
+ /**
227
+ * 处理ws消息
228
+ */
229
+ _webSocketHandler(ws) {
230
+ ws.on("message", async (msg) => {
231
+ this.logger.debug(" 收到ws消息:" + msg);
232
+ var data;
233
+ try {
234
+ data = JSON.parse(String(msg));
235
+ let ret;
236
+ if (data.action.startsWith(".handle_quick_operation")) {
237
+ const event = data.params.context, res = data.params.operation;
238
+ this._quickOperate(event, res);
239
+ ret = JSON.stringify({
240
+ retcode: 0,
241
+ status: "async",
242
+ data: null,
243
+ error: null,
244
+ echo: data.echo
245
+ });
246
+ }
247
+ else {
248
+ ret = await this.apply(data);
249
+ }
250
+ ws.send(ret);
251
+ }
252
+ catch (e) {
253
+ let code, message;
254
+ if (e instanceof onebot_1.NotFoundError) {
255
+ code = 1404;
256
+ message = "不支持的api";
257
+ }
258
+ else {
259
+ code = 1400;
260
+ message = "请求格式错误";
261
+ }
262
+ ws.send(JSON.stringify({
263
+ retcode: code,
264
+ status: "failed",
265
+ data: null,
266
+ error: {
267
+ code, message
268
+ },
269
+ echo: data?.echo
270
+ }));
271
+ }
272
+ });
273
+ ws.send(JSON.stringify(V11.genMetaEvent(this.client.uin, "connect")));
274
+ ws.send(JSON.stringify(V11.genMetaEvent(this.client.uin, "enable")));
275
+ }
276
+ /**
277
+ * 创建反向ws
278
+ */
279
+ _createWsr(url) {
280
+ const timestmap = Date.now();
281
+ const headers = {
282
+ "X-Self-ID": String(this.client.uin),
283
+ "X-Client-Role": "Universal",
284
+ "User-Agent": "OneBot",
285
+ };
286
+ if (this.config.access_token)
287
+ headers.Authorization = "Bearer " + this.config.access_token;
288
+ const ws = new ws_1.WebSocket(url, { headers });
289
+ ws.on("error", (err) => {
290
+ this.logger.error(err.message);
291
+ });
292
+ ws.on("open", () => {
293
+ this.logger.info(`反向ws(${url})连接成功。`);
294
+ this.wsr.add(ws);
295
+ this._webSocketHandler(ws);
296
+ });
297
+ ws.on("close", (code) => {
298
+ this.wsr.delete(ws);
299
+ if (timestmap < this.timestamp)
300
+ return;
301
+ this.logger.warn(`反向ws(${url})被关闭,关闭码${code},将在${this.config.reconnect_interval}秒后尝试重连。`);
302
+ setTimeout(() => {
303
+ if (timestmap < this.timestamp)
304
+ return;
305
+ this._createWsr(url);
306
+ }, this.config.reconnect_interval * 1000);
307
+ });
308
+ return ws;
309
+ }
310
+ /**
311
+ * 快速操作
312
+ */
313
+ _quickOperate(event, res) {
314
+ if (event.post_type === "message") {
315
+ if (res.reply) {
316
+ if (event.message_type === "discuss")
317
+ return;
318
+ const action = event.message_type === "private" ? "sendPrivateMsg" : "sendGroupMsg";
319
+ const id = event.message_type === "private" ? event.user_id : event.group_id;
320
+ this.client[action](id, res.reply, res.auto_escape);
321
+ }
322
+ if (event.message_type === "group") {
323
+ if (res.delete)
324
+ this.client.deleteMsg(event.message_id);
325
+ if (res.kick && !event.anonymous)
326
+ this.client.setGroupKick(event.group_id, event.user_id, res.reject_add_request);
327
+ if (res.ban)
328
+ this.client.setGroupBan(event.group_id, event.user_id, res.ban_duration > 0 ? res.ban_duration : 1800);
329
+ }
330
+ }
331
+ if (event.post_type === "request" && "approve" in res) {
332
+ const action = event.request_type === "friend" ? "setFriendAddRequest" : "setGroupAddRequest";
333
+ this.client[action](event.flag, res.approve, res.reason ? res.reason : "", !!res.block);
334
+ }
335
+ }
336
+ /**
337
+ * 调用api
338
+ */
339
+ async apply(req) {
340
+ let { action, params, echo } = req;
341
+ action = (0, utils_1.toLine)(action);
342
+ let is_async = action.includes("_async");
343
+ if (is_async)
344
+ action = action.replace("_async", "");
345
+ let is_queue = action.includes("_rate_limited");
346
+ if (is_queue)
347
+ action = action.replace("_rate_limited", "");
348
+ if (action === 'send_msg') {
349
+ if (["private", "group", "discuss"].includes(params.message_type)) {
350
+ action = "send_" + params.message_type + "_msg";
351
+ }
352
+ else if (params.user_id)
353
+ action = "send_private_msg";
354
+ else if (params.group_id)
355
+ action = "send_group_msg";
356
+ else if (params.discuss_id)
357
+ action = "send_discuss_msg";
358
+ else
359
+ throw new Error('required message_type or input (user_id/group_id)');
360
+ }
361
+ const method = (0, utils_1.toHump)(action);
362
+ if (Reflect.has(this.action, method)) {
363
+ const ARGS = String(Reflect.get(this.action, method)).match(/\(.*\)/)?.[0]
364
+ .replace("(", "")
365
+ .replace(")", "")
366
+ .split(",")
367
+ .filter(Boolean).map(v => v.replace(/=.+/, "").trim());
368
+ const args = [];
369
+ for (let k of ARGS) {
370
+ if (Reflect.has(params, k)) {
371
+ if (onebot_1.BOOLS.includes(k))
372
+ params[k] = (0, utils_1.toBool)(params[k]);
373
+ if (k === 'message') {
374
+ if (typeof params[k] === 'string') {
375
+ params[k] = (0, icqq_cq_enable_1.fromCqcode)(params[k]);
376
+ }
377
+ else {
378
+ params[k] = (0, icqq_cq_enable_1.fromSegment)(params[k]);
379
+ }
380
+ }
381
+ args.push(params[k]);
382
+ }
383
+ }
384
+ let ret, result;
385
+ if (is_queue) {
386
+ this._queue.push({ method, args });
387
+ this._runQueue();
388
+ result = V11.success(null, 0, true);
389
+ }
390
+ else {
391
+ try {
392
+ ret = this.action[method].apply(this, args);
393
+ }
394
+ catch (e) {
395
+ return JSON.stringify(V11.error(e.message));
396
+ }
397
+ if (ret instanceof Promise) {
398
+ if (is_async) {
399
+ result = V11.success(null, 0, true);
400
+ }
401
+ else {
402
+ result = V11.success(await ret, 0, false);
403
+ }
404
+ }
405
+ else {
406
+ result = V11.success(await ret, 0, false);
407
+ }
408
+ }
409
+ if (result.data instanceof Map)
410
+ result.data = [...result.data.values()];
411
+ if (echo) {
412
+ result.echo = echo;
413
+ }
414
+ return JSON.stringify(result);
415
+ }
416
+ else
417
+ throw new onebot_1.NotFoundError();
418
+ }
419
+ /**
420
+ * 限速队列调用
421
+ */
422
+ async _runQueue() {
423
+ if (this.queue_running)
424
+ return;
425
+ while (this._queue.length > 0) {
426
+ this.queue_running = true;
427
+ const task = this._queue.shift();
428
+ const { method, args } = task;
429
+ this.action[method].apply(this, args);
430
+ await new Promise((resolve) => {
431
+ setTimeout(resolve, this.config.rate_limit_interval * 1000);
432
+ });
433
+ this.queue_running = false;
434
+ }
435
+ }
436
+ }
437
+ exports.V11 = V11;
438
+ (function (V11) {
439
+ function success(data, retcode = 0, pending) {
440
+ return {
441
+ retcode,
442
+ status: pending ? 'async' : 'success',
443
+ data,
444
+ error: null
445
+ };
446
+ }
447
+ V11.success = success;
448
+ function error(error, retcode = 1) {
449
+ return {
450
+ retcode,
451
+ status: 'error',
452
+ data: null,
453
+ error
454
+ };
455
+ }
456
+ V11.error = error;
457
+ V11.defaultConfig = {
458
+ heartbeat: 3,
459
+ access_token: '',
460
+ post_timeout: 15,
461
+ secret: '',
462
+ rate_limit_interval: 4,
463
+ post_message_format: 'string',
464
+ reconnect_interval: 3,
465
+ use_http: true,
466
+ enable_cors: true,
467
+ use_ws: true,
468
+ http_reverse: [],
469
+ ws_reverse: []
470
+ };
471
+ function genMetaEvent(uin, type) {
472
+ return {
473
+ self_id: uin,
474
+ time: Math.floor(Date.now() / 1000),
475
+ post_type: "meta_event",
476
+ meta_event_type: "lifecycle",
477
+ sub_type: type,
478
+ };
479
+ }
480
+ V11.genMetaEvent = genMetaEvent;
481
+ })(V11 = exports.V11 || (exports.V11 = {}));
@@ -0,0 +1,32 @@
1
+ import { V12 } from '../../../service/V12';
2
+ import { OnlineStatus } from "icqq";
3
+ import { Action } from "./";
4
+ import { V11 } from "../../../service/V11";
5
+ export declare class CommonAction {
6
+ sendMsg(): void;
7
+ /**
8
+ * 撤回消息
9
+ * @param message_id {string} 消息id
10
+ */
11
+ deleteMsg(this: V12, message_id: string): Promise<boolean>;
12
+ getSelfInfo(this: V12): {
13
+ user_id: number;
14
+ nickname: string;
15
+ };
16
+ getStatus(this: V12): {
17
+ online: OnlineStatus;
18
+ good: boolean;
19
+ };
20
+ getLatestEvents(this: V12, limit?: number, timout?: number): Promise<V12.Payload<keyof Action>[]>;
21
+ getVersion(this: V12): {
22
+ impl: string;
23
+ platform: string;
24
+ version: string;
25
+ onebot_version: string;
26
+ };
27
+ submitSlider(this: V11, ticket: string): void;
28
+ submitSmsCode(this: V11, code: string): void;
29
+ sendSmsCode(this: V11): void;
30
+ login(this: V11, password?: string): Promise<unknown>;
31
+ getSupportedActions(this: V12): string[];
32
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonAction = void 0;
4
+ const icqq_1 = require("icqq");
5
+ const onebot_1 = require("../../../onebot");
6
+ const utils_1 = require("../../../utils");
7
+ class CommonAction {
8
+ sendMsg() { }
9
+ /**
10
+ * 撤回消息
11
+ * @param message_id {string} 消息id
12
+ */
13
+ deleteMsg(message_id) {
14
+ return this.client.deleteMsg(message_id);
15
+ }
16
+ getSelfInfo() {
17
+ return {
18
+ user_id: this.client.uin,
19
+ nickname: this.client.nickname
20
+ };
21
+ }
22
+ getStatus() {
23
+ return {
24
+ online: this.client.status = icqq_1.OnlineStatus.Online,
25
+ good: this.oneBot.status === onebot_1.OneBotStatus.Good
26
+ };
27
+ }
28
+ getLatestEvents(limit = 0, timout = 0) {
29
+ return new Promise(resolve => {
30
+ if (!this.history.length && timout !== 0) {
31
+ return setTimeout(() => resolve(this.action.getLatestEvents.apply(this, [limit, timout])), timout * 1000);
32
+ }
33
+ return resolve(this.history.reverse().filter((_, i) => limit === 0 ? true : i < limit));
34
+ });
35
+ }
36
+ getVersion() {
37
+ return {
38
+ impl: 'icqq_onebot',
39
+ platform: 'qq',
40
+ version: '0.0.1',
41
+ onebot_version: '12'
42
+ };
43
+ }
44
+ submitSlider(ticket) {
45
+ return this.client.submitSlider(ticket);
46
+ }
47
+ submitSmsCode(code) {
48
+ return this.client.submitSmsCode(code);
49
+ }
50
+ sendSmsCode() {
51
+ return this.client.sendSmsCode();
52
+ }
53
+ login(password) {
54
+ const _this = this;
55
+ return new Promise(async (resolve) => {
56
+ const timer = setTimeout(() => {
57
+ resolve('登录超时');
58
+ }, 5000);
59
+ function receiveQrcode(event) {
60
+ _this.client.off('system.login.device', receiveDevice);
61
+ _this.client.off('system.login.slider', receiveSlider);
62
+ _this.client.off('system.online', closeListen);
63
+ clearTimeout(timer);
64
+ resolve(event);
65
+ }
66
+ function receiveDevice(event) {
67
+ _this.client.off('system.login.qrcode', receiveQrcode);
68
+ _this.client.off('system.login.slider', receiveSlider);
69
+ _this.client.off('system.online', closeListen);
70
+ clearTimeout(timer);
71
+ resolve(event);
72
+ }
73
+ function receiveError(event) {
74
+ clearTimeout(timer);
75
+ resolve(event);
76
+ }
77
+ function receiveSlider(event) {
78
+ _this.client.off('system.login.qrcode', receiveQrcode);
79
+ _this.client.off('system.login.device', receiveDevice);
80
+ _this.client.off('system.online', closeListen);
81
+ clearTimeout(timer);
82
+ resolve(event);
83
+ }
84
+ function closeListen() {
85
+ _this.client.off('system.login.slider', receiveSlider);
86
+ _this.client.off('system.login.qrcode', receiveQrcode);
87
+ _this.client.off('system.login.device', receiveDevice);
88
+ clearTimeout(timer);
89
+ resolve('登录成功');
90
+ }
91
+ this.client.once('system.login.qrcode', receiveQrcode);
92
+ this.client.once('system.login.device', receiveDevice);
93
+ this.client.once('system.login.slider', receiveSlider);
94
+ this.client.once('system.login.error', receiveError);
95
+ this.client.once('system.online', closeListen);
96
+ await this.client.login(password).catch(() => resolve('登录失败'));
97
+ });
98
+ }
99
+ getSupportedActions() {
100
+ return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
101
+ return key !== 'constructor';
102
+ }).map(utils_1.toLine);
103
+ }
104
+ }
105
+ exports.CommonAction = CommonAction;
@@ -0,0 +1,13 @@
1
+ import { V12 } from "../index";
2
+ import { Sendable } from "icqq";
3
+ export declare class FriendAction {
4
+ getUserInfo(this: V12, user_id: number): Promise<{
5
+ user_id: number;
6
+ nickname: string;
7
+ sex: import("icqq").Gender;
8
+ age: number;
9
+ area: string;
10
+ }>;
11
+ getFriendList(this: V12): Map<number, import("icqq").FriendInfo>;
12
+ sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
13
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FriendAction = void 0;
4
+ class FriendAction {
5
+ getUserInfo(user_id) {
6
+ return this.client.getStrangerInfo(user_id);
7
+ }
8
+ getFriendList() {
9
+ return this.client.getFriendList();
10
+ }
11
+ sendPrivateMsg(user_id, message) {
12
+ return this.client.sendPrivateMsg(user_id, message);
13
+ }
14
+ }
15
+ exports.FriendAction = FriendAction;