Skip to content

Commit

Permalink
fix: 서버 수 업데이트 시 오류 핸들링 (#46)
Browse files Browse the repository at this point in the history
* fix: handle error raised during guild count update

* chore: reformat code

* feat: attach exception on error
  • Loading branch information
skinmaker1345 authored Sep 18, 2024
1 parent bcd2eab commit 3cdef7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 6 additions & 2 deletions koreanbots/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ async def request(
async with self.session.request(
method, KOREANBOTS_URL + endpoint, **kwargs
) as response:
remain_limit = response.headers["x-ratelimit-remaining"]
if int(remain_limit) == 0 or response.status == 429:
remain_limit = response.headers.get("x-ratelimit-remaining")
if (
remain_limit is not None
and int(remain_limit) == 0
or response.status == 429
):
reset_limit_timestamp = int(response.headers["x-ratelimit-reset"])
reset_limit = datetime.fromtimestamp(reset_limit_timestamp)
retry_after = reset_limit - datetime.now()
Expand Down
12 changes: 9 additions & 3 deletions koreanbots/integrations/dico.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ async def tasks_send_guildcount(self) -> None:
if self.include_shard_count:
if self.client.shard_count:
kwargs.update({"shards": self.client.shard_count})
log.info("Send")
await self.guildcount(int(self.client.application_id), **kwargs)
log.info("Complete i will sleep")
log.info("Initiating guild count update...")
try:
await self.guildcount(int(self.client.application_id), **kwargs)
except:
log.exception("Guild count update failed due to an error.")
else:
log.info(
"Guild count updated successfully. Waiting 30 minutes for the next update."
)
await sleep(1800)
12 changes: 9 additions & 3 deletions koreanbots/integrations/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ async def tasks_send_guildcount(self) -> None:
if self.include_shard_count:
if self.client.shard_count:
kwargs.update({"shards": self.client.shard_count})
log.info("Send")
await self.guildcount(self.client.user.id, **kwargs)
log.info("Complete i will sleep")
log.info("Initiating guild count update...")
try:
await self.guildcount(int(self.client.user.id), **kwargs)
except:
log.exception("Guild count update failed due to an error.")
else:
log.info(
"Guild count updated successfully. Waiting 30 minutes for the next update."
)
await sleep(1800)

0 comments on commit 3cdef7d

Please sign in to comment.