@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
119 lines • 4.45 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WechatySkeleton = void 0;
/**
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
*
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
* Wechaty Contributors <https://github.com/wechaty>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const memory_card_1 = require("memory-card");
const wechaty_puppet_1 = require("@juzi/wechaty-puppet");
const UUID = __importStar(require("uuid"));
const mod_js_1 = require("../schemas/mod.js");
class WechatySkeleton extends mod_js_1.WechatyEventEmitter {
static log = wechaty_puppet_1.log;
log = wechaty_puppet_1.log;
/**
* the UUID of the Wechaty
* @ignore
*/
id;
__memory;
get memory() {
if (!this.__memory) {
throw new Error('NOMEMORY');
}
return this.__memory;
}
__options;
constructor(...args) {
wechaty_puppet_1.log.verbose('WechatySkeleton', 'constructor()');
super();
this.id = UUID.v4();
this.__options = args[0] || {};
/**
* Huan(202008):
*
* Set max listeners to 1K, so that we can add lots of listeners without the warning message.
* The listeners might be one of the following functionilities:
* 1. Plugins
* 2. Redux Observables
* 3. etc...
*/
super.setMaxListeners(1024);
}
/**
* Initialize the Wechaty instance for ready to be started.
*
* 1. It will be called automatically by the start()
* 2. It should be allowed for being called multiple times in the same instance,
* by skipping the second time initialization.
*/
async init() {
wechaty_puppet_1.log.verbose('WechatySkeleton', 'init()');
if (!this.__memory) {
this.__memory = new memory_card_1.MemoryCard(this.__options.name);
try {
await this.__memory.load();
}
catch (_) {
wechaty_puppet_1.log.silly('WechatySkeleton', 'onStart() memory.load() had already loaded');
}
}
}
async start() {
wechaty_puppet_1.log.verbose('WechatySkeleton', 'start()');
// no super.start()
/**
* Huan(202203): Call the init() functions (with super.init() inside them for chaining)
*/
await this.init();
}
async stop() {
wechaty_puppet_1.log.verbose('WechatySkeleton', 'stop()');
// no super.stop()
}
on(event, listener) {
wechaty_puppet_1.log.verbose('WechatySkeleton', 'on(%s, listener) registering... listenerCount: %s', event, this.listenerCount(event));
return super.on(event, listener);
}
}
exports.WechatySkeleton = WechatySkeleton;
//# sourceMappingURL=wechaty-skeleton.js.map