commandbot
Version:
A framework that helps you create your own Discord bot easier.
62 lines (61 loc) • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandPermissions = void 0;
const discord_js_1 = require("discord.js");
/**
* Object that stores permission resolvables and properties (bouund to a {@link PermissionCommand})
* @class
*/
class CommandPermissions {
/**
* @constructor
* @param {PermissionCommand} command - command attached to this permissions object
* @param {?CommandPermissionsInit} [o] - initialization options
*/
constructor(command, o) {
var _a, _b;
this.command = command;
this.checkType = (_a = o === null || o === void 0 ? void 0 : o.checkType) !== null && _a !== void 0 ? _a : "ANY";
this.permissions = (o === null || o === void 0 ? void 0 : o.resolvable) instanceof Function ? o.resolvable : new discord_js_1.Permissions((_b = o === null || o === void 0 ? void 0 : o.resolvable) !== null && _b !== void 0 ? _b : BigInt(0));
}
/**
* Whether this object uses custom function to check permissions
* @type {boolean}
*/
get isCustom() {
return this.permissions instanceof Function ? true : false;
}
/**
* Permission bitfield
* @type {BigInt}
*/
get bitfield() {
return this.permissions instanceof Function ? BigInt(NaN) : BigInt(this.permissions.bitfield);
}
/**
* Checks if the interaction sender is permitted to use the command attached to this object
* @param {Interaction | Message} i - command interaction or Discord message
* @returns {boolean} Whether a sender can use the command bound to this object
* @public
*/
check(i) {
var _a, _b;
if (this.permissions instanceof Function) {
return this.permissions(i);
}
else {
if (this.permissions.bitfield === BigInt(0))
return true;
const memberPermissions = new discord_js_1.Permissions(typeof ((_a = i.member) === null || _a === void 0 ? void 0 : _a.permissions) === "string" ? BigInt(0) : (_b = i.member) === null || _b === void 0 ? void 0 : _b.permissions);
switch (this.checkType) {
case "ALL":
return memberPermissions.has(this.permissions);
case "ANY":
return memberPermissions.any(this.permissions);
default:
return false;
}
}
}
}
exports.CommandPermissions = CommandPermissions;