wechaty-puppet-matrix 0.0.35 → 0.0.36

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.
@@ -0,0 +1,8 @@
1
+ import type { MessagePayload } from '../../engine-schema.js';
2
+ import type * as PUPPET from '@juzi/wechaty-puppet';
3
+ import type { EventPayload } from './event.js';
4
+ export type Runner<T> = () => Promise<T | null>;
5
+ export declare function executeRunners<T>(runners: Runner<T>[]): Promise<T | null>;
6
+ declare const _default: (puppet: PUPPET.Puppet, message: MessagePayload) => Promise<EventPayload>;
7
+ export default _default;
8
+ //# sourceMappingURL=event-room-join-no-xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-room-join-no-xml.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join-no-xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA4B9C,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAEhD,wBAAsB,cAAc,CAAC,CAAC,EAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAShF;yBAEqB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAwHC"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeRunners = executeRunners;
4
+ const is_type_js_1 = require("../utils/is-type.js");
5
+ const types_js_1 = require("../types.js");
6
+ const YOU_INVITE_OTHER_REGEX_LIST = [
7
+ /^你邀请"(.+)"加入了群聊 {2}/,
8
+ /^You invited (.+) to the group chat/,
9
+ ];
10
+ const OTHER_INVITE_YOU_REGEX_LIST = [
11
+ /^"([^"]+?)"邀请你加入了群聊,群聊参与人还有:(.+)/,
12
+ /^(.+) invited you to a group chat with (.+)/,
13
+ ];
14
+ const OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST = [
15
+ /^"([^"]+?)"邀请你和"(.+?)"加入了群聊/,
16
+ /^(.+?) invited you and (.+?) to (the|a) group chat/,
17
+ ];
18
+ const OTHER_INVITE_OTHER_REGEX_LIST = [
19
+ /^"(.+)"邀请"(.+)"加入了群聊/,
20
+ /^(.+?) invited (.+?) to (the|a) group chat/,
21
+ ];
22
+ const OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST = [
23
+ /^"?(.+)"通过扫描你分享的二维码加入群聊/,
24
+ /^"?(.+)" joined group chat via the QR code you shared/,
25
+ ];
26
+ const OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST = [
27
+ /^"(.+)"通过扫描"(.+)"分享的二维码加入群聊/,
28
+ /^"(.+)" joined the group chat via the QR Code shared by "(.+)"/,
29
+ ];
30
+ async function executeRunners(runners) {
31
+ for (const runner of runners) {
32
+ const ret = await runner();
33
+ if (ret) {
34
+ return ret;
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ exports.default = async (puppet, message) => {
40
+ const roomId = message.fromWxid || '';
41
+ if (!(0, is_type_js_1.isRoomId)(roomId)) {
42
+ return null;
43
+ }
44
+ const timestamp = message.timeStamp;
45
+ if (message.msgType !== types_js_1.WechatMessageType.Sys && message.msgType !== types_js_1.WechatMessageType.SysTemplate) {
46
+ return null;
47
+ }
48
+ await puppet._updateRoom(roomId);
49
+ const youInviteOther = async () => {
50
+ let matches = null;
51
+ [...YOU_INVITE_OTHER_REGEX_LIST, ...OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST].some((re) => !!(matches = message.msg.match(re)));
52
+ if (matches) {
53
+ const inviteName = matches[1];
54
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteName))[0];
55
+ return {
56
+ inviteeIdList: [inviteeId],
57
+ inviterId: puppet.currentUserId,
58
+ roomId,
59
+ timestamp,
60
+ };
61
+ }
62
+ return null;
63
+ };
64
+ const otherInviteYou = async () => {
65
+ let matches = null;
66
+ OTHER_INVITE_YOU_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)));
67
+ if (matches) {
68
+ const inviteName = matches[1];
69
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviteName))[0];
70
+ return {
71
+ inviteeIdList: [puppet.currentUserId],
72
+ inviterId,
73
+ roomId,
74
+ timestamp,
75
+ };
76
+ }
77
+ return null;
78
+ };
79
+ const otherInviteOther = async () => {
80
+ let matches = null;
81
+ [...OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST, ...OTHER_INVITE_OTHER_REGEX_LIST].some((re) => !!(matches = message.msg.match(re)));
82
+ if (matches) {
83
+ const inviteeIdList = [];
84
+ const inviterName = matches[1];
85
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0];
86
+ const inviteeName = matches[2];
87
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0];
88
+ if (message.msg.includes('你')) {
89
+ inviteeIdList.push(puppet.currentUserId);
90
+ }
91
+ inviteeIdList.push(inviteeId);
92
+ return {
93
+ inviteeIdList,
94
+ inviterId,
95
+ roomId,
96
+ timestamp,
97
+ };
98
+ }
99
+ return null;
100
+ };
101
+ const otherJoinViaQrCode = async () => {
102
+ let matches = null;
103
+ OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)));
104
+ if (matches) {
105
+ const inviteeIdList = [];
106
+ const inviteeName = matches[1];
107
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0];
108
+ inviteeIdList.push(inviteeId);
109
+ const inviterName = matches[2];
110
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0];
111
+ return {
112
+ inviteeIdList,
113
+ inviterId,
114
+ roomId,
115
+ timestamp,
116
+ };
117
+ }
118
+ return null;
119
+ };
120
+ const ret = await executeRunners([youInviteOther, otherInviteYou, otherInviteOther, otherJoinViaQrCode]);
121
+ return ret;
122
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"event-room-join.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;yBAiCxB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAmKC"}
1
+ {"version":3,"file":"event-room-join.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;yBAiCxB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAsKC"}
@@ -39,6 +39,7 @@ exports.default = async (puppet, message) => {
39
39
  if (message.msgType !== types_js_1.WechatMessageType.Sys && message.msgType !== types_js_1.WechatMessageType.SysTemplate) {
40
40
  return null;
41
41
  }
42
+ await puppet._updateRoom(roomId);
42
43
  const jsonPayload = await (0, xml_to_json_js_1.xmlToJson)(message.msg);
43
44
  if (!jsonPayload
44
45
  || !jsonPayload.sysmsg
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/mod.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AASlE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/mod.ts"],"names":[],"mappings":"AAOA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAUlE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA"}
@@ -10,11 +10,13 @@ const event_room_join_js_1 = __importDefault(require("./event-room-join.js"));
10
10
  const event_room_leave_js_1 = __importDefault(require("./event-room-leave.js"));
11
11
  const event_room_topic_js_1 = __importDefault(require("./event-room-topic.js"));
12
12
  const event_message_js_1 = __importDefault(require("./event-message.js"));
13
+ const event_room_join_no_xml_js_1 = __importDefault(require("./event-room-join-no-xml.js"));
13
14
  const event_js_1 = require("./event.js");
14
15
  Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return event_js_1.EventType; } });
