mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
fix: camelize all gateway payloads
This commit is contained in:
@@ -8,7 +8,6 @@ import { createGatewayManager, ShardSocketCloseCodes } from '@discordeno/gateway
|
||||
import type { CreateRestManagerOptions, RestManager } from '@discordeno/rest'
|
||||
import { createRestManager } from '@discordeno/rest'
|
||||
import type {
|
||||
CamelCase,
|
||||
Camelize,
|
||||
DiscordAutoModerationActionExecution,
|
||||
DiscordAutoModerationRule,
|
||||
@@ -54,7 +53,6 @@ import type {
|
||||
DiscordVoiceServerUpdate,
|
||||
DiscordVoiceState,
|
||||
DiscordWebhookUpdate,
|
||||
GatewayEventNames,
|
||||
} from '@discordeno/types'
|
||||
|
||||
/**
|
||||
@@ -77,11 +75,11 @@ export function createBot(options: CreateBotOptions): Bot {
|
||||
|
||||
// RUN DISPATCH CHECK
|
||||
await bot.events.dispatchRequirements?.(data, shard)
|
||||
// @ts-expect-error dynamic handling
|
||||
bot.events[
|
||||
data.t.toLowerCase().replace(/_([a-z])/g, function (g) {
|
||||
return g[1].toUpperCase()
|
||||
}) as CamelCase<Lowercase<GatewayEventNames>>
|
||||
}) as keyof EventHandlers
|
||||
// @ts-expect-error as any gets removed by linter
|
||||
]?.(data.d, shard)
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { DiscordGatewayPayload, DiscordHello, DiscordReady } from '@discordeno/types'
|
||||
import { GatewayCloseEventCodes, GatewayOpcodes } from '@discordeno/types'
|
||||
import { createLeakyBucket, delay } from '@discordeno/utils'
|
||||
import { camelize, createLeakyBucket, delay } from '@discordeno/utils'
|
||||
import { inflateSync } from 'zlib'
|
||||
import type { BotStatusUpdate, ShardEvents, ShardGatewayConfig, ShardHeart, ShardSocketRequest } from './types.js'
|
||||
import { ShardSocketCloseCodes, ShardState } from './types.js'
|
||||
@@ -458,7 +458,7 @@ export class Shard {
|
||||
|
||||
// The necessary handling required for the Shards connection has been finished.
|
||||
// Now the event can be safely forwarded.
|
||||
this.events.message?.(this, messageData)
|
||||
this.events.message?.(this, camelize(messageData))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ActivityTypes, DiscordGatewayPayload, GatewayOpcodes, PresenceStatus } from '@discordeno/types'
|
||||
import type { ActivityTypes, Camelize, DiscordGatewayPayload, GatewayOpcodes, PresenceStatus } from '@discordeno/types'
|
||||
import type Shard from './Shard.js'
|
||||
|
||||
export enum ShardState {
|
||||
@@ -112,7 +112,7 @@ export interface ShardEvents {
|
||||
/** The shard has successfully been identified itself with Discord. */
|
||||
identified?: (shard: Shard) => unknown
|
||||
/** The shard has received a message from Discord. */
|
||||
message?: (shard: Shard, payload: DiscordGatewayPayload) => unknown
|
||||
message?: (shard: Shard, payload: Camelize<DiscordGatewayPayload>) => unknown
|
||||
}
|
||||
|
||||
export enum ShardSocketCloseCodes {
|
||||
|
||||
Reference in New Issue
Block a user