Skip to content

Commit

Permalink
Change a bunch of logger INFOs to DEBUGs in the gateway class
Browse files Browse the repository at this point in the history
  • Loading branch information
4Kaylum committed Jan 18, 2024
1 parent 0afeb9f commit d3aabd1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
3 changes: 2 additions & 1 deletion novus/api/gateway/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
38 changes: 18 additions & 20 deletions novus/api/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"
Expand All @@ -663,31 +663,31 @@ 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"),
)
while True:
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:
await self.send(GatewayOpcode.heartbeat, self.sequence)
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"
),
self.shard_id, beat_attempt,
)
continue
log.info(
log.debug(
(
"[%s] Failed to get a response to heartbeat "
"(attempt %s) - reconnecting"
Expand All @@ -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"
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit d3aabd1

Please sign in to comment.