|
17 | 17 | wait_for, |
18 | 18 | ) |
19 | 19 | from contextlib import suppress |
20 | | -from enum import IntEnum |
21 | 20 | from sys import platform, version_info |
22 | 21 | from time import perf_counter |
23 | 22 | from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union |
|
26 | 25 | from aiohttp import ClientWebSocketResponse, WSMessage, WSMsgType |
27 | 26 |
|
28 | 27 | from ...base import __version__, get_logger |
29 | | -from ...client.enums import ComponentType, InteractionType, OptionType |
| 28 | +from ...client.enums import ComponentType, IntEnum, InteractionType, OptionType |
30 | 29 | from ...client.models import Option |
31 | 30 | from ...utils.missing import MISSING |
32 | 31 | from ..dispatch import Listener |
@@ -242,7 +241,6 @@ async def _manage_heartbeat(self) -> None: |
242 | 241 | """Manages the heartbeat loop.""" |
243 | 242 | log.debug(f"Sending heartbeat every {self.__heartbeater.delay / 1000} seconds...") |
244 | 243 | while not self.__heartbeat_event.is_set(): |
245 | | - |
246 | 244 | log.debug("Sending heartbeat...") |
247 | 245 | if not self.__heartbeater.event.is_set(): |
248 | 246 | log.debug("HEARTBEAT_ACK missing, reconnecting...") |
@@ -404,7 +402,6 @@ def _dispatch_interaction_event(self, data: dict) -> None: |
404 | 402 | _option = self.__sub_command_context(option, _context) |
405 | 403 | __kwargs.update(_option) |
406 | 404 |
|
407 | | - self._dispatch.dispatch("on_command", _context) |
408 | 405 | elif data["type"] == InteractionType.MESSAGE_COMPONENT: |
409 | 406 | _name = f"component_{_context.data.custom_id}" |
410 | 407 |
|
@@ -931,6 +928,12 @@ async def _reconnect(self, to_resume: bool, code: Optional[int] = 1012) -> None: |
931 | 928 | if self.__heartbeat_event.is_set(): |
932 | 929 | self.__heartbeat_event.clear() # Because we're hardresetting the process |
933 | 930 |
|
| 931 | + self._dispatch.dispatch( |
| 932 | + "on_disconnect" |
| 933 | + ) # will be followed by the on_ready event after reconnection |
| 934 | + # reconnection happens whenever it disconnects either with or without a resume prompt |
| 935 | + # as this is called whenever the WS client closes |
| 936 | + |
934 | 937 | if not to_resume: |
935 | 938 | url = self.ws_url if self.ws_url else await self._http.get_gateway() |
936 | 939 | else: |
@@ -963,7 +966,6 @@ async def __receive_packet(self, ignore_lock: bool = False) -> Optional[Dict[str |
963 | 966 | buffer = bytearray() |
964 | 967 |
|
965 | 968 | while True: |
966 | | - |
967 | 969 | if not ignore_lock: |
968 | 970 | # meaning if we're reconnecting or something because of tasks |
969 | 971 | await self.__closed.wait() |
@@ -1003,7 +1005,6 @@ async def __receive_packet(self, ignore_lock: bool = False) -> Optional[Dict[str |
1003 | 1005 | await self._reconnect(True) |
1004 | 1006 |
|
1005 | 1007 | elif packet.type == WSMsgType.CLOSING: |
1006 | | - |
1007 | 1008 | if ignore_lock: |
1008 | 1009 | raise LibraryException( |
1009 | 1010 | message="Discord unexpectedly closing on receiving by force.", severity=50 |
@@ -1061,7 +1062,6 @@ async def _send_packet(self, data: Dict[str, Any]) -> None: |
1061 | 1062 | await self._client.send_str(packet) |
1062 | 1063 | else: |
1063 | 1064 | async with self.reconnect_lock: # needs to lock while it reconnects. |
1064 | | - |
1065 | 1065 | if data["op"] != OpCodeType.HEARTBEAT.value: |
1066 | 1066 | # This is because the ratelimiter limits already accounts for this. |
1067 | 1067 | await self._ratelimiter.block() |
|
0 commit comments