UNPKG

@juzi/wechaty-puppet-whatsapp

Version:
69 lines 2.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ee_ts_1 = require("ee-ts"); const config_js_1 = require("../config.js"); const error_type_js_1 = require("../exception/error-type.js"); const whatsapp_error_js_1 = __importDefault(require("../exception/whatsapp-error.js")); class WhatsAppBase extends ee_ts_1.EventEmitter { manager; static _botId; static _whatsAppClient; pendingLogoutEmitTimer; get botId() { return WhatsAppBase._botId; } set botId(value) { WhatsAppBase._botId = value; } get whatsAppClient() { return WhatsAppBase._whatsAppClient; } set whatsAppClient(value) { WhatsAppBase._whatsAppClient = value; } constructor(manager) { super(); this.manager = manager; } baseStop() { this.botId = undefined; this.whatsAppClient = undefined; this.clearPendingLogoutEmitTimer(); } getBotId() { if (!this.botId) { throw (0, whatsapp_error_js_1.default)(error_type_js_1.WA_ERROR_TYPE.ERR_INIT, 'This bot is not login'); } return this.botId; } clearPendingLogoutEmitTimer() { if (this.pendingLogoutEmitTimer) { clearTimeout(this.pendingLogoutEmitTimer); this.pendingLogoutEmitTimer = undefined; } } getWhatsAppClient() { if (!this.whatsAppClient) { throw (0, whatsapp_error_js_1.default)(error_type_js_1.WA_ERROR_TYPE.ERR_INIT, 'Not init whatsapp'); } return this.whatsAppClient; } /** * MemoryCard Session Section */ async setSession(session) { const memoryCard = this.manager.getMemory(); await memoryCard.set(config_js_1.MEMORY_SLOT, session); await memoryCard.save(); } async clearSession() { const memoryCard = this.manager.getMemory(); await memoryCard.delete(config_js_1.MEMORY_SLOT); await memoryCard.save(); } } exports.default = WhatsAppBase; //# sourceMappingURL=whatsapp-base.js.map