UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

59 lines (58 loc) 2.1 kB
/*! * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { RexReplyInteractionBase } from "./replyBase.js"; export class RexUpdateReplyInteractionBase extends RexReplyInteractionBase { constructor(inter, opt) { super(inter, opt); } update(options) { clearTimeout(this.debounceTimeout); clearTimeout(this.auditTimeout); this.auditLatestOptions = null; this.auditTimeout = undefined; const d = this.debounceResolve; const a = this.auditResolve; this.auditResolve = undefined; this.auditReject = undefined; this.debounceResolve = undefined; this.inter; return Promise.resolve(); } updateDebounce(options) { clearTimeout(this.debounceTimeout); const r = this.debounceResolve; return new Promise((resolve, reject) => { this.debounceResolve = resolve; this.debounceTimeout = setTimeout(() => { }, this.debounceDelay); }).finally(() => { if (r) r(); }); } updateAudit(options) { if (this.auditLatestOptions && this.auditTimeout && this.auditResolve) { const lastResolve = this.auditResolve; return new Promise((resolve, reject) => { this.auditResolve = resolve; this.auditReject = reject; this.auditLatestOptions = options; }).finally(lastResolve); } return new Promise((resolve, reject) => { this.auditResolve = resolve; this.auditReject = reject; this.auditLatestOptions = options; this.auditTimeout = setTimeout(() => { this.auditTimeout = undefined; this.auditLatestOptions = undefined; }, this.auditDelay); }); } deferUpdate(options) { return this.inter.deferUpdate(options); } }