UNPKG

wechaty-puppet-padplus

Version:
53 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const wechaty_puppet_1 = require("wechaty-puppet"); const is_type_1 = require("./is-type"); /** * * 3. Room Topic Event * */ const ROOM_TOPIC_OTHER_REGEX_LIST = [ /^"(.+)" changed the group name to "(.+)"$/, /^"(.+)"修改群名为“(.+)”$/, ]; const ROOM_TOPIC_YOU_REGEX_LIST = [ /^(You) changed the group name to "(.+)"$/, /^(你)修改群名为“(.+)”$/, ]; function roomTopicEventMessageParser(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 = []; let matchesForYou = []; ROOM_TOPIC_OTHER_REGEX_LIST.some(regex => !!(matchesForOther = content.match(regex))); ROOM_TOPIC_YOU_REGEX_LIST.some(regex => !!(matchesForYou = content.match(regex))); const matches = matchesForOther || matchesForYou; if (!matches) { return null; } let changerName = matches[1]; const topic = matches[2]; if ((matchesForYou && changerName === '你') || changerName === 'You') { changerName = wechaty_puppet_1.YOU; } const roomTopicEvent = { changerName, roomId, timestamp, topic, }; return roomTopicEvent; } exports.roomTopicEventMessageParser = roomTopicEventMessageParser; //# sourceMappingURL=room-event-topic-message-parser.js.map