wechaty-puppet-padplus
Version:
Puppet Padplus for Wechaty
92 lines • 3.35 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const xml_to_json_1 = require("./xml-to-json");
const is_type_1 = require("./is-type");
/**
*
* 1. Friendship Confirm Event
*
*/
const FRIENDSHIP_CONFIRM_REGEX_LIST = [
/^You have added (.+) as your WeChat contact. Start chatting!$/,
/^你已添加了(.+),现在可以开始聊天了。$/,
/I've accepted your friend request. Now let's chat!$/,
/^(.+) just added you to his\/her contacts list. Send a message to him\/her now!$/,
/^(.+)刚刚把你添加到通讯录,现在可以开始聊天了。$/,
/^我通过了你的朋友验证请求,现在我们可以开始聊天了$/,
];
function friendshipConfirmEventMessageParser(rawPayload) {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
let matches = null;
const text = rawPayload.content;
FRIENDSHIP_CONFIRM_REGEX_LIST.some(regexp => {
matches = text.match(regexp);
return !!matches;
});
if (!matches) {
return null;
}
return rawPayload.fromUserName;
}
exports.friendshipConfirmEventMessageParser = friendshipConfirmEventMessageParser;
/**
*
* 2. Friendship Receive Event
*
*/
function friendshipReceiveEventMessageParser(rawPayload) {
return __awaiter(this, void 0, void 0, function* () {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
try {
const jsonPayload = yield xml_to_json_1.xmlToJson(rawPayload.content);
const contactId = jsonPayload.msg.$.fromusername;
if (is_type_1.isContactId(contactId)) {
return contactId;
}
}
catch (e) {
// not receive event
}
return null;
});
}
exports.friendshipReceiveEventMessageParser = friendshipReceiveEventMessageParser;
/**
*
* 3. Friendship Verify Event
*
*/
const FRIENDSHIP_VERIFY_REGEX_LIST = [
/^(.+) has enabled Friend Confirmation/,
/^(.+)开启了朋友验证,你还不是他(她)朋友。请先发送朋友验证请求,对方验证通过后,才能聊天。/,
];
function friendshipVerifyEventMessageParser(rawPayload) {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
let matches = null;
const text = rawPayload.content;
FRIENDSHIP_VERIFY_REGEX_LIST.some(regexp => {
matches = text.match(regexp);
return !!matches;
});
if (!matches) {
return null;
}
return rawPayload.fromUserName;
}
exports.friendshipVerifyEventMessageParser = friendshipVerifyEventMessageParser;
//# sourceMappingURL=friendship-event-message-parser.js.map