mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-15 10:58:16 +00:00
a0a1554756
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { DiscordRole } from "../../types/discord.ts";
|
|
import { ToggleBitfield } from "./ToggleBitfield.ts";
|
|
|
|
export const RoleToggle = {
|
|
/** If this role is showed seperately in the user listing */
|
|
hoist: 1 << 0,
|
|
/** Whether this role is managed by an integration */
|
|
managed: 1 << 1,
|
|
/** Whether this role is mentionable */
|
|
mentionable: 1 << 2,
|
|
};
|
|
|
|
export class RoleToggles extends ToggleBitfield {
|
|
constructor(role: DiscordRole) {
|
|
super();
|
|
|
|
if (role.hoist) this.add(RoleToggle.hoist);
|
|
if (role.managed) this.add(RoleToggle.managed);
|
|
if (role.mentionable) this.add(RoleToggle.mentionable);
|
|
}
|
|
|
|
/** If this role is showed seperately in the user listing */
|
|
get hoist() {
|
|
return this.has("hoist");
|
|
}
|
|
|
|
/** Whether this role is managed by an integration */
|
|
get managed() {
|
|
return this.has("managed");
|
|
}
|
|
|
|
/** Whether this role is mentionable */
|
|
get mentionable() {
|
|
return this.has("mentionable");
|
|
}
|
|
|
|
/** Checks whether or not the permissions exist in this */
|
|
has(permissions: RoleToggleKeys | RoleToggleKeys[]) {
|
|
if (!Array.isArray(permissions)) return super.contains(RoleToggle[permissions]);
|
|
|
|
return super.contains(permissions.reduce((a, b) => (a |= RoleToggle[b]), 0));
|
|
}
|
|
|
|
/** Lists all the toggles for the role and whether or not each is true or false. */
|
|
list() {
|
|
const json = {};
|
|
for (const [key, value] of Object.entries(RoleToggle)) {
|
|
// @ts-ignore
|
|
json[key] = super.contains(value);
|
|
}
|
|
|
|
return json as Record<RoleToggleKeys, boolean>;
|
|
}
|
|
}
|
|
|
|
export type RoleToggleKeys = keyof typeof RoleToggle;
|