UNPKG

@juzi/wechaty-puppet-whatsapp

Version:
63 lines 1.83 kB
import { EventEmitter as EE } from 'ee-ts'; import { MEMORY_SLOT } from '../config.js'; import { WA_ERROR_TYPE } from '../exception/error-type.js'; import WAError from '../exception/whatsapp-error.js'; export default class WhatsAppBase extends EE { 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 WAError(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 WAError(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(MEMORY_SLOT, session); await memoryCard.save(); } async clearSession() { const memoryCard = this.manager.getMemory(); await memoryCard.delete(MEMORY_SLOT); await memoryCard.save(); } } //# sourceMappingURL=whatsapp-base.js.map