UNPKG

ircgrampp

Version:

IRCGram++ is a complexly simple Telegram <-> IRC Gateway

67 lines (50 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _storage = _interopRequireDefault(require("./storage")); var _debug = _interopRequireDefault(require("debug")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const debug = { info: (0, _debug.default)('channels-info') }; const DB_NAME = 'Channels'; let instance; class ChannelsInfo extends _storage.default { constructor() { super(DB_NAME); } remove(channel, sync = true) { let channelId = typeof channel === "number" ? channel : channel.id; debug.info(`Remove channel info for ${channelId}`); return this.remove(x => x.id === channelId, sync); } find(cond) { debug.info(`Find channel ${cond}`); if (typeof cond === "number") { return super.find(x => x.id === cond); } else { return super.find(x => x.title === cond); } } save(channel, sync = true) { debug.info(`Save channel info for ${channel.id}`); var actual = this.find(x => x.id === channel.id); if (actual) { debug.info(`This exists, remove old`); this.remove(channel, false); } this.push(channel); if (sync) { this.sync(); } } static getInstance() { if (!instance) { instance = new ChannelsInfo(); } return instance; } } exports.default = ChannelsInfo;