1010from core import checks
1111from core .models import PermissionLevel , getLogger
1212from core .thread import Thread
13- from .utils import async_tasks
1413
1514# Remove view perms from this role while pining, so only on-duty mods get the ping.
1615MOD_TEAM_ROLE_ID = 267629731250176001
@@ -49,9 +48,7 @@ def __init__(self, bot: ModmailBot):
4948 self .ping_tasks : list [PingTask ] = None
5049 self .db = bot .api .get_plugin_partition (self )
5150
52- self .init_task = async_tasks .create_task (self .init_plugin (), self .bot .loop )
53-
54- async def init_plugin (self ) -> None :
51+ async def cog_load (self ) -> None :
5552 """Fetch the current config from the db."""
5653 db_config = await self .db .find_one ({"_id" : "ping-delay-config" })
5754 db_config = db_config or {}
@@ -66,7 +63,7 @@ async def init_plugin(self) -> None:
6663 log .info ("Loaded config: %s" , self .config )
6764 log .info ("Loaded %d ping tasks" , len (self .ping_tasks ))
6865 for task in self .ping_tasks :
69- async_tasks .create_task (self .maybe_ping_later (task ), self . bot . loop )
66+ asyncio .create_task (self .maybe_ping_later (task ))
7067
7168 @commands .group (invoke_without_command = True )
7269 @checks .has_permissions (PermissionLevel .SUPPORTER )
@@ -84,8 +81,6 @@ async def set_delay(self, ctx: commands.Context) -> None:
8481 @checks .has_permissions (PermissionLevel .OWNER )
8582 async def set_initial (self , ctx : commands .Context , wait_duration : int ) -> None :
8683 """Set the number of seconds to wait after a thread is opened to ping."""
87- await self .init_task
88-
8984 await self .db .find_one_and_update (
9085 {"_id" : "ping-delay-config" },
9186 {"$set" : {"initial_wait_duration" : wait_duration }},
@@ -98,8 +93,6 @@ async def set_initial(self, ctx: commands.Context, wait_duration: int) -> None:
9893 @checks .has_permissions (PermissionLevel .OWNER )
9994 async def set_delayed (self , ctx : commands .Context , wait_duration : int ) -> None :
10095 """Set the number of seconds to wait after a thread is opened to ping."""
101- await self .init_task
102-
10396 await self .db .find_one_and_update (
10497 {"_id" : "ping-delay-config" },
10598 {"$set" : {"delayed_wait_duration" : wait_duration }},
@@ -127,8 +120,6 @@ async def ping_string(self, ctx: commands.Context) -> None:
127120 @ping_string .command (name = "set" )
128121 async def set_ping (self , ctx : commands .Context , ping_string : str ) -> None :
129122 """Set what to send after a waiting for a thread to be responded to."""
130- await self .init_task
131-
132123 await self .db .find_one_and_update (
133124 {"_id" : "ping-delay-config" },
134125 {"$set" : {"ping_string" : ping_string }},
@@ -153,8 +144,6 @@ async def ping_ignore_categories(self, ctx: commands.Context) -> None:
153144 @ping_ignore_categories .command (name = "add" , aliases = ("set" ,))
154145 async def set_category (self , ctx : commands .Context , category_to_ignore : discord .CategoryChannel ) -> None :
155146 """Add a category to the list of ignored categories."""
156- await self .init_task
157-
158147 if category_to_ignore .id in self .config .ignored_categories :
159148 await ctx .send (f":x: { category_to_ignore } already in the ignored categories." )
160149 return
@@ -172,8 +161,6 @@ async def set_category(self, ctx: commands.Context, category_to_ignore: discord.
172161 @ping_ignore_categories .command (name = "get" )
173162 async def get_category (self , ctx : commands .Context ) -> None :
174163 """Get the list of ignored categories."""
175- await self .init_task
176-
177164 if not self .config .ignored_categories :
178165 await ctx .send ("There are currently no ignored categories." )
179166 return
@@ -185,8 +172,6 @@ async def get_category(self, ctx: commands.Context) -> None:
185172 @ping_ignore_categories .command (name = "delete" , aliases = ("remove" , "del" , "rem" ))
186173 async def del_category (self , ctx : commands .Context , category_to_ignore : discord .CategoryChannel ) -> None :
187174 """Remove a category from the list of ignored categories."""
188- await self .init_task
189-
190175 if category_to_ignore .id not in self .config .ignored_categories :
191176 await ctx .send (f":x: { category_to_ignore } isn't in the ignored categories list." )
192177 return
@@ -208,7 +193,7 @@ async def add_ping_task(self, task: PingTask) -> None:
208193 upsert = True ,
209194 )
210195
211- async_tasks .create_task (self .maybe_ping_later (task ), self . bot . loop )
196+ asyncio .create_task (self .maybe_ping_later (task ))
212197
213198 async def remove_ping_task (self , task : PingTask ) -> None :
214199 """Removes a ping task to the internal cache and to the db."""
@@ -289,7 +274,6 @@ async def maybe_ping_later(self, ping_task: PingTask) -> None:
289274 @commands .Cog .listener ()
290275 async def on_thread_ready (self , thread : Thread , * args ) -> None :
291276 """Schedule a task to check if the bot should ping in the thread after the defined wait duration."""
292- await self .init_task
293277 now = datetime .utcnow ()
294278 ping_task = PingTask (
295279 when_to_ping = (now + timedelta (seconds = self .config .initial_wait_duration )).isoformat (),
0 commit comments