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>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { DiscordEmoji, DiscordRole } from "../../types/discord.ts";
|
|
import { ToggleBitfield } from "./ToggleBitfield.ts";
|
|
|
|
export const EmojiToggle = {
|
|
/** Whether this emoji must be wrapped in colons */
|
|
requireColons: 1 << 0,
|
|
/** Whether this emoji is managed */
|
|
managed: 1 << 1,
|
|
/** Whether this emoji is animated */
|
|
animated: 1 << 2,
|
|
/** Whether this emoji can be used, may be false due to loss of Server Boosts */
|
|
available: 1 << 3,
|
|
};
|
|
|
|
export class EmojiToggles extends ToggleBitfield {
|
|
constructor(role: DiscordEmoji) {
|
|
super();
|
|
|
|
if (role.require_colons) this.add(EmojiToggle.requireColons);
|
|
if (role.managed) this.add(EmojiToggle.managed);
|
|
if (role.animated) this.add(EmojiToggle.animated);
|
|
if (role.available) this.add(EmojiToggle.available);
|
|
}
|
|
|
|
/** Whether this emoji must be wrapped in colons */
|
|
get requireColons() {
|
|
return this.has("requireColons");
|
|
}
|
|
|
|
/** Whether this emoji is managed */
|
|
get managed() {
|
|
return this.has("managed");
|
|
}
|
|
|
|
/** Whether this emoji is animated */
|
|
get animated() {
|
|
return this.has("animated");
|
|
}
|
|
|
|
/** Whether this emoji can be used, may be false due to loss of Server Boosts */
|
|
get available() {
|
|
return this.has("available");
|
|
}
|
|
|
|
/** Checks whether or not the permissions exist in this */
|
|
has(permissions: EmojiToggleKeys | EmojiToggleKeys[]) {
|
|
if (!Array.isArray(permissions)) return super.contains(EmojiToggle[permissions]);
|
|
|
|
return super.contains(permissions.reduce((a, b) => (a |= EmojiToggle[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(EmojiToggle)) {
|
|
// @ts-ignore
|
|
json[key] = super.contains(value);
|
|
}
|
|
|
|
return json as Record<EmojiToggleKeys, boolean>;
|
|
}
|
|
}
|
|
|
|
export type EmojiToggleKeys = keyof typeof EmojiToggle;
|