15
16
  Object.defineProperty(exports, "parseEvent", { enumerable: true, get: function () { return event_js_1.parseEvent; } });
16
17
  (0, event_js_1.addEventParser)(event_js_1.EventType.Friendship, event_friendship_js_1.default);
17
18
  (0, event_js_1.addEventParser)(event_js_1.EventType.RoomInvite, event_room_invite_js_1.default);
19
+ (0, event_js_1.addEventParser)(event_js_1.EventType.RoomJoin, event_room_join_no_xml_js_1.default);
18
20
  (0, event_js_1.addEventParser)(event_js_1.EventType.RoomJoin, event_room_join_js_1.default);
19
21
  (0, event_js_1.addEventParser)(event_js_1.EventType.RoomLeave, event_room_leave_js_1.default);
20
22
  (0, event_js_1.addEventParser)(event_js_1.EventType.RoomTopic, event_room_topic_js_1.default);
@@ -0,0 +1,8 @@
1
+ import type { MessagePayload } from '../../engine-schema.js';
2
+ import type * as PUPPET from '@juzi/wechaty-puppet';
3
+ import type { EventPayload } from './event.js';
4
+ export type Runner<T> = () => Promise<T | null>;
5
+ export declare function executeRunners<T>(runners: Runner<T>[]): Promise<T | null>;
6
+ declare const _default: (puppet: PUPPET.Puppet, message: MessagePayload) => Promise<EventPayload>;
7
+ export default _default;
8
+ //# sourceMappingURL=event-room-join-no-xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-room-join-no-xml.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join-no-xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA4B9C,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAEhD,wBAAsB,cAAc,CAAC,CAAC,EAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAShF;yBAEqB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAwHC"}
@@ -0,0 +1,119 @@
1
+ import { isRoomId } from '../utils/is-type.js';
2
+ import { WechatMessageType } from '../types.js';
3
+ const YOU_INVITE_OTHER_REGEX_LIST = [
4
+ /^你邀请"(.+)"加入了群聊 {2}/,
5
+ /^You invited (.+) to the group chat/,
6
+ ];
7
+ const OTHER_INVITE_YOU_REGEX_LIST = [
8
+ /^"([^"]+?)"邀请你加入了群聊,群聊参与人还有:(.+)/,
9
+ /^(.+) invited you to a group chat with (.+)/,
10
+ ];
11
+ const OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST = [
12
+ /^"([^"]+?)"邀请你和"(.+?)"加入了群聊/,
13
+ /^(.+?) invited you and (.+?) to (the|a) group chat/,
14
+ ];
15
+ const OTHER_INVITE_OTHER_REGEX_LIST = [
16
+ /^"(.+)"邀请"(.+)"加入了群聊/,
17
+ /^(.+?) invited (.+?) to (the|a) group chat/,
18
+ ];
19
+ const OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST = [
20
+ /^"?(.+)"通过扫描你分享的二维码加入群聊/,
21
+ /^"?(.+)" joined group chat via the QR code you shared/,
22
+ ];
23
+ const OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST = [
24
+ /^"(.+)"通过扫描"(.+)"分享的二维码加入群聊/,
25
+ /^"(.+)" joined the group chat via the QR Code shared by "(.+)"/,
26
+ ];
27
+ export async function executeRunners(runners) {
28
+ for (const runner of runners) {
29
+ const ret = await runner();
30
+ if (ret) {
31
+ return ret;
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+ export default async (puppet, message) => {
37
+ const roomId = message.fromWxid || '';
38
+ if (!isRoomId(roomId)) {
39
+ return null;
40
+ }
41
+ const timestamp = message.timeStamp;
42
+ if (message.msgType !== WechatMessageType.Sys && message.msgType !== WechatMessageType.SysTemplate) {
43
+ return null;
44
+ }
45
+ await puppet._updateRoom(roomId);
46
+ const youInviteOther = async () => {
47
+ let matches = null;
48
+ [...YOU_INVITE_OTHER_REGEX_LIST, ...OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST].some((re) => !!(matches = message.msg.match(re)));
49
+ if (matches) {
50
+ const inviteName = matches[1];
51
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteName))[0];
52
+ return {
53
+ inviteeIdList: [inviteeId],
54
+ inviterId: puppet.currentUserId,
55
+ roomId,
56
+ timestamp,
57
+ };
58
+ }
59
+ return null;
60
+ };
61
+ const otherInviteYou = async () => {
62
+ let matches = null;
63
+ OTHER_INVITE_YOU_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)));
64
+ if (matches) {
65
+ const inviteName = matches[1];
66
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviteName))[0];
67
+ return {
68
+ inviteeIdList: [puppet.currentUserId],
69
+ inviterId,
70
+ roomId,
71
+ timestamp,
72
+ };
73
+ }
74
+ return null;
75
+ };
76
+ const otherInviteOther = async () => {
77
+ let matches = null;
78
+ [...OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST, ...OTHER_INVITE_OTHER_REGEX_LIST].some((re) => !!(matches = message.msg.match(re)));
79
+ if (matches) {
80
+ const inviteeIdList = [];
81
+ const inviterName = matches[1];
82
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0];
83
+ const inviteeName = matches[2];
84
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0];
85
+ if (message.msg.includes('你')) {
86
+ inviteeIdList.push(puppet.currentUserId);
87
+ }
88
+ inviteeIdList.push(inviteeId);
89
+ return {
90
+ inviteeIdList,
91
+ inviterId,
92
+ roomId,
93
+ timestamp,
94
+ };
95
+ }
96
+ return null;
97
+ };
98
+ const otherJoinViaQrCode = async () => {
99
+ let matches = null;
100
+ OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)));
101
+ if (matches) {
102
+ const inviteeIdList = [];
103
+ const inviteeName = matches[1];
104
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0];
105
+ inviteeIdList.push(inviteeId);
106
+ const inviterName = matches[2];
107
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0];
108
+ return {
109
+ inviteeIdList,
110
+ inviterId,
111
+ roomId,
112
+ timestamp,
113
+ };
114
+ }
115
+ return null;
116
+ };
117
+ const ret = await executeRunners([youInviteOther, otherInviteYou, otherInviteOther, otherJoinViaQrCode]);
118
+ return ret;
119
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"event-room-join.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;yBAiCxB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAmKC"}
1
+ {"version":3,"file":"event-room-join.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/event-room-join.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;yBAiCxB,QAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAAC;AAA5F,wBAsKC"}
@@ -37,6 +37,7 @@ export default async (puppet, message) => {
37
37
  if (message.msgType !== WechatMessageType.Sys && message.msgType !== WechatMessageType.SysTemplate) {
38
38
  return null;
39
39
  }
40
+ await puppet._updateRoom(roomId);
40
41
  const jsonPayload = await xmlToJson(message.msg);
41
42
  if (!jsonPayload
42
43
  || !jsonPayload.sysmsg
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/mod.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AASlE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/matrix/events/mod.ts"],"names":[],"mappings":"AAOA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAUlE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA"}
@@ -4,9 +4,11 @@ import roomJoinParser from './event-room-join.js';
4
4
  import roomLeaveParser from './event-room-leave.js';
5
5
  import roomTopicParser from './event-room-topic.js';
6
6
  import messageParser from './event-message.js';
7
+ import roomJoinNoXmlParser from './event-room-join-no-xml.js';
7
8
  import { addEventParser, EventType, parseEvent } from './event.js';
8
9
  addEventParser(EventType.Friendship, friendShipParser);
9
10
  addEventParser(EventType.RoomInvite, roomInviteParser);
11
+ addEventParser(EventType.RoomJoin, roomJoinNoXmlParser);
10
12
  addEventParser(EventType.RoomJoin, roomJoinParser);
11
13
  addEventParser(EventType.RoomLeave, roomLeaveParser);
12
14
  addEventParser(EventType.RoomTopic, roomTopicParser);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-puppet-matrix",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Puppet matrix for Wechaty",
5
5
  "type": "module",
6
6
  "typings": "./dist/esm/src/mod.d.ts",
@@ -0,0 +1,165 @@
1
+ import type { MessagePayload } from '../../engine-schema.js'
2
+ import type * as PUPPET from '@juzi/wechaty-puppet'
3
+ import { isRoomId } from '../utils/is-type.js'
4
+ import type { EventPayload } from './event.js'
5
+ import { WechatMessageType } from '../types.js'
6
+
7
+ const YOU_INVITE_OTHER_REGEX_LIST = [
8
+ /^你邀请"(.+)"加入了群聊 {2}/,
9
+ /^You invited (.+) to the group chat/,
10
+ ]
11
+ const OTHER_INVITE_YOU_REGEX_LIST = [
12
+ /^"([^"]+?)"邀请你加入了群聊,群聊参与人还有:(.+)/,
13
+ /^(.+) invited you to a group chat with (.+)/,
14
+ ]
15
+ const OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST = [
16
+ /^"([^"]+?)"邀请你和"(.+?)"加入了群聊/,
17
+ /^(.+?) invited you and (.+?) to (the|a) group chat/,
18
+ ]
19
+ const OTHER_INVITE_OTHER_REGEX_LIST = [
20
+ /^"(.+)"邀请"(.+)"加入了群聊/,
21
+ /^(.+?) invited (.+?) to (the|a) group chat/,
22
+ ]
23
+ const OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST = [
24
+ /^"?(.+)"通过扫描你分享的二维码加入群聊/,
25
+ /^"?(.+)" joined group chat via the QR code you shared/,
26
+ ]
27
+ const OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST = [
28
+ /^"(.+)"通过扫描"(.+)"分享的二维码加入群聊/,
29
+ /^"(.+)" joined the group chat via the QR Code shared by "(.+)"/,
30
+ ]
31
+
32
+ export type Runner<T> = () => Promise<T | null>;
33
+
34
+ export async function executeRunners<T> (runners: Runner<T>[]): Promise<T | null> {
35
+ for (const runner of runners) {
36
+ const ret = await runner()
37
+ if (ret) {
38
+ return ret
39
+ }
40
+ }
41
+
42
+ return null
43
+ }
44
+
45
+ export default async (puppet: PUPPET.Puppet, message: MessagePayload): Promise<EventPayload> => {
46
+ const roomId = message.fromWxid || ''
47
+ if (!isRoomId(roomId)) {
48
+ return null
49
+ }
50
+
51
+ const timestamp = message.timeStamp
52
+ // 都是系统消息
53
+ if (message.msgType !== WechatMessageType.Sys && message.msgType !== WechatMessageType.SysTemplate) {
54
+ return null
55
+ }
56
+
57
+ // @ts-ignore
58
+ await puppet._updateRoom(roomId)
59
+ /**
60
+ * 1. You Invite Other to join the Room
61
+ * (including other join var qr code you shared)
62
+ * /^你邀请"(.+)"加入了群聊 {2}\$revoke\$/,
63
+ * /^" ?(.+)"通过扫描你分享的二维码加入群聊/,
64
+ */
65
+ const youInviteOther = async () => {
66
+ let matches: null | string[] = null;
67
+ [ ...YOU_INVITE_OTHER_REGEX_LIST, ...OTHER_JOIN_VIA_YOUR_QRCODE_REGEX_LIST ].some((re) => !!(matches = message.msg.match(re)))
68
+
69
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
70
+ if (matches) {
71
+ const inviteName = matches[1]!
72
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteName))[0]!
73
+
74
+ return {
75
+ inviteeIdList: [ inviteeId ],
76
+ inviterId: puppet.currentUserId,
77
+ roomId,
78
+ timestamp,
79
+ } as PUPPET.payloads.EventRoomJoin
80
+ }
81
+ return null
82
+ }
83
+
84
+ /**
85
+ * 2. Other Invite you to join the Room
86
+ * /^"([^"]+?)"邀请你加入了群聊/,
87
+ */
88
+ const otherInviteYou = async () => {
89
+ let matches: null | string[] = null
90
+ OTHER_INVITE_YOU_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)))
91
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
92
+ if (matches) {
93
+ const inviteName = matches[1]!
94
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviteName))[0]!
95
+
96
+ return {
97
+ inviteeIdList: [ puppet.currentUserId ],
98
+ inviterId,
99
+ roomId,
100
+ timestamp,
101
+ } as PUPPET.payloads.EventRoomJoin
102
+ }
103
+ return null
104
+ }
105
+
106
+ /**
107
+ * 3. Other invite you and others to join the room
108
+ * /^"([^"]+?)"邀请你和"(.+?)"加入了群聊/,
109
+ * /^"(.+)"邀请"(.+)"加入了群聊/,
110
+ */
111
+ const otherInviteOther = async () => {
112
+ let matches: null | string[] = null;
113
+ [ ...OTHER_INVITE_YOU_AND_OTHER_REGEX_LIST, ...OTHER_INVITE_OTHER_REGEX_LIST ].some((re) => !!(matches = message.msg.match(re)))
114
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
115
+ if (matches) {
116
+ const inviteeIdList = []
117
+ const inviterName = matches[1]
118
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0]
119
+ const inviteeName = matches[2]
120
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0]
121
+ // 如果包含ni则把机器人的id放进去
122
+ if (message.msg.includes('你')) {
123
+ inviteeIdList.push(puppet.currentUserId)
124
+ }
125
+ inviteeIdList.push(inviteeId)
126
+ return {
127
+ inviteeIdList,
128
+ inviterId,
129
+ roomId,
130
+ timestamp,
131
+ } as PUPPET.payloads.EventRoomJoin
132
+ }
133
+ return null
134
+ }
135
+
136
+ /**
137
+ * 4. Other Invite Other via Qrcode to join a Room
138
+ * /^" (.+)"通过扫描"(.+)"分享的二维码加入群聊/,
139
+ */
140
+ const otherJoinViaQrCode = async () => {
141
+ let matches: null | string[] = null
142
+ OTHER_JOIN_VIA_OTHER_QRCODE_REGEX_LIST.some((re) => !!(matches = message.msg.match(re)))
143
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
144
+ if (matches) {
145
+ const inviteeIdList = []
146
+
147
+ const inviteeName = matches[1]!
148
+ const inviteeId = (await puppet.roomMemberSearch(roomId, inviteeName))[0]!
149
+ inviteeIdList.push(inviteeId)
150
+
151
+ const inviterName = matches[2]
152
+ const inviterId = (await puppet.roomMemberSearch(roomId, inviterName))[0]!
153
+ return {
154
+ inviteeIdList,
155
+ inviterId,
156
+ roomId,
157
+ timestamp,
158
+ } as PUPPET.payloads.EventRoomJoin
159
+ }
160
+ return null
161
+ }
162
+ const ret = await executeRunners([ youInviteOther, otherInviteYou, otherInviteOther, otherJoinViaQrCode ])
163
+
164
+ return ret
165
+ }
@@ -46,6 +46,9 @@ export default async (puppet: PUPPET.Puppet, message: MessagePayload): Promise<E
46
46
  return null
47
47
  }
48
48
 
49
+ // @ts-ignore
50
+ await puppet._updateRoom(roomId)
51
+
49
52
  const jsonPayload = await xmlToJson(message.msg)
50
53
  if (
51
54
  !jsonPayload
@@ -4,10 +4,12 @@ import roomJoinParser from './event-room-join.js'
4
4
  import roomLeaveParser from './event-room-leave.js'
5
5
  import roomTopicParser from './event-room-topic.js'
6
6
  import messageParser from './event-message.js'
7
+ import roomJoinNoXmlParser from './event-room-join-no-xml.js'
7
8
  import { addEventParser, EventType, parseEvent } from './event.js'
8
9
 
9
10
  addEventParser(EventType.Friendship, friendShipParser)
10
11
  addEventParser(EventType.RoomInvite, roomInviteParser)
12
+ addEventParser(EventType.RoomJoin, roomJoinNoXmlParser)
11
13
  addEventParser(EventType.RoomJoin, roomJoinParser)
12
14
  addEventParser(EventType.RoomLeave, roomLeaveParser)
13
15
  addEventParser(EventType.RoomTopic, roomTopicParser)