@alemonjs/qq-bot 2.1.17 → 2.1.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/lib/hook.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EventKeys, Events } from 'alemonjs';
2
2
  import { GROUP_AT_MESSAGE_CREATE_TYPE } from './message/group/GROUP_AT_MESSAGE_CREATE';
3
+ import { GROUP_MESSAGE_CREATE_TYPE } from './message/group/GROUP_MESSAGE_CREATE';
3
4
  import { QQBotAPI as API } from './sdk/api';
4
5
  import { AT_MESSAGE_CREATE_TYPE } from './message/AT_MESSAGE_CREATE';
5
6
  import { INTERACTION_CREATE_TYPE } from './message/INTERACTION_CREATE';
@@ -28,8 +29,10 @@ import { GROUP_MSG_RECEIVE_TYPE } from './message/group/GROUP_MSG_RECEIVE';
28
29
  import { GROUP_MSG_REJECT_TYPE } from './message/group/GROUP_MSG_REJECT';
29
30
  import { C2C_MSG_RECEIVE_TYPE } from './message/group/C2C_MSG_RECEIVE';
30
31
  import { C2C_MSG_REJECT_TYPE } from './message/group/C2C_MSG_REJECT';
32
+ import { MESSAGE_AUDIT_PASS_TYPE } from './message/group/MESSAGE_AUDIT_PASS';
33
+ import { MESSAGE_AUDIT_REJECT_TYPE } from './message/group/MESSAGE_AUDIT_REJECT';
31
34
  type MAP = {
32
- 'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE | MESSAGE_CREATE_TYPE;
35
+ 'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | GROUP_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE | MESSAGE_CREATE_TYPE;
33
36
  'private.message.create': DIRECT_MESSAGE_CREATE_TYPE | C2C_MESSAGE_CREATE_TYPE;
34
37
  'interaction.create': INTERACTION_CREATE_TYPE;
35
38
  'private.interaction.create': INTERACTION_CREATE_TYPE;
@@ -49,7 +52,7 @@ type MAP = {
49
52
  'member.ban': undefined;
50
53
  'member.unban': undefined;
51
54
  'member.update': GUILD_MEMBER_UPDATE_TYPE;
52
- 'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE;
55
+ 'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE | MESSAGE_AUDIT_PASS_TYPE | MESSAGE_AUDIT_REJECT_TYPE;
53
56
  'private.message.update': undefined;
54
57
  'private.message.delete': DIRECT_MESSAGE_DELETE_TYPE;
55
58
  'private.friend.add': FRIEND_ADD_TYPE;
package/lib/hook.js CHANGED
@@ -16,6 +16,9 @@ const useMode = (event) => {
16
16
  if (tag === 'GROUP_AT_MESSAGE_CREATE') {
17
17
  currentMode = 'group';
18
18
  }
19
+ if (tag === 'GROUP_MESSAGE_CREATE') {
20
+ currentMode = 'group';
21
+ }
19
22
  if (tag === 'C2C_MESSAGE_CREATE') {
20
23
  currentMode = 'c2c';
21
24
  }
@@ -1,12 +1,27 @@
1
1
  export interface GROUP_AT_MESSAGE_CREATE_TYPE {
2
2
  author: {
3
+ bot?: boolean;
3
4
  id: string;
4
5
  member_openid: string;
6
+ union_openid: string;
5
7
  username: string;
6
8
  };
7
9
  content: string;
8
10
  group_openid: string;
9
11
  group_id: string;
10
12
  id: string;
13
+ mentions?: {
14
+ bot?: boolean;
15
+ id: string;
16
+ is_you?: boolean;
17
+ member_openid?: string;
18
+ scope?: string;
19
+ username: string;
20
+ }[];
11
21
  timestamp: string;
22
+ message_scene: {
23
+ ext: string[];
24
+ source: string;
25
+ };
26
+ message_type: number;
12
27
  }
@@ -0,0 +1,27 @@
1
+ export interface GROUP_MESSAGE_CREATE_TYPE {
2
+ author: {
3
+ bot?: boolean;
4
+ id: string;
5
+ member_openid: string;
6
+ union_openid: string;
7
+ username: string;
8
+ };
9
+ content: string;
10
+ group_openid: string;
11
+ group_id: string;
12
+ id: string;
13
+ mentions?: {
14
+ bot?: boolean;
15
+ id: string;
16
+ is_you?: boolean;
17
+ member_openid?: string;
18
+ scope?: string;
19
+ username: string;
20
+ }[];
21
+ timestamp: string;
22
+ message_scene: {
23
+ ext: string[];
24
+ source: string;
25
+ };
26
+ message_type: number;
27
+ }
@@ -0,0 +1,7 @@
1
+ export type MESSAGE_AUDIT_PASS_TYPE = {
2
+ audit_id: string;
3
+ audit_time: string;
4
+ create_time?: string;
5
+ group_openid?: string;
6
+ message_id?: string;
7
+ };
@@ -0,0 +1,7 @@
1
+ export type MESSAGE_AUDIT_REJECT_TYPE = {
2
+ audit_id: string;
3
+ audit_time: string;
4
+ create_time?: string;
5
+ group_openid?: string;
6
+ message_id?: string;
7
+ };
package/lib/register.js CHANGED
@@ -11,6 +11,34 @@ const register = (client) => {
11
11
  const createUserAvatarURL = (authorId) => {
12
12
  return `https://q.qlogo.cn/qqapp/${config.app_id}/${authorId}/640`;
13
13
  };
14
+ const getGroupMessageMeta = (event) => {
15
+ const author = event?.author;
16
+ const UserId = author?.id ?? '';
17
+ const memberOpenId = author?.member_openid ?? '';
18
+ const groupId = event?.group_id ?? event?.group_openid ?? '';
19
+ const messageId = event?.id ?? '';
20
+ const [isMaster, UserKey] = UserId ? getMaster(UserId) : [false, ''];
21
+ return {
22
+ UserId,
23
+ UserKey,
24
+ isMaster,
25
+ UserName: author?.username ?? '',
26
+ UserAvatar: UserId ? createUserAvatarURL(UserId) : '',
27
+ groupId,
28
+ messageId,
29
+ openId: memberOpenId ? `C2C:${memberOpenId}` : ''
30
+ };
31
+ };
32
+ const getGroupAuditMeta = (event) => {
33
+ const groupId = event?.group_openid ?? '';
34
+ const messageId = event?.message_id ?? event?.audit_id ?? '';
35
+ const auditTime = event?.audit_time ?? '';
36
+ return {
37
+ groupId,
38
+ messageId,
39
+ auditTime
40
+ };
41
+ };
14
42
  client.on('GROUP_ADD_ROBOT', event => {
15
43
  cbp.send(FormatEvent.create('guild.join')
16
44
  .addPlatform({ Platform: platform, value: event, BotId: botId })
@@ -41,25 +69,50 @@ const register = (client) => {
41
69
  .addMessage({ MessageId: '' })
42
70
  .add({ tag: 'GROUP_DEL_ROBOT' }).value);
43
71
  });
72
+ client.on('GROUP_MESSAGE_CREATE', event => {
73
+ if (event?.author?.bot) {
74
+ return;
75
+ }
76
+ const msg = getMessageContent(event);
77
+ const meta = getGroupMessageMeta(event);
78
+ cbp.send(FormatEvent.create('message.create')
79
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
80
+ .addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
81
+ .addChannel({ ChannelId: meta.groupId })
82
+ .addUser({
83
+ UserId: meta.UserId,
84
+ UserKey: meta.UserKey,
85
+ UserAvatar: meta.UserAvatar,
86
+ UserName: meta.UserName,
87
+ IsMaster: meta.isMaster,
88
+ IsBot: false
89
+ })
90
+ .addMessage({ MessageId: meta.messageId })
91
+ .addText({ MessageText: msg?.trim() })
92
+ .addOpen({ OpenId: meta.openId })
93
+ .add({ tag: 'GROUP_MESSAGE_CREATE' }).value);
94
+ });
44
95
  client.on('GROUP_AT_MESSAGE_CREATE', event => {
45
- const UserId = event.author.id;
46
- const [isMaster, UserKey] = getMaster(UserId);
47
- const UserAvatar = createUserAvatarURL(event.author.id);
96
+ if (event?.author?.bot) {
97
+ return;
98
+ }
99
+ const msg = getMessageContent(event);
100
+ const meta = getGroupMessageMeta(event);
48
101
  cbp.send(FormatEvent.create('message.create')
49
102
  .addPlatform({ Platform: platform, value: event, BotId: botId })
50
- .addGuild({ GuildId: event.group_id, SpaceId: `GROUP:${event.group_id}` })
51
- .addChannel({ ChannelId: event.group_id })
103
+ .addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
104
+ .addChannel({ ChannelId: meta.groupId })
52
105
  .addUser({
53
- UserId: event.author.id,
54
- UserKey,
55
- UserAvatar: UserAvatar,
56
- UserName: event?.author?.username,
57
- IsMaster: isMaster,
106
+ UserId: meta.UserId,
107
+ UserKey: meta.UserKey,
108
+ UserAvatar: meta.UserAvatar,
109
+ UserName: meta.UserName,
110
+ IsMaster: meta.isMaster,
58
111
  IsBot: false
59
112
  })
60
- .addMessage({ MessageId: event.id })
61
- .addText({ MessageText: event.content?.trim() })
62
- .addOpen({ OpenId: `C2C:${event.author.member_openid}` })
113
+ .addMessage({ MessageId: meta.messageId })
114
+ .addText({ MessageText: msg?.trim() })
115
+ .addOpen({ OpenId: meta.openId })
63
116
  .add({ tag: 'GROUP_AT_MESSAGE_CREATE' }).value);
64
117
  });
65
118
  client.on('C2C_MESSAGE_CREATE', event => {
@@ -395,6 +448,28 @@ const register = (client) => {
395
448
  .addMessage({ MessageId: `group_msg_reject_${event.group_openid}_${event.timestamp}` })
396
449
  .add({ tag: 'GROUP_MSG_REJECT' }).value);
397
450
  });
451
+ client.on('MESSAGE_AUDIT_PASS', event => {
452
+ const meta = getGroupAuditMeta(event);
453
+ cbp.send(FormatEvent.create('notice.create')
454
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
455
+ .addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
456
+ .addChannel({ ChannelId: meta.groupId })
457
+ .addUser({ UserId: '', UserKey: '', IsMaster: false, IsBot: false })
458
+ .addMessage({ MessageId: meta.messageId })
459
+ .addText({ MessageText: meta.auditTime })
460
+ .add({ tag: 'MESSAGE_AUDIT_PASS' }).value);
461
+ });
462
+ client.on('MESSAGE_AUDIT_REJECT', event => {
463
+ const meta = getGroupAuditMeta(event);
464
+ cbp.send(FormatEvent.create('notice.create')
465
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
466
+ .addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
467
+ .addChannel({ ChannelId: meta.groupId })
468
+ .addUser({ UserId: '', UserKey: '', IsMaster: false, IsBot: false })
469
+ .addMessage({ MessageId: meta.messageId })
470
+ .addText({ MessageText: meta.auditTime })
471
+ .add({ tag: 'MESSAGE_AUDIT_REJECT' }).value);
472
+ });
398
473
  client.on('C2C_MSG_RECEIVE', event => {
399
474
  cbp.send(FormatEvent.create('private.notice.create')
400
475
  .addPlatform({ Platform: platform, value: event, BotId: botId })
@@ -460,6 +535,9 @@ const register = (client) => {
460
535
  if (tag === 'GROUP_AT_MESSAGE_CREATE') {
461
536
  return await GROUP_AT_MESSAGE_CREATE(client, event, val);
462
537
  }
538
+ if (tag === 'GROUP_MESSAGE_CREATE') {
539
+ return await GROUP_AT_MESSAGE_CREATE(client, event, val);
540
+ }
463
541
  if (tag === 'C2C_MESSAGE_CREATE') {
464
542
  return await C2C_MESSAGE_CREATE(client, event, val);
465
543
  }
@@ -485,13 +563,9 @@ const register = (client) => {
485
563
  },
486
564
  mention: event => {
487
565
  const value = event.value || {};
488
- const tag = event._tag;
489
566
  const Metions = [];
490
- if (tag === 'GROUP_AT_MESSAGE_CREATE' || tag === 'C2C_MESSAGE_CREATE') {
491
- return new Promise(resolve => resolve(Metions));
492
- }
493
567
  if (value.mentions) {
494
- const mentions = event.value['mentions'];
568
+ const mentions = (event.value['mentions'] || []);
495
569
  const MessageMention = mentions.map(item => {
496
570
  const UserId = item.id;
497
571
  const [isMaster, UserKey] = getMaster(UserId);
@@ -499,7 +573,7 @@ const register = (client) => {
499
573
  UserId: item.id,
500
574
  IsMaster: isMaster,
501
575
  UserName: item.username,
502
- IsBot: item.bot,
576
+ IsBot: item.bot ?? false,
503
577
  UserKey: UserKey
504
578
  };
505
579
  });
@@ -3,9 +3,12 @@ import { C2C_MSG_REJECT_TYPE } from '../message/group/C2C_MSG_REJECT';
3
3
  import { C2C_MSG_RECEIVE_TYPE } from '../message/group/C2C_MSG_RECEIVE';
4
4
  import { GROUP_ADD_ROBOT_TYPE } from '../message/group/GROUP_ADD_ROBOT';
5
5
  import { GROUP_AT_MESSAGE_CREATE_TYPE } from '../message/group/GROUP_AT_MESSAGE_CREATE';
6
+ import { GROUP_MESSAGE_CREATE_TYPE } from '../message/group/GROUP_MESSAGE_CREATE';
6
7
  import { GROUP_DEL_ROBOT_TYPE } from '../message/group/GROUP_DEL_ROBOT';
7
8
  import { GROUP_MSG_RECEIVE_TYPE } from '../message/group/GROUP_MSG_RECEIVE';
8
9
  import { GROUP_MSG_REJECT_TYPE } from '../message/group/GROUP_MSG_REJECT';
10
+ import { MESSAGE_AUDIT_PASS_TYPE } from '../message/group/MESSAGE_AUDIT_PASS';
11
+ import { MESSAGE_AUDIT_REJECT_TYPE } from '../message/group/MESSAGE_AUDIT_REJECT';
9
12
  import { FRIEND_ADD_TYPE } from '../message/group/FRIEND_ADD';
10
13
  import { FRIEND_DEL_TYPE } from '../message/group/FRIEND_DEL';
11
14
  import { ERROR_TYPE } from '../message/ERROR';
@@ -15,9 +18,12 @@ export type QQBotGroupEventMap = {
15
18
  C2C_MSG_RECEIVE: C2C_MSG_RECEIVE_TYPE;
16
19
  GROUP_ADD_ROBOT: GROUP_ADD_ROBOT_TYPE;
17
20
  GROUP_AT_MESSAGE_CREATE: GROUP_AT_MESSAGE_CREATE_TYPE;
21
+ GROUP_MESSAGE_CREATE: GROUP_MESSAGE_CREATE_TYPE;
18
22
  GROUP_DEL_ROBOT: GROUP_DEL_ROBOT_TYPE;
19
23
  GROUP_MSG_RECEIVE: GROUP_MSG_RECEIVE_TYPE;
20
24
  GROUP_MSG_REJECT: GROUP_MSG_REJECT_TYPE;
25
+ MESSAGE_AUDIT_PASS: MESSAGE_AUDIT_PASS_TYPE;
26
+ MESSAGE_AUDIT_REJECT: MESSAGE_AUDIT_REJECT_TYPE;
21
27
  FRIEND_ADD: FRIEND_ADD_TYPE;
22
28
  FRIEND_DEL: FRIEND_DEL_TYPE;
23
29
  ERROR: ERROR_TYPE;
package/lib/sends.js CHANGED
@@ -17,6 +17,7 @@ const createButtonsData = (rows, startId = 0) => {
17
17
  id++;
18
18
  const typing = options?.type ?? 'command';
19
19
  const typeMap = { command: 2, link: 0, call: 1 };
20
+ const rowData = options?.rawData ?? {};
20
21
  return {
21
22
  id: String(id),
22
23
  render_data: {
@@ -27,14 +28,15 @@ const createButtonsData = (rows, startId = 0) => {
27
28
  action: {
28
29
  type: typeMap[typing],
29
30
  permission: {
30
- type: typeof options.permission?.type === 'undefined' ? 2 : options.permission.type,
31
- specify_user_ids: options.permission.userIds,
32
- specify_role_ids: options.permission.roleIds
31
+ type: typeof options.permission?.type === 'undefined' ? 2 : options?.permission?.type,
32
+ specify_user_ids: options?.permission?.userIds,
33
+ specify_role_ids: options?.permission?.roleIds
33
34
  },
34
35
  unsupport_tips: options?.toolTip ?? '',
35
36
  data: options?.data ?? '',
36
37
  at_bot_show_channel_list: false,
37
- enter: options?.autoEnter ?? false
38
+ enter: options?.autoEnter ?? false,
39
+ ...rowData
38
40
  }
39
41
  };
40
42
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.17",
3
+ "version": "2.1.19",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",