Bug(gateway) Fix fetch of discord gateway session information (#3098)

* bug(gateway) Remove update createBot options

Add overrides when fetching discord session info

* Use createBot options instead of defaults
This commit is contained in:
Fleny
2023-08-05 18:31:35 +00:00
committed by GitHub
parent a911519ed0
commit e70a1788f5
2 changed files with 25 additions and 16 deletions
+12 -1
View File
@@ -69,8 +69,19 @@ export function createBot(options: CreateBotOptions): Bot {
async start() {
if (!options.gateway?.connection) {
bot.gateway.connection = await bot.rest.getSessionInfo()
// Check for overrides in the configuration
if (!options.gateway?.url)
bot.gateway.url = bot.gateway.connection.url;
if (!options.gateway?.totalShards)
bot.gateway.totalShards = bot.gateway.connection.shards;
if (!options.gateway?.lastShardId)
bot.gateway.lastShardId = bot.gateway.connection.shards - 1;
}
return await bot.gateway.spawnShards()
await bot.gateway.spawnShards()
},
async shutdown() {
+13 -15
View File
@@ -5,17 +5,15 @@ import Shard from './Shard.js'
import type { ShardEvents, StatusUpdate, UpdateVoiceState } from './types.js'
export function createGatewayManager(options: CreateGatewayManagerOptions): GatewayManager {
if (!options.connection) {
options.connection = {
url: 'wss://gateway.discord.gg',
shards: 1,
sessionStartLimit: {
maxConcurrency: 1,
remaining: 1000,
total: 1000,
resetAfter: 1000 * 60 * 60 * 24,
},
}
const connectionOptions = options.connection ?? {
url: 'wss://gateway.discord.gg',
shards: 1,
sessionStartLimit: {
maxConcurrency: 1,
remaining: 1000,
total: 1000,
resetAfter: 1000 * 60 * 60 * 24,
},
}
const gateway: GatewayManager = {
@@ -28,11 +26,11 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate
device: options.properties?.device ?? 'Discordeno',
},
token: options.token,
url: options.url ?? options.connection.url ?? 'wss://gateway.discord.gg',
url: options.url ?? connectionOptions.url ?? 'wss://gateway.discord.gg',
version: options.version ?? 10,
connection: options.connection,
totalShards: options.totalShards ?? options.connection.shards ?? 1,
lastShardId: options.lastShardId ?? (options.totalShards ? options.totalShards - 1 : (options.connection ? options.connection.shards - 1 : 0)),
connection: connectionOptions,
totalShards: options.totalShards ?? connectionOptions.shards ?? 1,
lastShardId: options.lastShardId ?? (options.totalShards ? options.totalShards - 1 : (connectionOptions ? connectionOptions.shards - 1 : 0)),
firstShardId: options.firstShardId ?? 0,
totalWorkers: options.totalWorkers ?? 4,
shardsPerWorker: options.shardsPerWorker ?? 25,