harmony/src/utils/intents.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-12-02 12:29:52 +00:00
import { GatewayIntents } from '../types/gateway.ts'
2020-12-28 22:02:43 +00:00
export type PrivilegedIntents = 'GUILD_MEMBERS' | 'GUILD_PRESENCES'
2020-12-02 12:29:52 +00:00
2020-12-03 05:28:20 +00:00
/* eslint-disable @typescript-eslint/no-extraneous-class */
2020-12-03 04:06:41 +00:00
/** Utility class for handling Gateway Intents */
2020-12-02 12:29:52 +00:00
export class Intents {
2020-12-28 22:02:43 +00:00
static NonPrivileged: number[] = [
2020-12-02 12:29:52 +00:00
GatewayIntents.GUILD_MESSAGES,
GatewayIntents.DIRECT_MESSAGES,
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
GatewayIntents.DIRECT_MESSAGE_TYPING,
GatewayIntents.GUILDS,
GatewayIntents.GUILD_BANS,
GatewayIntents.GUILD_EMOJIS,
GatewayIntents.GUILD_INTEGRATIONS,
GatewayIntents.GUILD_INVITES,
GatewayIntents.GUILD_MESSAGE_REACTIONS,
GatewayIntents.GUILD_MESSAGE_TYPING,
GatewayIntents.GUILD_VOICE_STATES,
GatewayIntents.GUILD_WEBHOOKS
]
static All: number[] = [
GatewayIntents.GUILD_MEMBERS,
GatewayIntents.GUILD_PRESENCES,
2020-12-28 22:02:43 +00:00
...Intents.NonPrivileged
2020-12-02 12:29:52 +00:00
]
static Presence: number[] = [
GatewayIntents.GUILD_PRESENCES,
2020-12-28 22:02:43 +00:00
...Intents.NonPrivileged
2020-12-02 12:29:52 +00:00
]
static GuildMembers: number[] = [
GatewayIntents.GUILD_MEMBERS,
2020-12-28 22:02:43 +00:00
...Intents.NonPrivileged
2020-12-02 12:29:52 +00:00
]
2020-12-28 22:02:43 +00:00
static None: number[] = [...Intents.NonPrivileged]
2020-12-02 12:29:52 +00:00
2020-12-28 22:02:43 +00:00
/** Create an Array of Intents easily passing Intents you're privileged for and disable the ones you don't need */
2020-12-02 12:29:52 +00:00
static create(
2020-12-28 22:02:43 +00:00
privileged?: PrivilegedIntents[],
2020-12-02 12:29:52 +00:00
disable?: number[]
): number[] {
2020-12-28 22:02:43 +00:00
let intents: number[] = [...Intents.NonPrivileged]
2020-12-02 12:29:52 +00:00
2020-12-28 22:02:43 +00:00
if (privileged !== undefined && privileged.length !== 0) {
if (privileged.includes('GUILD_MEMBERS'))
2020-12-02 12:29:52 +00:00
intents.push(GatewayIntents.GUILD_MEMBERS)
2020-12-28 22:02:43 +00:00
if (privileged.includes('GUILD_PRESENCES'))
2020-12-02 12:29:52 +00:00
intents.push(GatewayIntents.GUILD_PRESENCES)
}
if (disable !== undefined) {
intents = intents.filter((intent) => !disable.includes(intent))
}
return intents
}
}