mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
* 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>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { DiscordUser } from "../../types/discord.ts";
|
|
import { ToggleBitfield } from "./ToggleBitfield.ts";
|
|
|
|
export const UserToggle = {
|
|
/** Whether the user belongs to an OAuth2 application */
|
|
bot: 1 << 0,
|
|
/** Whether the user is an Official Discord System user (part of the urgent message system) */
|
|
system: 1 << 1,
|
|
/** Whether the user has two factor enabled on their account */
|
|
mfaEnabled: 1 << 2,
|
|
/** Whether the email on this account has been verified */
|
|
verified: 1 << 3,
|
|
};
|
|
|
|
export class UserToggles extends ToggleBitfield {
|
|
constructor(user: DiscordUser) {
|
|
super();
|
|
|
|
if (user.bot) this.add(UserToggle.bot);
|
|
if (user.system) this.add(UserToggle.system);
|
|
if (user.mfa_enabled) this.add(UserToggle.mfaEnabled);
|
|
if (user.verified) this.add(UserToggle.verified);
|
|
}
|
|
|
|
/** Whether the user belongs to an OAuth2 application */
|
|
get bot() {
|
|
return this.has("bot");
|
|
}
|
|
|
|
/** Whether the user is an Official Discord System user (part of the urgent message system) */
|
|
get system() {
|
|
return this.has("system");
|
|
}
|
|
|
|
/** Whether the user has two factor enabled on their account */
|
|
get mfaEnabled() {
|
|
return this.has("mfaEnabled");
|
|
}
|
|
|
|
/** Whether the email on this account has been verified */
|
|
get verified() {
|
|
return this.has("verified");
|
|
}
|
|
|
|
/** Checks whether or not the permissions exist in this */
|
|
has(permissions: UserToggleKeys | UserToggleKeys[]) {
|
|
if (!Array.isArray(permissions)) return super.contains(UserToggle[permissions]);
|
|
|
|
return super.contains(permissions.reduce((a, b) => (a |= UserToggle[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(UserToggle)) {
|
|
// @ts-ignore
|
|
json[key] = super.contains(value);
|
|
}
|
|
|
|
return json as Record<UserToggleKeys, boolean>;
|
|
}
|
|
}
|
|
|
|
export type UserToggleKeys = keyof typeof UserToggle;
|