Skip to content

Commit

Permalink
fix: guild update not running on on_ready registered (#45)
Browse files Browse the repository at this point in the history
* fix: guild update not running on on_ready registered

* style: black and isort

* fix: unintended discord.py usage

* style: black

* fix: mypy type
  • Loading branch information
eunwoo1104 authored Jul 21, 2024
1 parent c70781f commit bcd2eab
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion koreanbots/integrations/discord.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from asyncio.tasks import Task, sleep
from logging import getLogger
from typing import TYPE_CHECKING, Optional, Union
from typing import (
TYPE_CHECKING,
Any,
Callable,
Coroutine,
Optional,
TypeVar,
Union,
cast,
)

from aiohttp import ClientSession

Expand All @@ -11,6 +20,10 @@
from discord import Client as DiscordpyClient
from disnake.client import Client as DisnakeClient

T = TypeVar("T")
Coro = Coroutine[Any, Any, T]
CoroT = TypeVar("CoroT", bound=Callable[..., Coro[Any]])

log = getLogger(__name__)


Expand Down Expand Up @@ -40,6 +53,7 @@ async def close() -> None:

if run_task:
client_ready = getattr(client, "on_ready", None)
client_event = getattr(client, "event")
self.guildcount_sender: Optional[Task[None]] = None

# Set default on_ready handler to start send_guildcount task.
Expand All @@ -54,7 +68,19 @@ async def on_ready() -> None:
async def on_ready() -> None:
self.run_post_guild_count_task()

def event(coro: CoroT, /) -> CoroT:
if coro.__name__ == "on_ready":

async def on_ready() -> None:
self.run_post_guild_count_task()
await coro()

return cast(CoroT, client_event(on_ready))

return cast(CoroT, client_event(coro))

client.event(on_ready)
setattr(client, "event", event)

@property
def is_running(self) -> bool:
Expand Down

0 comments on commit bcd2eab

Please sign in to comment.