wechaty-puppet-padplus
Version:
Puppet Padplus for Wechaty
70 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const wechaty_puppet_1 = require("wechaty-puppet");
const is_type_1 = require("./is-type");
/**
*
* 2. Room Leave Event
*
*
* try to find 'leave' event for Room
*
* 1.
* You removed "李卓桓" from the group chat
* You were removed from the group chat by "李卓桓"
* 2.
* 你将"Huan LI++"移出了群聊
* 你被"李卓桓"移出群聊
*/
const ROOM_LEAVE_OTHER_REGEX_LIST = [
/^(You) removed "(.+)" from the group chat/,
/^(你)将"(.+)"移出了群聊/,
];
const ROOM_LEAVE_BOT_REGEX_LIST = [
/^(You) were removed from the group chat by "([^"]+)"/,
/^(你)被"([^"]+?)"移出群聊/,
];
function roomLeaveEventMessageParser(rawPayload) {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
const roomId = rawPayload.fromUserName;
const content = rawPayload.content;
const timestamp = rawPayload.createTime;
if (!roomId) {
return null;
}
if (!is_type_1.isRoomId(roomId)) {
return null;
}
let matchesForOther = [];
ROOM_LEAVE_OTHER_REGEX_LIST.some(regex => !!(matchesForOther = content.match(regex)));
let matchesForBot = [];
ROOM_LEAVE_BOT_REGEX_LIST.some(re => !!(matchesForBot = content.match(re)));
const matches = matchesForOther || matchesForBot;
if (!matches) {
return null;
}
let leaverName;
let removerName;
if (matchesForOther) {
removerName = wechaty_puppet_1.YOU;
leaverName = matchesForOther[2];
}
else if (matchesForBot) {
removerName = matchesForBot[2];
leaverName = wechaty_puppet_1.YOU;
}
else {
throw new Error('for typescript type checking, will never go here');
}
const roomLeaveEvent = {
leaverNameList: [leaverName],
removerName,
roomId,
timestamp,
};
return roomLeaveEvent;
}
exports.roomLeaveEventMessageParser = roomLeaveEventMessageParser;
//# sourceMappingURL=room-event-leave-message-parser.js.map