aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-04-18 17:15:55 +0100
committerGravatar Chris Lovering <[email protected]>2022-04-18 17:47:02 +0100
commiteec5a13cdd430b8010af2c8dca7228d969558e03 (patch)
tree7f053fd66c3b8c96ea83e74ecb0dad4748ad68b0
parentAdd cog_unload functions to cancel scheduled tasks (diff)
Use discord.py's async cog loading for more cogs
In the case of the docs cog, the lock is not needed on the cog_load function as it is ran before the bot even starts listening for commands.
-rw-r--r--bot/exts/info/doc/_cog.py3
-rw-r--r--bot/exts/moderation/modpings.py14
-rw-r--r--bot/exts/moderation/watchchannels/_watchchannel.py4
3 files changed, 6 insertions, 15 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py
index bbdc4e82a..e635c4308 100644
--- a/bot/exts/info/doc/_cog.py
+++ b/bot/exts/info/doc/_cog.py
@@ -84,8 +84,7 @@ class DocCog(commands.Cog):
event_loop=self.bot.loop,
)
- @lock(NAMESPACE, COMMAND_LOCK_SINGLETON, raise_error=True)
- async def init_refresh_inventory(self) -> None:
+ async def cog_load(self) -> None:
"""Refresh documentation inventory on cog initialization."""
await self.bot.wait_until_guild_available()
await self.refresh_inventories()
diff --git a/bot/exts/moderation/modpings.py b/bot/exts/moderation/modpings.py
index 0030ae542..730fc45ee 100644
--- a/bot/exts/moderation/modpings.py
+++ b/bot/exts/moderation/modpings.py
@@ -3,7 +3,6 @@ import datetime
import arrow
from async_rediscache import RedisCache
-from botcore.utils import scheduling
from botcore.utils.scheduling import Scheduler
from dateutil.parser import isoparse, parse as dateutil_parse
from discord import Embed, Member
@@ -41,15 +40,10 @@ class ModPings(Cog):
self.guild = None
self.moderators_role = None
- self.modpings_schedule_task = scheduling.create_task(
- self.reschedule_modpings_schedule(),
- event_loop=self.bot.loop
- )
- self.reschedule_task = scheduling.create_task(
- self.reschedule_roles(),
- name="mod-pings-reschedule",
- event_loop=self.bot.loop,
- )
+ async def cog_load(self) -> None:
+ """Schedule both when to reapply role and all mod ping schedules."""
+ await self.reschedule_modpings_schedule()
+ await self.reschedule_roles()
async def reschedule_roles(self) -> None:
"""Reschedule moderators role re-apply times."""
diff --git a/bot/exts/moderation/watchchannels/_watchchannel.py b/bot/exts/moderation/watchchannels/_watchchannel.py
index bc78b3934..46f9c296e 100644
--- a/bot/exts/moderation/watchchannels/_watchchannel.py
+++ b/bot/exts/moderation/watchchannels/_watchchannel.py
@@ -70,8 +70,6 @@ class WatchChannel(metaclass=CogABCMeta):
self.message_history = MessageHistory()
self.disable_header = disable_header
- self._start = scheduling.create_task(self.start_watchchannel(), event_loop=self.bot.loop)
-
@property
def modlog(self) -> ModLog:
"""Provides access to the ModLog cog for alert purposes."""
@@ -94,7 +92,7 @@ class WatchChannel(metaclass=CogABCMeta):
return True
- async def start_watchchannel(self) -> None:
+ async def cog_load(self) -> None:
"""Starts the watch channel by getting the channel, webhook, and user cache ready."""
await self.bot.wait_until_guild_available()