From d3aabd16d90db11b29685714a76349ed72e78b4b Mon Sep 17 00:00:00 2001 From: Kae Bartlett Date: Thu, 18 Jan 2024 04:50:52 +0000 Subject: [PATCH] Change a bunch of logger INFOs to DEBUGs in the gateway class --- novus/api/gateway/dispatch.py | 3 ++- novus/api/gateway/gateway.py | 38 +++++++++++++++++------------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/novus/api/gateway/dispatch.py b/novus/api/gateway/dispatch.py index e1ce89d3..f3b6d4dd 100644 --- a/novus/api/gateway/dispatch.py +++ b/novus/api/gateway/dispatch.py @@ -76,7 +76,7 @@ def __init__(self, shard: GatewayShard) -> None: ] ] self.EVENT_HANDLER = { - # "Application command permissions update": None, + "APPLICATION_COMMAND_PERMISSIONS_UPDATE": self.ignore("APPLICATION_COMMAND_PERMISSIONS_UPDATE"), # "Auto moderation rule create": None, # "Auto moderation rule update": None, # "Auto moderation rule delete": None, @@ -101,6 +101,7 @@ def __init__(self, shard: GatewayShard) -> None: "GUILD_STICKERS_UPDATE": self._handle_guild_stickers_update, "GUILD_INTEGRATIONS_UPDATE": self.ignore("GUILD_INTEGRATIONS_UPDATE"), "GUILD_JOIN_REQUEST_UPDATE": self.ignore("GUILD_JOIN_REQUEST_UPDATE"), + "GUILD_JOIN_REQUEST_DELETE": self.ignore("GUILD_JOIN_REQUEST_DELETE"), "GUILD_MEMBER_ADD": self._handle_guild_member_add, "GUILD_MEMBER_REMOVE": self._handle_guild_member_remove, "GUILD_MEMBER_UPDATE": self._handle_guild_member_update, diff --git a/novus/api/gateway/gateway.py b/novus/api/gateway/gateway.py index c352e1de..f404fb8a 100644 --- a/novus/api/gateway/gateway.py +++ b/novus/api/gateway/gateway.py @@ -384,7 +384,7 @@ async def receive( # Catch any errors if data.type == aiohttp.WSMsgType.ERROR: - log.info("[%s] Got error from socket %s", self.shard_id, data) + log.error("[%s] Got error from socket %s", self.shard_id, data) return None elif data.type == aiohttp.WSMsgType.CLOSING: log.info( @@ -399,7 +399,7 @@ async def receive( ) raise GatewayException.all_exceptions[data.data]() elif data.type == aiohttp.WSMsgType.CLOSED: - log.info("[%s] Socket closed", self.shard_id) + log.info("[%s] Socket closed by Discord (%s)", self.shard_id, data.data) raise GatewayException() # Load data into the buffer if we need to @@ -469,7 +469,7 @@ async def reconnect(self) -> None: Reconnect to the gateway. """ - log.info(f"[{self.shard_id}] Starting reconnect...") + log.debug(f"[{self.shard_id}] Starting reconnect...") self.connecting.set() await self.close(code=0) await self.connect( @@ -526,10 +526,10 @@ async def _connect( session = await self.parent.get_session() ws_url = ws_url or self.ws_url if sleep_time: - log.info("[%s] Sleeping %ss before attempting connection", self.shard_id, sleep_time) + log.debug("[%s] Sleeping %ss before attempting connection", self.shard_id, sleep_time) self.state = "Sleeping before connecting" await asyncio.sleep(sleep_time) - log.info("[%s] Creating websocket connection to %s", self.shard_id, ws_url) + log.debug("[%s] Creating websocket connection to %s", self.shard_id, ws_url) try: if reconnect: self.state = "Pending reconnect" @@ -556,12 +556,12 @@ async def _connect( # Get hello self.state = "Waiting for HELLO" - log.info("[%s] Waiting for a HELLO", self.shard_id) + log.debug("[%s] Waiting for a HELLO", self.shard_id) timeout = 60.0 try: got = await asyncio.wait_for(self.receive(), timeout=timeout) except Exception as e: - log.info( + log.debug( "[%s] Failed to get a HELLO after %ss (%s), reattempting (%s)", self.shard_id, timeout, e, attempt, ) @@ -596,12 +596,12 @@ async def _connect( await self.identify() # Wait for a ready or resume - log.info("[%s] Waiting for a READY/RESUMED", self.shard_id) + log.debug("[%s] Waiting for a READY/RESUMED", self.shard_id) self.state = "Waiting for READY/RESUMED" try: await asyncio.wait_for(self.ready_received.wait(), timeout=60.0) except asyncio.TimeoutError: - log.info( + log.debug( "[%s] Failed to get a READY from the gateway after 60s; reattempting connect (%s)", self.shard_id, attempt, ) @@ -654,7 +654,7 @@ async def heartbeat( wait = heartbeat_interval if jitter: wait = heartbeat_interval * random.random() - log.info( + log.debug( ( "[%s] Starting heartbeat - initial %ss, " "normally %ss" @@ -663,7 +663,7 @@ async def heartbeat( format(heartbeat_interval / 100, ".2f"), ) else: - log.info( + log.debug( "[%s] Starting heartbeat at %ss", self.shard_id, format(heartbeat_interval / 100, ".2f"), ) @@ -671,7 +671,7 @@ async def heartbeat( try: await asyncio.sleep(wait / 1_000) except asyncio.CancelledError: - log.info("[%s] Heartbeat has been cancelled", self.shard_id) + log.debug("[%s] Heartbeat has been cancelled", self.shard_id) return for beat_attempt in range(1_000): try: @@ -679,7 +679,7 @@ async def heartbeat( await asyncio.wait_for(self.heartbeat_received.wait(), timeout=10) except asyncio.CancelledError: if beat_attempt <= 5: - log.info( + log.debug( ( "[%s] Failed to get a response to heartbeat " "(attempt %s) - trying again" @@ -687,7 +687,7 @@ async def heartbeat( self.shard_id, beat_attempt, ) continue - log.info( + log.debug( ( "[%s] Failed to get a response to heartbeat " "(attempt %s) - reconnecting" @@ -699,7 +699,7 @@ async def heartbeat( t.add_done_callback(self.running_tasks.discard) return except ValueError: - log.info( + log.debug( ( "[%s] Socket closed so could not send heartbeat - " "reconnecting" @@ -719,7 +719,7 @@ async def identify(self) -> None: Send an identify to Discord. """ - log.info("[%s] Sending identify", self.shard_id) + log.debug("[%s] Sending identify", self.shard_id) token = cast(str, self.parent._token) await self.send( GatewayOpcode.identify, @@ -746,7 +746,7 @@ async def chunk_guild( Send a request to chunk a guild. """ - log.info("[%s] Chunking guild %s", self.shard_id, guild_id) + log.debug("[%s] Chunking guild %s", self.shard_id, guild_id) data = { "guild_id": str(guild_id), "limit": limit, @@ -772,7 +772,7 @@ async def resume(self) -> None: Send a resume to Discord. """ - log.info("[%s] Sending resume", self.shard_id) + log.debug("[%s] Sending resume", self.shard_id) token = cast(str, self.parent._token) await self.send( GatewayOpcode.resume, @@ -894,5 +894,3 @@ async def message_handler(self) -> None: # Everything else case _: print("Failed to deal with gateway message %s" % dump(message)) - - log.info("[%s] Done reading messages", self.shard_id)