UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

47 lines (46 loc) 1.93 kB
"use strict"; /* eslint-disable @typescript-eslint/ban-ts-comment */ Object.defineProperty(exports, "__esModule", { value: true }); exports.resolvePermissions = void 0; const validatePermission_1 = require("./validatePermission"); const structures_1 = require("../structures"); /** * Resolve the permissions of the command. * @param permissions The permissions to resolve. * @param ctx The context of the command. * @returns The result of the permission check. */ // eslint-disable-next-line @typescript-eslint/ban-types async function resolvePermissions(permissions, ctx) { const requiredPerms = []; for (const permission of permissions) { if (typeof permission === 'object') { assertPermissionToObj(permission); for (const permissionRecord of Object.entries(permission)) { let validateAny = false; for (const perm of permissionRecord[1]) { if (validateAny) break; if (await (0, validatePermission_1.validatePermission)(perm, ctx)) validateAny = true; } // @ts-expect-error const value = permissionRecord[0].prototype instanceof structures_1.BasePermission ? new permissionRecord[0]().value : permissionRecord[0]; if (!validateAny) requiredPerms.push(value); } } else { // @ts-expect-error const value = permission.prototype instanceof structures_1.BasePermission ? new permission().value : permission; if (!await (0, validatePermission_1.validatePermission)(permission, ctx)) requiredPerms.push(value); } } return { passed: requiredPerms.length === 0, requiredPerms }; } exports.resolvePermissions = resolvePermissions; function assertPermissionToObj(permission) { }