mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 00:10:07 +00:00
* Migrate eslint and prettier to biomejs This does NOT include examples/bigbot as it has its own formatter * Update to biome 1.8.0 * Readd dotenv dev dependency to rest During a merge it got lost
21 lines
783 B
TypeScript
21 lines
783 B
TypeScript
import assert from 'node:assert'
|
|
import { BitwisePermissionFlags, type Guild, type Member } from '@discordeno/bot'
|
|
|
|
export async function calculateMemberPermissions(guild: Guild, member: Member): Promise<bigint> {
|
|
if (member.id === guild.ownerId) return 8n
|
|
|
|
let permissions = guild.roles.get(guild.id)?.permissions.bitfield
|
|
const rolePerms = member.roles.map((x) => guild.roles.get(x)?.permissions.bitfield).filter((x): x is bigint => x !== undefined)
|
|
|
|
// Small hack to avoid calling assert with 0n
|
|
if (permissions === undefined) assert(permissions)
|
|
|
|
for (const rolePerm of rolePerms) {
|
|
permissions |= rolePerm
|
|
}
|
|
|
|
if ((permissions & BigInt(BitwisePermissionFlags.ADMINISTRATOR)) === BigInt(BitwisePermissionFlags.ADMINISTRATOR)) return 8n
|
|
|
|
return permissions
|
|
}
|