0.5.0 • Published 4 years ago
@spectacles/util v0.5.0
Spectacles Utils
Various utilities for interacting with Discord and using Spectacles.
Encoding/Decoding
encode and decode convenience functions for JSON de/serializing arbitrary data.
Permissions
A Permissions class with methods for dealing with Discord permissions.
- static
FLAGS: each individual Discord permission flag. - static
ALL: every permission flag OR'd together - static
NONE: 0 constructor(bitfield: number = Permissions.NONE)add(perms: number): this: adds a bitfield to the permissionsremove(perms: number): this: removes permissionshas(perms: number): this: checks if permissions existapply(data: { guild: AvailableGuild, channel?: Channel, member?: GuildMember }): this: applies guild and optionally channel and member permissions to the bitfield. After this method, the bitfield will represent the final permissions for the given guild & channel and/or member with appropriate overrides. Operates in accordance with Discord recommendations.- readonly
isAdmin: boolean: whether this bitfield contains the administrator flag clone(): Permissions: create a new permissions instance from this bitfieldvalueOf(): number: the bitfieldtoJSON(): string[]: an array of readable strings representing the permissions in this bitfield
Snowflakes
A Snowflake class with methods for creating/inspecting Discord snowflakes. Requires BigInt support.
- static
EPOCH: number: the epoch to use for snowflakes (defaults to Discord's) constructor(bin: bigint | string = 0n)createdAt: Date: get/set when the snowflake was createdworkerID: number: get/set the worker IDprocessID: number: get/set the process IDincrement: number: get/set the incrementvalueOf(): bigint: the raw snowflake