2021-05-31 03:30:55 +02:00
|
|
|
import { Permissions } from "discord.js";
|
2020-08-07 01:21:31 +03:00
|
|
|
|
|
|
|
const permissionNumberToName: Map<bigint, string> = new Map();
|
|
|
|
const ignoredPermissionConstants = ["all", "allGuild", "allText", "allVoice"];
|
|
|
|
|
2021-05-31 03:30:55 +02:00
|
|
|
for (const key in Permissions.FLAGS) {
|
2020-08-07 01:21:31 +03:00
|
|
|
if (ignoredPermissionConstants.includes(key)) continue;
|
2021-07-29 13:00:32 +01:00
|
|
|
permissionNumberToName.set(BigInt(Permissions.FLAGS[key]), key);
|
2020-08-07 01:21:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param permissions Bitmask of permissions to get the names for
|
|
|
|
*/
|
|
|
|
export function getPermissionNames(permissions: number | bigint): string[] {
|
2020-11-09 20:03:57 +02:00
|
|
|
const permissionNames: string[] = [];
|
2020-08-07 01:21:31 +03:00
|
|
|
for (const [permissionNumber, permissionName] of permissionNumberToName.entries()) {
|
|
|
|
if (BigInt(permissions) & permissionNumber) {
|
|
|
|
permissionNames.push(permissionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissionNames;
|
|
|
|
}
|