@@ -220,5 +220,49 @@ class MentionPrefix(Sentinel):
220220LIB_PATH = os .sep .join (__file__ .split (os .sep )[:- 2 ])
221221"""The path to the library folder."""
222222
223- RECOVERABLE_WEBSOCKET_CLOSE_CODES = (4000 , 4001 , 4002 , 4003 , 4005 , 4007 , 4008 , 4009 )
224- NON_RESUMABLE_WEBSOCKET_CLOSE_CODES = (1000 , 4007 )
223+ # fmt: off
224+ RECOVERABLE_WEBSOCKET_CLOSE_CODES = ( # Codes that are recoverable, and the bot will reconnect
225+ 1000 , # Normal closure
226+ 1001 , # Server going away
227+ 1003 , # Unsupported Data
228+ 1005 , # No status code
229+ 1006 , # Abnormal closure
230+ 1008 , # Policy Violation
231+ 1009 , # Message too big
232+ 1011 , # Server error
233+ 1012 , # Server is restarting
234+ 1014 , # Handshake failed
235+ 1015 , # TLS error
236+ 4000 , # Unknown error
237+ 4001 , # Unknown opcode
238+ 4002 , # Decode error
239+ 4003 , # Not authenticated
240+ 4005 , # Already authenticated
241+ 4007 , # Invalid seq
242+ 4008 , # Rate limited
243+ 4009 , # Session timed out
244+ )
245+ NON_RESUMABLE_WEBSOCKET_CLOSE_CODES = ( # Codes that are recoverable, but the bot won't be able to resume the session
246+ 1000 , # Normal closure
247+ 1003 , # Unsupported Data
248+ 1008 , # Policy Violation
249+ 1009 , # Message too big
250+ 1011 , # Server error
251+ 1012 , # Server is restarting
252+ 1014 , # Handshake failed
253+ 1015 , # TLS error
254+ 4007 , # Invalid seq
255+ )
256+ # Any close code not in the above two tuples is a non-recoverable close code, and will result in the bot shutting down
257+ # fmt: on
258+
259+
260+ # Sanity check the above constants - only useful during development, but doesn't hurt to leave in
261+ try :
262+ assert set (NON_RESUMABLE_WEBSOCKET_CLOSE_CODES ).issubset (set (RECOVERABLE_WEBSOCKET_CLOSE_CODES ))
263+ except AssertionError as e :
264+ # find the difference between the two sets
265+ diff = set (NON_RESUMABLE_WEBSOCKET_CLOSE_CODES ) - set (RECOVERABLE_WEBSOCKET_CLOSE_CODES )
266+ raise RuntimeError (
267+ f"NON_RESUMABLE_WEBSOCKET_CLOSE_CODES contains codes that are not in RECOVERABLE_WEBSOCKET_CLOSE_CODES: { diff } "
268+ ) from e
0 commit comments