@wilcosp/rex
Version:
Rex is an automated command manager for discord js
74 lines (73 loc) • 2.65 kB
JavaScript
"use strict";
/*!
* 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/.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RexContextMenuCommand = void 0;
const zod_1 = require("zod");
const applicationCommandBase_js_1 = require("../applicationCommandBase.js");
const message_js_1 = require("../interactions/context/message.js");
const user_js_1 = require("../interactions/context/user.js");
class RexContextMenuCommand extends applicationCommandBase_js_1.RexApplicationCommandBase {
constructor(name, type, description = "") {
super(name, description, type);
this.name = name;
}
get commandInfo() {
const ref = this._commandInfo?.deref();
if (ref) {
return ref;
}
return {
id: this._commandId,
description: this._description,
name: this.name,
type: this._type,
nsfw: this.nsfw,
nameLocalizations: this.nameLocals,
descriptionLocalizations: this.descriptionLocals,
};
}
setExecute(fun) {
super.setExecute(fun);
return this;
}
toCommand() {
if (!this._execute) {
throw Error(`execute function of contextmenu command ${this.name} is missing`);
}
return super.toCommand();
}
run(inter) {
if (this._execute) {
return this._execute.apply(this.commandInfo, [
createInteraction(inter, {
autoDefer: this.autoDefer,
deferEphemeral: this.deferEphemeral,
debounceDelay: this.debounceDelay,
auditDelay: this.auditDelay,
useFailOver: this.useFailover,
}),
]);
}
}
static checkName(name) {
zod_1.z.string()
.regex(/^[ \p{L}\p{N}\p{sc=Deva}\p{sc=Thai}_-]{1,32}$/u, `${name} is not valid to the regex /^[ \p{L}\p{N}\p{sc=Deva}\p{sc=Thai}_-]{1,32}/u`)
.parse(name);
}
static checkDescription(name, description) {
}
}
exports.RexContextMenuCommand = RexContextMenuCommand;
function createInteraction(inter, opts) {
if (inter.isUserContextMenuCommand()) {
return new user_js_1.RexUserContextmenuInteraction(inter, opts);
}
if (inter.isMessageContextMenuCommand()) {
return new message_js_1.RexMessageContextmenuInteraction(inter, opts);
}
throw new Error("context menu interactio not supported");
}