@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
53 lines • 3.14 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvancedCommand = void 0;
const bento_1 = require("@ayanaware/bento");
const CommandManager_1 = require("../CommandManager");
const OptionType_1 = require("../constants/OptionType");
class AdvancedCommand {
constructor() {
this.name = '@ayanaware/bentocord:AdvancedCommand';
this.parent = CommandManager_1.CommandManager;
this.replaceable = true;
this.definition = {
name: ['advanced', { key: 'BENTOCORD_COMMAND_ADV' }],
description: { key: 'BENTOCORD_COMMAND_ADV_DESCRIPTION', backup: 'Run non-slash exposed commands' },
options: [
{ type: OptionType_1.OptionType.STRING, name: ['alias', { key: 'BENTOCORD_OPTION_ALIAS' }], description: { key: 'BENTOCORD_OPTION_ALIAS_DESCRIPTION', backup: 'Command name or alias' } },
{ type: OptionType_1.OptionType.STRING, name: ['options', { key: 'BENTOCORD_OPTION_OPTIONS' }], description: { key: 'BENTOCORD_OPTION_OPTIONS_DESCRIPTION', backup: 'Command arguments to pass' }, required: false, rest: true },
],
registerSlash: true,
disablePrefix: true,
};
}
async execute(ctx, options) {
const aliases = await this.cm.getItemTranslations(this.definition.name, true);
if (aliases.some(a => a[0] === options.alias.toLocaleLowerCase()))
return ctx.createTranslatedResponse('BENTOCORD_ADV_NO_RECURSIVE', {}, 'Recursive execution is not allowed.');
const command = this.cm.findCommand(options.alias);
if (!command)
return ctx.createTranslatedResponse('BENTOCORD_ADV_NOTEXIST', { command: options.alias }, 'Command "{command}" does not exist in CommandManager');
const definition = command.definition;
// pre-flight checks, perms, suppressors, etc
if (!(await this.cm.prepareCommand(command, ctx)))
return;
// fufill options
const cmdOptions = await this.cm.fufillTextOptions(ctx, definition, options.options);
return this.cm.executeCommand(command, ctx, cmdOptions);
}
}
__decorate([
(0, bento_1.Inject)(),
__metadata("design:type", CommandManager_1.CommandManager)
], AdvancedCommand.prototype, "cm", void 0);
exports.AdvancedCommand = AdvancedCommand;
//# sourceMappingURL=Advanced.js.map