diff options
author | 2020-03-23 19:31:23 +0100 | |
---|---|---|
committer | 2020-03-23 19:31:23 +0100 | |
commit | 79376abcb7d305484bf5283f95d3a32641aeb6d5 (patch) | |
tree | 659d6fa3f5b5655531ea8909f07571bec1c0c92d /bot/decorators.py | |
parent | Deseasonify: remove `load_extensions` method (diff) |
Deseasonify: abdicate responsibility to wait until bot is ready
The wrapper will no longer wait for the bot to be ready before it calls
the wrapped function for the first time. If the function requires the
bot's cache to be ready, it is responsible for awaiting the method
itself.
This removes the need to acquire a reference to the bot instance inside
the decorator, which seems to be difficult to do cleanly.
As Mark adds, this may in fact be safer as the bot may temporarily
disconnect while the task is active, and awaiting the bot's
ready status every time will prevent issues in such a situation.
Co-authored-by: MarkKoz <[email protected]>
Diffstat (limited to 'bot/decorators.py')
-rw-r--r-- | bot/decorators.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/bot/decorators.py b/bot/decorators.py index 74976cd6..400f1bbb 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -12,7 +12,6 @@ from discord import Colour, Embed from discord.ext import commands from discord.ext.commands import CheckFailure, Context -from bot.bot import bot from bot.constants import ERROR_REPLIES, Month ONE_DAY = 24 * 60 * 60 @@ -41,16 +40,13 @@ def seasonal_task(*allowed_months: Month, sleep_time: typing.Union[float, int] = The decorated function will be called once every `sleep_time` seconds while the current UTC month is in `allowed_months`. Sleep time defaults to 24 hours. + + The wrapped task is responsible for waiting for the bot to be ready, if necessary. """ def decorator(task_body: typing.Callable) -> typing.Callable: @functools.wraps(task_body) async def decorated_task(*args, **kwargs) -> None: - """ - Call `task_body` once every `sleep_time` seconds in `allowed_months`. - - Wait for bot to be ready before calling `task_body` for the first time. - """ - await bot.wait_until_ready() + """Call `task_body` once every `sleep_time` seconds in `allowed_months`.""" log.info(f"Starting seasonal task {task_body.__qualname__} ({allowed_months})") while True: |