commandbot
Version:
A framework that helps you create your own Discord bot easier.
61 lines (60 loc) • 2.57 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermissionCommand = void 0;
const errors_js_1 = require("../../errors.js");
const CommandPermissions_js_1 = require("../../structures/CommandPermissions.js");
const FunctionCommand_js_1 = require("./FunctionCommand.js");
/**
* Executable command with attached permission system
* @class
* @extends {FunctionCommand}
*/
class PermissionCommand extends FunctionCommand_js_1.FunctionCommand {
/**
* Constructor of command with attached permissions
* @constructor
* @param {CommandManager} manager - command manager attached to this command
* @param {CommandType} type - command type
* @param {PermissionCommandInit} options - command initalization options
*/
constructor(manager, type, options) {
super(manager, type, {
name: options.name,
announceSuccess: options.announceSuccess,
default_permission: options.default_permission,
ephemeral: options.ephemeral,
function: options.function,
});
this.permissions = new CommandPermissions_js_1.CommandPermissions(this, options.permissions);
}
/**
* Invoke the command
* @param {InputManager} input - input data
* @returns {Promise<void>}
* @public
* @async
*/
start(input) {
const _super = Object.create(null, {
start: { get: () => super.start }
});
return __awaiter(this, void 0, void 0, function* () {
if (this.permissions.check(input.interaction)) {
yield _super.start.call(this, input);
}
else {
throw new errors_js_1.PermissionsError(this);
}
});
}
}
exports.PermissionCommand = PermissionCommand;