/** * Checks if the user has a specific permission. * @param {string|Array<string>} perms The permission(s) to check. * @example * const member = client.guilds.first().members.first(); * member.perms.has("ADMINISTRATOR"); * @returns {Boolean} */ has(perms) { if (Array.isArray(perms)) { const results = perms.map(p => this.has(p)); if (results.includes(r => !Boolean(r))) return false; return true; } else { if (!PERMISSIONS[perms.toUpperCase()]) throw new Error("Invalid permission passed"); return Boolean(this.total & PERMISSIONS[perms.toUpperCase()]); } }
/** * 验证Http Method * * @param {String|Array} name - 名称,如 get post put */ function assertMethod(name) { let valid = false; const method = this.method; if (typeof name === 'string') { valid = name.toUpperCase() === method; } else if (Array.isArray(name)) { valid = name.some(item => { return item.toUpperCase() === method; }); } if (!valid) { this.throw(401, `invalid request method, expect: ${name}, actual: ${method}`); } }
like(methods = ['HI', 'HI_CA', 'AAT', 'WCI']) { if (typeof methods === 'string') { const method = this._methods[methods.toUpperCase()]; if (method) { return this[method](); let count = methods.length; for (const m of methods) { const method = this._methods[m.toUpperCase()]; if (method) { try {
/** * 验证Http Method * * @param {String|Array} name - 名称,如 get post put */ function assertMethod(name) { let valid = false; const method = this.method; if (typeof name === 'string') { valid = name.toUpperCase() === method; } else if (Array.isArray(name)) { valid = name.some(item => { return item.toUpperCase() === method; }); } if (!valid) { this.throw(401, `invalid request method, expect: ${name}, actual: ${method}`); } }