From 0efc4543daa49e3412777140a6702709c777b4f7 Mon Sep 17 00:00:00 2001 From: Fleny Date: Mon, 17 Feb 2025 09:35:06 +0100 Subject: [PATCH] fix(types, gateway)!: UpdatePresence inconsistencies (#4124) * FIx Update Presence incosistencies * use keyof typeof for DiscordUpdatePresence status * Remove deprecated gateway types --- packages/gateway/src/Shard.ts | 7 +++--- packages/gateway/src/manager.ts | 17 +++++---------- packages/gateway/src/types.ts | 31 +-------------------------- packages/types/src/discord/gateway.ts | 16 +++++++++++++- 4 files changed, 24 insertions(+), 47 deletions(-) diff --git a/packages/gateway/src/Shard.ts b/packages/gateway/src/Shard.ts index 2509e4bb8..6b8b90d6d 100644 --- a/packages/gateway/src/Shard.ts +++ b/packages/gateway/src/Shard.ts @@ -1,12 +1,11 @@ import { Buffer } from 'node:buffer' import { type Inflate, createInflate, inflateSync, constants as zlibConstants } from 'node:zlib' -import type { DiscordGatewayPayload, DiscordHello, DiscordReady } from '@discordeno/types' +import type { DiscordGatewayPayload, DiscordHello, DiscordReady, DiscordUpdatePresence } from '@discordeno/types' import { GatewayCloseEventCodes, GatewayOpcodes } from '@discordeno/types' import { LeakyBucket, camelize, delay, logger } from '@discordeno/utils' import type { Decompress as ZstdDecompress } from 'fzstd' import NodeWebSocket from 'ws' import { - type BotStatusUpdate, type ShardEvents, type ShardGatewayConfig, type ShardHeart, @@ -689,7 +688,7 @@ export class DiscordenoShard { * async in case devs create the presence based on eg. database values. * Passing the shard's id there to make it easier for the dev to use this function. */ - async makePresence(): Promise { + async makePresence(): Promise { return } @@ -812,7 +811,7 @@ export interface ShardCreateOptions { /** The handler to alert the gateway manager that this shard has received a READY event. */ shardIsReady?: () => Promise /** Function to create the bot status to send on Identify requests */ - makePresence?: () => Promise + makePresence?: () => Promise } export default DiscordenoShard diff --git a/packages/gateway/src/manager.ts b/packages/gateway/src/manager.ts index 9e7756ba4..54a97530e 100644 --- a/packages/gateway/src/manager.ts +++ b/packages/gateway/src/manager.ts @@ -6,21 +6,14 @@ import { type DiscordGetGatewayBot, type DiscordMemberWithUser, type DiscordReady, + type DiscordUpdatePresence, GatewayIntents, GatewayOpcodes, type RequestGuildMembers, } from '@discordeno/types' import { Collection, delay, logger } from '@discordeno/utils' import Shard from './Shard.js' -import { - type BotStatusUpdate, - type ShardEvents, - ShardSocketCloseCodes, - type ShardSocketRequest, - type StatusUpdate, - type TransportCompression, - type UpdateVoiceState, -} from './types.js' +import { type ShardEvents, ShardSocketCloseCodes, type ShardSocketRequest, type TransportCompression, type UpdateVoiceState } from './types.js' export function createGatewayManager(options: CreateGatewayManagerOptions): GatewayManager { const connectionOptions = options.connection ?? { @@ -702,7 +695,7 @@ export interface CreateGatewayManagerOptions { * @remarks * This function will be called each time a Shard is going to identify */ - makePresence?: () => Promise + makePresence?: () => Promise /** Options related to resharding. */ resharding?: { /** @@ -808,7 +801,7 @@ export interface GatewayManager extends Required { * @param data The status data to set the bots status to. * @returns nothing */ - editBotStatus: (data: StatusUpdate) => Promise + editBotStatus: (data: DiscordUpdatePresence) => Promise /** * Edits the bot's status on one shard. * @@ -816,7 +809,7 @@ export interface GatewayManager extends Required { * @param data The status data to set the bots status to. * @returns nothing */ - editShardStatus: (shardId: number, data: StatusUpdate) => Promise + editShardStatus: (shardId: number, data: DiscordUpdatePresence) => Promise /** * Fetches the list of members for a guild over the gateway. If `gateway.cache.requestMembers.enabled` is not set, this function will return an empty array and you'll have to handle the `GUILD_MEMBERS_CHUNK` events yourself. * diff --git a/packages/gateway/src/types.ts b/packages/gateway/src/types.ts index 42023005c..1925a3019 100644 --- a/packages/gateway/src/types.ts +++ b/packages/gateway/src/types.ts @@ -1,4 +1,4 @@ -import type { ActivityTypes, Camelize, DiscordActivity, DiscordGatewayPayload, GatewayOpcodes, PresenceStatus } from '@discordeno/types' +import type { Camelize, DiscordGatewayPayload, GatewayOpcodes } from '@discordeno/types' import type Shard from './Shard.js' export enum ShardState { @@ -175,23 +175,6 @@ export interface ShardSocketRequest { d: unknown } -/** https://discord.com/developers/docs/topics/gateway-events#update-presence */ -export interface BotStatusUpdate { - // /** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */ - since: number | null - /** The user's activities */ - activities: BotActivity[] - /** The user's new status */ - status: keyof typeof PresenceStatus -} - -/** https://discord.com/developers/docs/topics/gateway-events#activity-object */ -export interface BotActivity { - name: string - type: ActivityTypes - url?: string -} - /** https://discord.com/developers/docs/topics/gateway#update-voice-state */ export interface UpdateVoiceState { /** id of the guild */ @@ -203,15 +186,3 @@ export interface UpdateVoiceState { /** Is the client deafened */ selfDeaf: boolean } - -/** https://discord.com/developers/docs/topics/gateway-events#update-presence */ -export interface StatusUpdate { - // /** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */ - // since: number | null; - /** The user's activities */ - activities?: Camelize[]> - /** The user's new status */ - status: keyof typeof PresenceStatus - // /** Whether or not the client is afk */ - // afk: boolean; -} diff --git a/packages/types/src/discord/gateway.ts b/packages/types/src/discord/gateway.ts index bd487bfe6..81606300a 100644 --- a/packages/types/src/discord/gateway.ts +++ b/packages/types/src/discord/gateway.ts @@ -291,7 +291,18 @@ export interface DiscordGatewayPayload { // TODO: Add Request Guild Members: https://discord.com/developers/docs/events/gateway-events#request-guild-members-request-guild-members-structure // TODO: Add Request Soundboard Sounds: https://discord.com/developers/docs/events/gateway-events#request-soundboard-sounds-request-soundboard-sounds-structure // TODO: Add Voice State Update: https://discord.com/developers/docs/events/gateway-events#update-voice-state-gateway-voice-state-update-structure -// TODO: Add Presence Update: https://discord.com/developers/docs/events/gateway-events#update-presence-gateway-presence-update-structure + +/** https://discord.com/developers/docs/events/gateway-events#update-presence-gateway-presence-update-structure */ +export interface DiscordUpdatePresence { + /** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */ + since: number | null + /** The user's activities */ + activities: DiscordBotActivity[] + /** The user's new status */ + status: keyof typeof PresenceStatus + /** Whether or not the client is afk */ + afk: boolean +} /** https://discord.com/developers/docs/events/gateway-events#update-presence-status-types */ export enum PresenceStatus { @@ -742,6 +753,9 @@ export interface DiscordActivity { buttons?: DiscordActivityButton[] } +/** https://discord.com/developers/docs/events/gateway-events#activity-object - Note at the bottom */ +export type DiscordBotActivity = Pick + /** https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types */ export enum ActivityTypes { Playing = 0,