Skip to content

Discord Client Reorganization

Created by: Neuheit

Summary

This PR aims to reorganize the DiscordClient files to make maintenance easier.

Details

I reorganized the DiscordClient and DiscordShardedClient files into multiple partial classes. There are 4 partial DiscordClient classes and 2 partial DiscordShardedClient classes. Since there are a lot of confusing line changes, I'll go over what was actually moved around in each file.

DiscordClient: This is the main DiscordClient partial. It contains the:

  • public properties,
  • constructor,
  • extension methods,
  • public rest and connection methods,
  • internal caching methods,
  • disposal.

DiscordClient.Events: This is the partial that contains the event declarations as well as event error handlers.

DiscordClient.WebSocket: This is the partial that focuses on the WebSocket handling, and contains the:

  • private WebSocket fields,
  • connection semaphore properties and methods,
  • internal connection methods and WS event handlers,
  • raw socket message handler + specific WS message handlers,
  • internal gateway methods (update status, identify, resume, etc).

DiscordClient.Dispatch: This contains the dispatch handler from the WebSocket socket message handler. I moved this to its own file because it contains over 1700 lines alone. It contains the:

  • private fields (session id and the guild download completed boolean)
  • all Discord event handlers.

DiscordShardedClient.Events: This partial contains all event declarations, event error handlers, and shard event invokers.

The normal DiscordShardedClient is pretty much the same aside from separating the events and changing a few minor things (see below).

In addition I simplified a few properties in the main DiscordClient partial. Internal fields such as the gateway version, gateway uri, and shardcount were removed and just made their respective public properties have internal setters.

In the main DiscordShardedClient partial, I added an exception handler for StartAsync that will properly stop the client and throw an aggregate exception which will allow the user to restart the client if it fails. I also changed the ShardClients property from a ReadOnlyDictionary to a ReadOnlyConcurrentDictionary.

Changes proposed

  • Reorganize all clients into their own folder
  • Split up normal and shared clients into multiple partial classes.

Merge request reports

Loading