perf: Much faster features

This commit is contained in:
Skillz4Killz
2022-10-08 03:38:31 +00:00
committed by GitHub
parent 0051a95afd
commit 4c22c0e95a

View File

@@ -2,6 +2,31 @@ import { DiscordGuild } from "../../types/discord.ts";
import { GuildFeatures } from "../../types/shared.ts";
import { ToggleBitfieldBigint } from "./ToggleBitfield.ts";
const featureNames = [
"inviteSplash",
"vipRegions",
"vanityUrl",
"verified",
"partnered",
"community",
"news",
"discoverable",
"featurable",
"animatedIcon",
"banner",
"welcomeScreenEnabled",
"memberVerificationGateEnabled",
"previewEnabled",
"ticketedEventsEnabled",
"monetizationEnabled",
"moreStickers",
"privateThreads",
"roleIcons",
"autoModeration",
"invitesDisabled",
"animatedBanner",
];
export const GuildToggle = {
/** Whether the bot is the owner of the guild */
owner: 1n << 0n,
@@ -99,32 +124,15 @@ export class GuildToggles extends ToggleBitfieldBigint {
}
get features() {
return Object.entries(this.list()).filter(([key, value]) =>
[
"inviteSplash",
"vipRegions",
"vanityUrl",
"verified",
"partnered",
"community",
"news",
"discoverable",
"featurable",
"animatedIcon",
"banner",
"welcomeScreenEnabled",
"memberVerificationGateEnabled",
"previewEnabled",
"ticketedEventsEnabled",
"monetizationEnabled",
"moreStickers",
"privateThreads",
"roleIcons",
"autoModeration",
"invitesDisabled",
"animatedBanner",
].includes(key) && value
).map(([key, _]) => key) as GuildToggleKeys[];
const features: GuildToggleKeys[] = [];
for (const [key, value] of Object.entries(GuildToggle)) {
if (!featureNames.includes(key)) continue;
if (!super.contains(Guildcontinue;
features.push(key as GuildToggleKeys);
}
return features;
}
/** Whether the bot is the owner of the guild */