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>
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import { DiscordUser, DiscordVoiceState } from "../../types/discord.ts";
|
|
import { ToggleBitfield } from "./ToggleBitfield.ts";
|
|
|
|
export const VoiceStateToggle = {
|
|
/** Whether this user is deafened by the server */
|
|
deaf: 1 << 0,
|
|
/** Whether this user is muted by the server */
|
|
mute: 1 << 1,
|
|
/** Whether this user is locally deafened */
|
|
selfDeaf: 1 << 2,
|
|
/** Whether this user is locally muted */
|
|
selfMute: 1 << 3,
|
|
/** Whether this user is streaming using "Go Live" */
|
|
selfStream: 1 << 4,
|
|
/** Whether this user's camera is enabled */
|
|
selfVideo: 1 << 5,
|
|
/** Whether this user is muted by the current user */
|
|
suppress: 1 << 6,
|
|
};
|
|
|
|
export class VoiceStateToggles extends ToggleBitfield {
|
|
constructor(voice: DiscordVoiceState) {
|
|
super();
|
|
|
|
if (voice.deaf) this.add(VoiceStateToggle.deaf);
|
|
if (voice.mute) this.add(VoiceStateToggle.mute);
|
|
if (voice.self_deaf) this.add(VoiceStateToggle.selfDeaf);
|
|
if (voice.self_mute) this.add(VoiceStateToggle.selfMute);
|
|
if (voice.self_stream) this.add(VoiceStateToggle.selfStream);
|
|
if (voice.self_video) this.add(VoiceStateToggle.selfVideo);
|
|
if (voice.suppress) this.add(VoiceStateToggle.suppress);
|
|
}
|
|
|
|
/** Whether this user is deafened by the server */
|
|
get deaf() {
|
|
return this.has("deaf");
|
|
}
|
|
|
|
/** Whether this user is muted by the server */
|
|
get mute() {
|
|
return this.has("mute");
|
|
}
|
|
|
|
/** Whether this user is locally deafened */
|
|
get selfDeaf() {
|
|
return this.has("selfDeaf");
|
|
}
|
|
|
|
/** Whether this user is locally muted */
|
|
get selfMute() {
|
|
return this.has("selfMute");
|
|
}
|
|
|
|
/** Whether this user is streaming using "Go Live" */
|
|
get selfStream() {
|
|
return this.has("selfStream");
|
|
}
|
|
|
|
/** Whether this user's camera is enabled */
|
|
get selfVideo() {
|
|
return this.has("selfVideo");
|
|
}
|
|
|
|
/** Whether this user is muted by the current user */
|
|
get suppress() {
|
|
return this.has("suppress");
|
|
}
|
|
|
|
/** Checks whether or not the permissions exist in this */
|
|
has(permissions: VoiceStateToggleKeys | VoiceStateToggleKeys[]) {
|
|
if (!Array.isArray(permissions)) return super.contains(VoiceStateToggle[permissions]);
|
|
|
|
return super.contains(permissions.reduce((a, b) => (a |= VoiceStateToggle[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(VoiceStateToggle)) {
|
|
// @ts-ignore
|
|
json[key] = super.contains(value);
|
|
}
|
|
|
|
return json as Record<VoiceStateToggleKeys, boolean>;
|
|
}
|
|
}
|
|
|
|
export type VoiceStateToggleKeys = keyof typeof VoiceStateToggle;
|