@alemonjs/qq-bot 2.1.0-alpha.17 → 2.1.0-alpha.19

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.
package/README.md CHANGED
@@ -54,33 +54,3 @@ qq-bot:
54
54
  master_id:
55
55
  - 'yyy'
56
56
  ```
57
-
58
- ```conf
59
- server {
60
- listen 443 ssl http2;
61
- server_name bundle.com;
62
- ssl_certificate /usr/local/nginx/bundle.crt;
63
- ssl_certificate_key /usr/local/nginx/bundle.key;
64
- # 对应 route: ''
65
- location /webhook {
66
- # 指向 webhook 服务的端口 17157
67
- proxy_pass http://localhost:17157;
68
- proxy_set_header Host $host;
69
- proxy_set_header X-Real-IP $remote_addr;
70
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71
- proxy_set_header X-Forwarded-Proto $scheme;
72
- }
73
- # 对应 ws: ''
74
- location /websocket {
75
- # 指向 WebSocket 服务的端口 17157
76
- proxy_pass http://localhost:17157;
77
- proxy_http_version 1.1;
78
- proxy_set_header Upgrade $http_upgrade;
79
- proxy_set_header Connection "upgrade";
80
- proxy_set_header Host $host;
81
- proxy_set_header X-Real-IP $remote_addr;
82
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
83
- proxy_set_header X-Forwarded-Proto $scheme;
84
- }
85
- }
86
- ```
package/lib/desktop.js CHANGED
@@ -20,7 +20,7 @@ const activate = context => {
20
20
  const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
21
21
  // 确保路径存在
22
22
  const html = readFileSync(dir, 'utf-8')
23
- .replace(iconReg, ``)
23
+ .replace(iconReg, '')
24
24
  .replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
25
25
  .replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
26
26
  // 立即渲染 webview
@@ -43,8 +43,9 @@ const activate = context => {
43
43
  }
44
44
  else if (data.type === 'qq-bot.init') {
45
45
  let config = getConfigValue();
46
- if (!config)
46
+ if (!config) {
47
47
  config = {};
48
+ }
48
49
  // 发送消息
49
50
  webView.postMessage({
50
51
  type: 'qq-bot.init',
package/lib/hook.js CHANGED
@@ -29,27 +29,27 @@ const useMode = (event) => {
29
29
  const tag = event.tag;
30
30
  let currentMode = 'group';
31
31
  // 群at
32
- if (tag == 'GROUP_AT_MESSAGE_CREATE') {
32
+ if (tag === 'GROUP_AT_MESSAGE_CREATE') {
33
33
  currentMode = 'group';
34
34
  }
35
35
  // 私聊
36
- if (tag == 'C2C_MESSAGE_CREATE') {
36
+ if (tag === 'C2C_MESSAGE_CREATE') {
37
37
  currentMode = 'group';
38
38
  }
39
39
  // 频道私聊
40
- if (tag == 'DIRECT_MESSAGE_CREATE') {
40
+ if (tag === 'DIRECT_MESSAGE_CREATE') {
41
41
  currentMode = 'guild';
42
42
  }
43
43
  // 频道at
44
- if (tag == 'AT_MESSAGE_CREATE') {
44
+ if (tag === 'AT_MESSAGE_CREATE') {
45
45
  currentMode = 'guild';
46
46
  }
47
47
  // 频道消息
48
- if (tag == 'MESSAGE_CREATE') {
48
+ if (tag === 'MESSAGE_CREATE') {
49
49
  currentMode = 'guild';
50
50
  }
51
51
  const isMode = (mode) => {
52
- return currentMode == mode;
52
+ return currentMode === mode;
53
53
  };
54
54
  return isMode;
55
55
  };
package/lib/index.d.ts CHANGED
@@ -2,6 +2,6 @@ export { platform } from './config.js';
2
2
  export { useClient, useMode, useValue } from './hook.js';
3
3
  export { QQBotAPI as API } from './sdk/api.js';
4
4
 
5
- declare const _default: () => void;
5
+ declare const main: () => void;
6
6
 
7
- export { _default as default };
7
+ export { main as default };
package/lib/index.js CHANGED
@@ -6,18 +6,47 @@ export { useClient, useMode, useValue } from './hook.js';
6
6
  export { QQBotAPI as API } from './sdk/api.js';
7
7
 
8
8
  // main
9
- var index = () => {
9
+ const main = () => {
10
10
  let value = getConfigValue();
11
- if (!value)
11
+ if (!value) {
12
12
  value = {};
13
+ }
13
14
  const config = value[platform];
14
15
  if (config?.route || config?.port || config?.ws) {
15
16
  start();
16
- return;
17
17
  }
18
18
  else {
19
19
  start$1();
20
20
  }
21
21
  };
22
+ const mainProcess = () => {
23
+ ['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
24
+ process?.on?.(sig, () => {
25
+ logger?.info?.(`[@alemonjs/qq-bot][${sig}] 收到信号,正在关闭...`);
26
+ setImmediate(() => process.exit(0));
27
+ });
28
+ });
29
+ process?.on?.('exit', code => {
30
+ logger?.info?.(`[@alemonjs/qq-bot][exit] 进程退出,code=${code}`);
31
+ });
32
+ // 监听主进程消息
33
+ process.on('message', msg => {
34
+ try {
35
+ const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
36
+ if (data?.type === 'start') {
37
+ main();
38
+ }
39
+ else if (data?.type === 'stop') {
40
+ process.exit(0);
41
+ }
42
+ }
43
+ catch { }
44
+ });
45
+ // 主动发送 ready 消息
46
+ if (process.send) {
47
+ process.send(JSON.stringify({ type: 'ready' }));
48
+ }
49
+ };
50
+ mainProcess();
22
51
 
23
- export { index as default, platform };
52
+ export { main as default, platform };
@@ -4,7 +4,7 @@ import { getQQBotConfig } from './config.js';
4
4
 
5
5
  const start = () => {
6
6
  const config = getQQBotConfig();
7
- const { master_id, master_key, ...cfgConfig } = config;
7
+ const { master_id: _, master_key: __, ...cfgConfig } = config;
8
8
  const client = new QQBotClient({
9
9
  ...cfgConfig
10
10
  });
@@ -22,7 +22,7 @@ const start = () => {
22
22
  const isGroupIntents = ['GROUP_AND_C2C_EVENT'];
23
23
  const pubIntents = ['INTERACTION'];
24
24
  const intents = [];
25
- if (config?.mode == 'guild') {
25
+ if (config?.mode === 'guild') {
26
26
  if (config?.is_private) {
27
27
  intents.push(...isPrivateIntents, ...pubIntents);
28
28
  }
@@ -30,7 +30,7 @@ const start = () => {
30
30
  intents.push(...notPrivateIntents, ...pubIntents);
31
31
  }
32
32
  }
33
- else if (config?.mode == 'group') {
33
+ else if (config?.mode === 'group') {
34
34
  intents.push(...isGroupIntents, ...pubIntents);
35
35
  }
36
36
  else {
@@ -50,7 +50,7 @@ const start = () => {
50
50
  mode: config?.mode ?? 'group'
51
51
  });
52
52
  // 连接
53
- client.connect(config?.gatewayURL);
53
+ void client.connect(config?.gatewayURL);
54
54
  register(client);
55
55
  };
56
56
 
package/lib/register.js CHANGED
@@ -20,7 +20,7 @@ const register = (client) => {
20
20
  const createUserAvatarURL = (author_id) => {
21
21
  return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/640`;
