mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
feat: gateway.preferSnakeCase
This commit is contained in:
@@ -10,7 +10,7 @@ import type {
|
||||
RequestGuildMembers,
|
||||
} from '@discordeno/types'
|
||||
import { GatewayCloseEventCodes, GatewayIntents, GatewayOpcodes } from '@discordeno/types'
|
||||
import { camelize, Collection, delay, LeakyBucket, logger } from '@discordeno/utils'
|
||||
import { Collection, LeakyBucket, camelize, delay, logger } from '@discordeno/utils'
|
||||
import { inflateSync } from 'node:zlib'
|
||||
import WebSocket from 'ws'
|
||||
import type { RequestMemberRequest } from './manager.js'
|
||||
@@ -467,6 +467,10 @@ export class DiscordenoShard {
|
||||
this.previousSequenceNumber = packet.s
|
||||
}
|
||||
|
||||
this.forwardToBot(packet);
|
||||
}
|
||||
|
||||
forwardToBot(packet: DiscordGatewayPayload): void {
|
||||
// The necessary handling required for the Shards connection has been finished.
|
||||
// Now the event can be safely forwarded.
|
||||
this.events.message?.(this, camelize(packet))
|
||||
|
||||
@@ -37,6 +37,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate
|
||||
totalWorkers: options.totalWorkers ?? 4,
|
||||
shardsPerWorker: options.shardsPerWorker ?? 25,
|
||||
spawnShardDelay: options.spawnShardDelay ?? 5300,
|
||||
preferSnakeCase: false,
|
||||
shards: new Map(),
|
||||
buckets: new Map(),
|
||||
cache: {
|
||||
@@ -167,6 +168,12 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate
|
||||
},
|
||||
})
|
||||
|
||||
if (this.preferSnakeCase) {
|
||||
shard.forwardToBot = async (payload) => {
|
||||
options.events.message?.(shard!, payload)
|
||||
}
|
||||
}
|
||||
|
||||
this.shards.set(shardId, shard)
|
||||
}
|
||||
|
||||
@@ -289,6 +296,11 @@ export interface CreateGatewayManagerOptions {
|
||||
* @default 5300
|
||||
*/
|
||||
spawnShardDelay?: number
|
||||
/**
|
||||
* Whether to send the discord packets in snake case form.
|
||||
* @default false
|
||||
*/
|
||||
preferSnakeCase?: boolean
|
||||
/**
|
||||
* Total amount of shards your bot uses. Useful for zero-downtime updates or resharding.
|
||||
* @default 1
|
||||
|
||||
Reference in New Issue
Block a user