@wilcosp/rex
Version:
Rex is an automated command manager for discord js
71 lines (70 loc) • 2.29 kB
JavaScript
/*!
* 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 { RexModalSubmitInteraction } from "../interactions/modal/modalSubmit.js";
import { RexModal } from "./modal.js";
export class RexModalExecute extends RexModal {
constructor(options, title) {
super(options, title);
this.deferEphemeral = false;
}
setExecute(fun) {
this.execute = fun;
return this;
}
setAutoDefer(defer, ephemeral = false) {
this.autoDefer = defer;
this.deferEphemeral = ephemeral;
return this;
}
setDebounceDelay(delay) {
this.debounceDelay = delay;
return this;
}
setAuditDelay(delay) {
this.auditDelay = delay;
return this;
}
setUseFailOver(value) {
this.useFailover = value;
return this;
}
run(inter) {
if (this.execute) {
return this.execute.apply(null, [
new RexModalSubmitInteraction(inter, {
autoDefer: this.autoDefer,
deferEphemeral: this.deferEphemeral,
debounceDelay: this.debounceDelay,
auditDelay: this.auditDelay,
useFailOver: this.useFailover,
}),
]);
}
throw new TypeError(`Modal with Id ${this.data.custom_id} doesn't have an execute function set`);
}
toJSON() {
if (!this.execute) {
throw new TypeError(`Modal with Id ${this.data.custom_id} doesn't have an execute function set`);
}
return super.toJSON();
}
copy() {
const modal = new RexModalExecute(this.data).setExecute(this.execute).setComponents(this.components);
if (this.debounceDelay) {
modal.setDebounceDelay(this.debounceDelay);
}
if (this.auditDelay) {
modal.setAuditDelay(this.auditDelay);
}
if (this.autoDefer) {
modal.setAutoDefer(this.autoDefer, this.deferEphemeral);
}
if (this.useFailover) {
modal.setUseFailOver(this.useFailover);
}
return modal;
}
}