UNPKG

dexare

Version:

Modular and extendable Discord bot framework

72 lines (71 loc) 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 logger_1 = __importDefault(require("./util/logger")); /** A data manager for Dexare. */ class DataManager { constructor(client, options) { this.options = options; this.client = client; this.logger = new logger_1.default(this.client, this.options.name); } /** Fired when the manager is signaled to start. */ async start() { } /** Fired when the manager is signaled to stop. */ async stop() { } /** * Gets the throttle result from an ID and scope. * @param scope The scope of the throttles * @param id The ID of the throttle * @returns The Throttle result, if any */ async getThrottle(scope, id) { return; } /** * Sets the throttle result to an ID and scope. * @param scope The scope of the throttles * @param id The ID of the throttle * @param object The throttle to set */ async setThrottle(scope, id, object) { return; } /** * Removes a throttle object. * @param scope The scope of the throttles * @param id The ID of the throttle */ async removeThrottle(scope, id) { return; } /** * Throttles something. * @param scope The group to put the throttle in * @param opts The throttling options to use * @param id The identifier of the throttle * @param event The event to use */ async throttle(scope, opts, id, event) { let throttle = await this.getThrottle(scope, id); if (!throttle || throttle.reset < Date.now()) { throttle = { reset: Date.now() + opts.duration * 1000, uses: opts.usages }; } const okay = throttle.uses > 0; if (okay) { throttle.uses--; await this.setThrottle(scope, id, throttle); } return { okay, reset: throttle.reset, usesLeft: throttle.uses }; } } exports.default = DataManager;