import { GatewayBotInfo , GatewayProvider , GatewaySendOptions , GatewaySendPayloadLike , GatewayShardsInfo } from '@discordoo/providers' ; import { GatewayManagerData } from '@src/gateway/interfaces' ; import { Client , ProviderConstructor } from '@src/core' ; import { DiscordooError , wait } from '@src/utils' ; import { Endpoints } from '@src/constants' ; import { CompletedGatewayOptions } from '@src/gateway/interfaces/CompletedGatewayOptions' ; export class GatewayManager < P extends GatewayProvider = GatewayProvider > { public provider : P ; public client : Client ; public options : CompletedGatewayOptions ; constructor ( client , Provider , data ) { this . client = client ; this . provider = new Provider ( this . client , data . gatewayOptions , data . providerOptions ) ; this . options = data . gatewayOptions ; } connect ( shards ? ) { return this . provider . connect ( shards ) ; } disconnect ( shards ? ) { return this . provider . disconnect ( shards ) ; } ping ( ) ; ping ( shards ) ; ping ( shards ? ) { return this . provider . ping ( shards ) ; } emit ( shardId , event , ... data ) { return this . client . internals . events . handlers . get ( event ) ?. execute ( shardId , ... data ) ; } reorganizeShards ( shards ) { return this . provider . reorganizeShards ( shards ) ; } reconnect ( shards ? ) { return this . provider . reconnect ( shards ) ; } async getGateway ( ) { const response = await this . client . internals . rest . api ( ) . url ( Endpoints . GATEWAY_BOT ( ) ) . get < GatewayBotInfo > ( ) ; if ( response . success ) return response . result ; else throw new DiscordooError ( 'GatewayManager' , 'Get gateway request ended with error:' , response . result ) ; } send ( data , options ? ) { return this . provider . send ( data , options ) ; } async waitShardSpawnTurn ( shardId ) { await wait ( 6000 ) ; } async init ( ) { await this . provider . init ( ) ; } }