22
22
  };
23
- client.on('GROUP_ADD_ROBOT', async (event) => {
23
+ client.on('GROUP_ADD_ROBOT', event => {
24
24
  // 机器人加入群组
25
25
  const e = {
26
26
  name: 'guild.join',
@@ -41,7 +41,7 @@ const register = (client) => {
41
41
  };
42
42
  cbp.send(e);
43
43
  });
44
- client.on('GROUP_DEL_ROBOT', async (event) => {
44
+ client.on('GROUP_DEL_ROBOT', event => {
45
45
  // 机器人离开群组
46
46
  const e = {
47
47
  name: 'guild.exit',
@@ -63,7 +63,7 @@ const register = (client) => {
63
63
  cbp.send(e);
64
64
  });
65
65
  // 监听消息
66
- client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
66
+ client.on('GROUP_AT_MESSAGE_CREATE', event => {
67
67
  const UserId = event.author.id;
68
68
  const [isMaster, UserKey] = getMaster(UserId);
69
69
  const UserAvatar = createUserAvatarURL(event.author.id);
@@ -91,7 +91,7 @@ const register = (client) => {
91
91
  };
92
92
  cbp.send(e);
93
93
  });
94
- client.on('C2C_MESSAGE_CREATE', async (event) => {
94
+ client.on('C2C_MESSAGE_CREATE', event => {
95
95
  const UserId = event.author.id;
96
96
  const [isMaster, UserKey] = getMaster(UserId);
97
97
  const UserAvatar = createUserAvatarURL(event.author.id);
@@ -120,11 +120,12 @@ const register = (client) => {
120
120
  /**
121
121
  * guild
122
122
  */
123
- client.on('DIRECT_MESSAGE_CREATE', async (event) => {
123
+ client.on('DIRECT_MESSAGE_CREATE', event => {
124
124
  // 屏蔽其他机器人的消息
125
- if (event?.author?.bot)
125
+ if (event?.author?.bot) {
126
126
  return;
127
- let msg = event?.content ?? '';
127
+ }
128
+ const msg = event?.content ?? '';
128
129
  const UserAvatar = event?.author?.avatar;
129
130
  const UserId = event.author.id;
130
131
  const [isMaster, UserKey] = getMaster(UserId);
@@ -152,11 +153,12 @@ const register = (client) => {
152
153
  cbp.send(e);
153
154
  });
154
155
  // 监听消息
155
- client.on('AT_MESSAGE_CREATE', async (event) => {
156
+ client.on('AT_MESSAGE_CREATE', event => {
156
157
  // 屏蔽其他机器人的消息
157
- if (event?.author?.bot)
158
+ if (event?.author?.bot) {
158
159
  return;
159
- let msg = getMessageContent(event);
160
+ }
161
+ const msg = getMessageContent(event);
160
162
  const UserAvatar = event?.author?.avatar;
161
163
  const UserId = event.author.id;
162
164
  const [isMaster, UserKey] = getMaster(UserId);
@@ -194,29 +196,31 @@ const register = (client) => {
194
196
  const getMessageContent = event => {
195
197
  let msg = event?.content ?? '';
196
198
  // 艾特消息处理
197
- const at_users = [];
199
+ const atUsers = [];
198
200
  if (event.mentions) {
199
201
  // 去掉@ 转为纯消息
200
202
  for (const item of event.mentions) {
201
- at_users.push({
203
+ atUsers.push({
202
204
  id: item.id
203
205
  });
204
206
  }
205
207
  // 循环删除文本中的at信息并去除前后空格
206
- at_users.forEach(item => {
208
+ atUsers.forEach(item => {
207
209
  msg = msg.replace(`<@!${item.id}>`, '').trim();
208
210
  });
209
211
  }
210
212
  return msg;
211
213
  };
212
214
  // 私域 -
213
- client.on('MESSAGE_CREATE', async (event) => {
215
+ client.on('MESSAGE_CREATE', event => {
214
216
  // 屏蔽其他机器人的消息
215
- if (event.author?.bot)
217
+ if (event.author?.bot) {
216
218
  return;
219
+ }
217
220
  // 撤回消息
218
- if (new RegExp(/DELETE$/).test(event.eventType))
221
+ if (new RegExp(/DELETE$/).test(event.eventType)) {
219
222
  return;
223
+ }
220
224
  const UserId = event.author.id;
221
225
  const msg = getMessageContent(event);
222
226
  const UserAvatar = event?.author?.avatar;
@@ -247,7 +251,7 @@ const register = (client) => {
247
251
  };
248
252
  cbp.send(e);
249
253
  });
250
- client.on('INTERACTION_CREATE', async (event) => {
254
+ client.on('INTERACTION_CREATE', event => {
251
255
  // try {
252
256
  // if (event.scene === 'group' || event.scene === 'c2c') {
253
257
  // await client.interactionResponse('group', event.id)
@@ -392,54 +396,79 @@ const register = (client) => {
392
396
  },
393
397
  use: {
394
398
  send: async (event, val) => {
395
- if (val.length < 0)
399
+ if (val.length < 0) {
396
400
  return [];
401
+ }
397
402
  // 打 tag
398
403
  const tag = event.tag;
399
404
  // 群at
400
- if (tag == 'GROUP_AT_MESSAGE_CREATE') {
405
+ if (tag === 'GROUP_AT_MESSAGE_CREATE') {
401
406
  return await GROUP_AT_MESSAGE_CREATE(client, event, val);
402
407
  }
403
408
  // 私聊
404
- if (tag == 'C2C_MESSAGE_CREATE') {
409
+ if (tag === 'C2C_MESSAGE_CREATE') {
405
410
  return await C2C_MESSAGE_CREATE(client, event, val);
406
411
  }
407
412
  // 频道私聊
408
- if (tag == 'DIRECT_MESSAGE_CREATE') {
413
+ if (tag === 'DIRECT_MESSAGE_CREATE') {
409
414
  return await DIRECT_MESSAGE_CREATE(client, event, val);
410
415
  }
411
416
  // 频道at
412
- if (tag == 'AT_MESSAGE_CREATE') {
417
+ if (tag === 'AT_MESSAGE_CREATE') {
413
418
  return await AT_MESSAGE_CREATE(client, event, val);
414
419
  }
415
420
  // 频道消息
416
- if (tag == 'MESSAGE_CREATE') {
421
+ if (tag === 'MESSAGE_CREATE') {
417
422
  return await MESSAGE_CREATE(client, event, val);
418
423
  }
419
424
  // 交互
420
- if (tag == 'INTERACTION_CREATE_GROUP') {
425
+ if (tag === 'INTERACTION_CREATE_GROUP') {
421
426
  return await GROUP_AT_MESSAGE_CREATE(client, event, val);
422
427
  }
423
- if (tag == 'INTERACTION_CREATE_C2C') {
428
+ if (tag === 'INTERACTION_CREATE_C2C') {
424
429
  return await C2C_MESSAGE_CREATE(client, event, val);
425
430
  }
426
- if (tag == 'INTERACTION_CREATE_GUILD') {
431
+ if (tag === 'INTERACTION_CREATE_GUILD') {
427
432
  return await AT_MESSAGE_CREATE(client, event, val);
428
433
  }
429
434
  return [];
430
435
  },
431
- mention: async (event) => {
432
- event.value || {};
433
- event.tag;
436
+ mention: event => {
437
+ const value = event.value || {};
438
+ const tag = event.tag;
434
439
  // const event = e.value
435
440
  const Metions = [];
436
441
  // group
437
- return Metions;
442
+ if (tag === 'GROUP_AT_MESSAGE_CREATE' || tag === 'C2C_MESSAGE_CREATE') {
443
+ // return Metions;
444
+ return new Promise(resolve => resolve(Metions));
445
+ }
446
+ // guild
447
+ if (value.mentions) {
448
+ const mentions = event.value['mentions'];
449
+ // 艾特消息处理
450
+ const MessageMention = mentions.map(item => {
451
+ const UserId = item.id;
452
+ const [isMaster, UserKey] = getMaster(UserId);
453
+ return {
454
+ UserId: item.id,
455
+ IsMaster: isMaster,
456
+ UserName: item.username,
457
+ IsBot: item.bot,
458
+ UserKey: UserKey
459
+ };
460
+ });
461
+ // return MessageMention;
462
+ return new Promise(resolve => resolve(MessageMention));
463
+ }
464
+ else {
465
+ // return Metions;
466
+ return new Promise(resolve => resolve(Metions));
467
+ }
438
468
  }
439
469
  }
440
470
  };
441
- // 处理行为
442
- cbp.onactions(async (data, consume) => {
471
+ const onactions = async (data, consume) => {
443
472
  if (data.action === 'message.send') {
444
473
  // 消息发送
445
474
  const event = data.payload.event;
@@ -469,9 +498,10 @@ const register = (client) => {
469
498
  const res = await api.active.send.user(user_id, paramFormat);
470
499
  consume(res);
471
500
  }
472
- });
473
- // 处理 api 调用
474
- cbp.onapis(async (data, consume) => {
501
+ };
502
+ // 处理行为
503
+ cbp.onactions((data, consume) => void onactions(data, consume));
504
+ const onapis = async (data, consume) => {
475
505
  const key = data.payload?.key;
476
506
  if (client[key]) {
477
507
  // 如果 client 上有对应的 key,直接调用。
@@ -479,7 +509,9 @@ const register = (client) => {
479
509
  const res = await client[key](...params);
480
510
  consume([createResult(ResultCode.Ok, '请求完成', res)]);
481
511
  }
482
- });
512
+ };
513
+ // 处理 api 调用
514
+ cbp.onapis((data, consume) => void onapis(data, consume));
483
515
  };
484
516
 
485
517
  export { register };
package/lib/sdk/api.d.ts CHANGED
@@ -15,13 +15,13 @@ declare class QQBotAPI {
15
15
  * @param config
16
16
  * @returns
17
17
  */
18
- groupService(options: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
18
+ groupService(options: AxiosRequestConfig): Promise<any>;
19
19
  /**
20
20
  * guild
21
21
  * @param opstion
22
22
  * @returns
23
23
  */
24
- guildServer(opstion: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
24
+ guildServer(opstion: AxiosRequestConfig): Promise<any>;
25
25
  /**
26
26
  * 得到鉴权
27
27
  * @returns
@@ -531,12 +531,12 @@ declare class QQBotAPI {
531
531
  * @param end_timestamp 日程结束时间戳
532
532
  * @param jump_channel_id 日程开始时跳转的子频道id
533
533
  * @param remind_type 日程提醒类型
534
- * 0 不提醒
535
- * 1 开始时提醒
536
- * 2 开始前 5 分钟提醒
537
- * 3 开始前 15 分钟提醒
538
- * 4 开始前 30 分钟提醒
539
- * 5 开始前 60 分钟提醒
534
+ * 0不提醒
535
+ * 1开始时提醒
536
+ * 2开始前 5 分钟提醒
537
+ * 3开始前 15 分钟提醒
538
+ * 4开始前 30 分钟提醒
539
+ * 5开始前 60 分钟提醒
540
540
  * @returns 返回 Schedule 对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
541
541
  */
542
542
  channelsSchedulesPost(channel_id: string, data: {
@@ -559,12 +559,12 @@ declare class QQBotAPI {
559
559
  * @param end_timestamp 日程结束时间戳
560
560
  * @param jump_channel_id 日程开始时跳转的子频道id
561
561
  * @param remind_type 日程提醒类型
562
- * 0 不提醒
563
- * 1 开始时提醒
564
- * 2 开始前 5 分钟提醒
565
- * 3 开始前 15 分钟提醒
566
- * 4 开始前 30 分钟提醒
567
- * 5 开始前 60 分钟提醒
562
+ * 0不提醒
563
+ * 1开始时提醒
564
+ * 2开始前 5 分钟提醒
565
+ * 3开始前 15 分钟提醒
566
+ * 4开始前 30 分钟提醒
567
+ * 5开始前 60 分钟提醒
568
568
  * @returns 返回 Schedule 对象(详见https://bot.q.qq.com/wiki/develop/api-v2/server-inter/channel/content/schedule/model.html#schedule)
569
569
  */
570
570
  channelsSchedulesSchedulePatch(channel_id: string, schedule_id: string, data: {