debug logs
This commit is contained in:
		
							parent
							
								
									3f7372d6a7
								
							
						
					
					
						commit
						010a48c7f0
					
				
					 4 changed files with 51 additions and 22 deletions
				
			
		|  | @ -414,4 +414,5 @@ export type ClientEvents = { | ||||||
|   commandMissingArgs: [ctx: CommandContext] |   commandMissingArgs: [ctx: CommandContext] | ||||||
|   commandUsed: [ctx: CommandContext] |   commandUsed: [ctx: CommandContext] | ||||||
|   commandError: [ctx: CommandContext, err: Error] |   commandError: [ctx: CommandContext, err: Error] | ||||||
|  |   gatewayError: [err: ErrorEvent, shards: [number, number]] | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -174,8 +174,8 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|       } |       } | ||||||
|       case GatewayOpcodes.RECONNECT: { |       case GatewayOpcodes.RECONNECT: { | ||||||
|         this.emit('reconnectRequired') |         this.emit('reconnectRequired') | ||||||
|         // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |         this.debug('Received OpCode RECONNECT') | ||||||
|         this.reconnect() |         await this.reconnect() | ||||||
|         break |         break | ||||||
|       } |       } | ||||||
|       default: |       default: | ||||||
|  | @ -191,8 +191,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|     switch (code) { |     switch (code) { | ||||||
|       case GatewayCloseCodes.UNKNOWN_ERROR: |       case GatewayCloseCodes.UNKNOWN_ERROR: | ||||||
|         this.debug('API has encountered Unknown Error. Reconnecting...') |         this.debug('API has encountered Unknown Error. Reconnecting...') | ||||||
|         // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |         await this.reconnect() | ||||||
|         this.reconnect() |  | ||||||
|         break |         break | ||||||
|       case GatewayCloseCodes.UNKNOWN_OPCODE: |       case GatewayCloseCodes.UNKNOWN_OPCODE: | ||||||
|         throw new Error( |         throw new Error( | ||||||
|  | @ -206,20 +205,17 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|         throw new Error('Invalid Token provided!') |         throw new Error('Invalid Token provided!') | ||||||
|       case GatewayCloseCodes.INVALID_SEQ: |       case GatewayCloseCodes.INVALID_SEQ: | ||||||
|         this.debug('Invalid Seq was sent. Reconnecting.') |         this.debug('Invalid Seq was sent. Reconnecting.') | ||||||
|         // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |         await this.reconnect() | ||||||
|         this.reconnect() |  | ||||||
|         break |         break | ||||||
|       case GatewayCloseCodes.RATE_LIMITED: |       case GatewayCloseCodes.RATE_LIMITED: | ||||||
|         throw new Error("You're ratelimited. Calm down.") |         throw new Error("You're ratelimited. Calm down.") | ||||||
|       case GatewayCloseCodes.SESSION_TIMED_OUT: |       case GatewayCloseCodes.SESSION_TIMED_OUT: | ||||||
|         this.debug('Session Timeout. Reconnecting.') |         this.debug('Session Timeout. Reconnecting.') | ||||||
|         // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |         await this.reconnect(true) | ||||||
|         this.reconnect(true) |  | ||||||
|         break |         break | ||||||
|       case GatewayCloseCodes.INVALID_SHARD: |       case GatewayCloseCodes.INVALID_SHARD: | ||||||
|         this.debug('Invalid Shard was sent. Reconnecting.') |         this.debug('Invalid Shard was sent. Reconnecting.') | ||||||
|         // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |         await this.reconnect() | ||||||
|         this.reconnect() |  | ||||||
|         break |         break | ||||||
|       case GatewayCloseCodes.SHARDING_REQUIRED: |       case GatewayCloseCodes.SHARDING_REQUIRED: | ||||||
|         throw new Error("Couldn't connect. Sharding is required!") |         throw new Error("Couldn't connect. Sharding is required!") | ||||||
|  | @ -257,6 +253,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|     error.name = 'ErrorEvent' |     error.name = 'ErrorEvent' | ||||||
|     console.log(error) |     console.log(error) | ||||||
|     this.emit('error', error, event) |     this.emit('error', error, event) | ||||||
|  |     this.client.emit('gatewayError', event, this.shards) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private enqueueIdentify(forceNew?: boolean): void { |   private enqueueIdentify(forceNew?: boolean): void { | ||||||
|  | @ -388,8 +385,8 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|           channel === undefined |           channel === undefined | ||||||
|             ? null |             ? null | ||||||
|             : typeof channel === 'string' |             : typeof channel === 'string' | ||||||
|             ? channel |               ? channel | ||||||
|             : channel?.id, |               : channel?.id, | ||||||
|         self_mute: voiceOptions.mute === undefined ? false : voiceOptions.mute, |         self_mute: voiceOptions.mute === undefined ? false : voiceOptions.mute, | ||||||
|         self_deaf: voiceOptions.deaf === undefined ? false : voiceOptions.deaf |         self_deaf: voiceOptions.deaf === undefined ? false : voiceOptions.deaf | ||||||
|       } |       } | ||||||
|  | @ -402,6 +399,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
| 
 | 
 | ||||||
|   async reconnect(forceNew?: boolean): Promise<void> { |   async reconnect(forceNew?: boolean): Promise<void> { | ||||||
|     this.emit('reconnecting') |     this.emit('reconnecting') | ||||||
|  |     this.debug('Reconnecting... (force new: ' + String(forceNew) + ')') | ||||||
| 
 | 
 | ||||||
|     clearInterval(this.heartbeatIntervalID) |     clearInterval(this.heartbeatIntervalID) | ||||||
|     if (forceNew === true) { |     if (forceNew === true) { | ||||||
|  | @ -429,6 +427,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   close(code: number = 1000, reason?: string): void { |   close(code: number = 1000, reason?: string): void { | ||||||
|  |     this.debug(`Closing with code ${code}${reason !== undefined && reason !== '' ? ` and reason ${reason}` : ''}`) | ||||||
|     return this.websocket?.close(code, reason) |     return this.websocket?.close(code, reason) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -175,15 +175,15 @@ export class Interaction extends SnowflakeBase { | ||||||
|       type: data.type ?? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, |       type: data.type ?? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||||||
|       data: |       data: | ||||||
|         data.type === undefined || |         data.type === undefined || | ||||||
|         data.type === InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || |           data.type === InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || | ||||||
|         data.type === InteractionResponseType.CHANNEL_MESSAGE |           data.type === InteractionResponseType.CHANNEL_MESSAGE | ||||||
|           ? { |           ? { | ||||||
|               content: data.content ?? '', |             content: data.content ?? '', | ||||||
|               embeds: data.embeds, |             embeds: data.embeds, | ||||||
|               tts: data.tts ?? false, |             tts: data.tts ?? false, | ||||||
|               flags, |             flags, | ||||||
|               allowed_mentions: data.allowedMentions ?? undefined |             allowed_mentions: data.allowedMentions ?? undefined | ||||||
|             } |           } | ||||||
|           : undefined |           : undefined | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -313,9 +313,10 @@ export class Interaction extends SnowflakeBase { | ||||||
|         (option as WebhookMessageOptions)?.embed !== undefined |         (option as WebhookMessageOptions)?.embed !== undefined | ||||||
|           ? [(option as WebhookMessageOptions).embed] |           ? [(option as WebhookMessageOptions).embed] | ||||||
|           : (option as WebhookMessageOptions)?.embeds !== undefined |           : (option as WebhookMessageOptions)?.embeds !== undefined | ||||||
|           ? (option as WebhookMessageOptions).embeds |             ? (option as WebhookMessageOptions).embeds | ||||||
|           : undefined, |             : undefined, | ||||||
|       file: (option as WebhookMessageOptions)?.file, |       file: (option as WebhookMessageOptions)?.file, | ||||||
|  |       files: (option as WebhookMessageOptions)?.files, | ||||||
|       tts: (option as WebhookMessageOptions)?.tts, |       tts: (option as WebhookMessageOptions)?.tts, | ||||||
|       allowed_mentions: (option as WebhookMessageOptions)?.allowedMentions |       allowed_mentions: (option as WebhookMessageOptions)?.allowedMentions | ||||||
|     } |     } | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								src/test/debug.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/test/debug.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | ||||||
|  | import { Client, event } from '../../mod.ts' | ||||||
|  | import { TOKEN } from './config.ts' | ||||||
|  | 
 | ||||||
|  | class MyClient extends Client { | ||||||
|  |   constructor() { | ||||||
|  |     super({ | ||||||
|  |       token: TOKEN, | ||||||
|  |       intents: [], | ||||||
|  |     }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @event() | ||||||
|  |   ready(): void { | ||||||
|  |     console.log('Connected!') | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   debug(title: string, msg: string): void { | ||||||
|  |     console.log(`[${title}] ${msg}`) | ||||||
|  |     if (title === 'Gateway' && msg === 'Initializing WebSocket...') { | ||||||
|  |       try { throw new Error("Stack") } catch (e) { | ||||||
|  |         console.log(e.stack) | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const client = new MyClient() | ||||||
|  | client.connect() | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue