UNPKG

dexare

Version:

Modular and extendable Discord bot framework

42 lines (41 loc) 1.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const dataManager_1 = __importDefault(require("../dataManager")); /** Data manager in Dexare using memory. */ class MemoryDataManager extends dataManager_1.default { constructor(client) { super(client, { name: 'memory-data', description: 'Dexare data manager using memory.' }); /** Current throttle objects for commands, mapped by scope and ID. */ this._throttles = new Map(); this.filePath = __filename; } async getThrottle(scope, id) { return this._throttles.get([scope, id].join(MemoryDataManager.SEPARATOR)); } async setThrottle(scope, id, object) { this._throttles.set([scope, id].join(MemoryDataManager.SEPARATOR), object); return; } async removeThrottle(scope, id) { this._throttles.delete([scope, id].join(MemoryDataManager.SEPARATOR)); return; } /** * Flushes any expired throttles. */ flushThrottles() { for (const key in this._throttles) { const throttle = this._throttles.get(key); if (throttle && throttle.reset < Date.now()) this._throttles.delete(key); } } } exports.default = MemoryDataManager; MemoryDataManager.SEPARATOR = '|';