mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(types, gateway)!: UpdatePresence inconsistencies (#4124)
* FIx Update Presence incosistencies * use keyof typeof for DiscordUpdatePresence status * Remove deprecated gateway types
This commit is contained in:
@@ -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<BotStatusUpdate | undefined> {
|
||||
async makePresence(): Promise<DiscordUpdatePresence | undefined> {
|
||||
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<void>
|
||||
/** Function to create the bot status to send on Identify requests */
|
||||
makePresence?: () => Promise<BotStatusUpdate | undefined>
|
||||
makePresence?: () => Promise<DiscordUpdatePresence | undefined>
|
||||
}
|
||||
|
||||
export default DiscordenoShard
|
||||
|
||||
@@ -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<BotStatusUpdate | undefined>
|
||||
makePresence?: () => Promise<DiscordUpdatePresence | undefined>
|
||||
/** Options related to resharding. */
|
||||
resharding?: {
|
||||
/**
|
||||
@@ -808,7 +801,7 @@ export interface GatewayManager extends Required<CreateGatewayManagerOptions> {
|
||||
* @param data The status data to set the bots status to.
|
||||
* @returns nothing
|
||||
*/
|
||||
editBotStatus: (data: StatusUpdate) => Promise<void>
|
||||
editBotStatus: (data: DiscordUpdatePresence) => Promise<void>
|
||||
/**
|
||||
* Edits the bot's status on one shard.
|
||||
*
|
||||
@@ -816,7 +809,7 @@ export interface GatewayManager extends Required<CreateGatewayManagerOptions> {
|
||||
* @param data The status data to set the bots status to.
|
||||
* @returns nothing
|
||||
*/
|
||||
editShardStatus: (shardId: number, data: StatusUpdate) => Promise<void>
|
||||
editShardStatus: (shardId: number, data: DiscordUpdatePresence) => Promise<void>
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -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<Omit<DiscordActivity, 'created_at'>[]>
|
||||
/** The user's new status */
|
||||
status: keyof typeof PresenceStatus
|
||||
// /** Whether or not the client is afk */
|
||||
// afk: boolean;
|
||||
}
|
||||
|
||||
@@ -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<DiscordActivity, 'name' | 'state' | 'type' | 'url'>
|
||||
|
||||
/** https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types */
|
||||
export enum ActivityTypes {
|
||||
Playing = 0,
|
||||
|
||||
Reference in New Issue
Block a user