UNPKG

@juzi/wechaty-puppet-whatsapp

Version:
48 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMaxTimestampForLoadHistoryMessages = exports.batchProcess = exports.getInviteCode = exports.isInviteLink = exports.isContactId = exports.isRoomId = exports.sleep = void 0; const config_js_1 = require("../config.js"); const InviteLinkRegex = /^(https?:\/\/)?chat\.whatsapp\.com\/(?:invite\/)?([a-zA-Z0-9_-]{22})$/; const sleep = async (milliseconds) => { if (milliseconds) { await new Promise(resolve => setTimeout(resolve, milliseconds)); } }; exports.sleep = sleep; const isRoomId = (id) => { return /@g.us$/i.test(id); }; exports.isRoomId = isRoomId; const isContactId = (id) => { return /@c.us$/i.test(id); }; exports.isContactId = isContactId; const isInviteLink = (link) => { return InviteLinkRegex.test(link); }; exports.isInviteLink = isInviteLink; const getInviteCode = (link) => { const matched = link.match(InviteLinkRegex); if (matched) { if (matched.length === 3) { const inviteCode = matched[2]; return inviteCode; } } return undefined; }; exports.getInviteCode = getInviteCode; const batchProcess = async (batchSize, list, func) => { let index = 0; while (batchSize * index < list.length) { const curList = list.slice(batchSize * index, batchSize * (index + 1)); await Promise.all(curList.map(func)); index++; } }; exports.batchProcess = batchProcess; const getMaxTimestampForLoadHistoryMessages = () => { return Math.floor(Date.now() / 1000) - config_js_1.HISTORY_MESSAGES_DAYS * 24 * 3600; }; exports.getMaxTimestampForLoadHistoryMessages = getMaxTimestampForLoadHistoryMessages; //# sourceMappingURL=miscellaneous.js.map