10
10
from core import checks
11
11
from core .models import PermissionLevel , getLogger
12
12
from core .thread import Thread
13
- from .utils import async_tasks
14
13
15
14
# Remove view perms from this role while pining, so only on-duty mods get the ping.
16
15
MOD_TEAM_ROLE_ID = 267629731250176001
@@ -49,9 +48,7 @@ def __init__(self, bot: ModmailBot):
49
48
self .ping_tasks : list [PingTask ] = None
50
49
self .db = bot .api .get_plugin_partition (self )
51
50
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 :
55
52
"""Fetch the current config from the db."""
56
53
db_config = await self .db .find_one ({"_id" : "ping-delay-config" })
57
54
db_config = db_config or {}
@@ -66,7 +63,7 @@ async def init_plugin(self) -> None:
66
63
log .info ("Loaded config: %s" , self .config )
67
64
log .info ("Loaded %d ping tasks" , len (self .ping_tasks ))
68
65
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 ))
70
67
71
68
@commands .group (invoke_without_command = True )
72
69
@checks .has_permissions (PermissionLevel .SUPPORTER )
@@ -84,8 +81,6 @@ async def set_delay(self, ctx: commands.Context) -> None:
84
81
@checks .has_permissions (PermissionLevel .OWNER )
85
82
async def set_initial (self , ctx : commands .Context , wait_duration : int ) -> None :
86
83
"""Set the number of seconds to wait after a thread is opened to ping."""
87
- await self .init_task
88
-
89
84
await self .db .find_one_and_update (
90
85
{"_id" : "ping-delay-config" },
91
86
{"$set" : {"initial_wait_duration" : wait_duration }},
@@ -98,8 +93,6 @@ async def set_initial(self, ctx: commands.Context, wait_duration: int) -> None:
98
93
@checks .has_permissions (PermissionLevel .OWNER )
99
94
async def set_delayed (self , ctx : commands .Context , wait_duration : int ) -> None :
100
95
"""Set the number of seconds to wait after a thread is opened to ping."""
101
- await self .init_task
102
-
103
96
await self .db .find_one_and_update (
104
97
{"_id" : "ping-delay-config" },
105
98
{"$set" : {"delayed_wait_duration" : wait_duration }},
@@ -127,8 +120,6 @@ async def ping_string(self, ctx: commands.Context) -> None:
127
120
@ping_string .command (name = "set" )
128
121
async def set_ping (self , ctx : commands .Context , ping_string : str ) -> None :
129
122
"""Set what to send after a waiting for a thread to be responded to."""
130
- await self .init_task
131
-
132
123
await self .db .find_one_and_update (
133
124
{"_id" : "ping-delay-config" },
134
125
{"$set" : {"ping_string" : ping_string }},
@@ -153,8 +144,6 @@ async def ping_ignore_categories(self, ctx: commands.Context) -> None:
153
144
@ping_ignore_categories .command (name = "add" , aliases = ("set" ,))
154
145
async def set_category (self , ctx : commands .Context , category_to_ignore : discord .CategoryChannel ) -> None :
155
146
"""Add a category to the list of ignored categories."""
156
- await self .init_task
157
-
158
147
if category_to_ignore .id in self .config .ignored_categories :
159
148
await ctx .send (f":x: { category_to_ignore } already in the ignored categories." )
160
149
return
@@ -172,8 +161,6 @@ async def set_category(self, ctx: commands.Context, category_to_ignore: discord.
172
161
@ping_ignore_categories .command (name = "get" )
173
162
async def get_category (self , ctx : commands .Context ) -> None :
174
163
"""Get the list of ignored categories."""
175
- await self .init_task
176
-
177
164
if not self .config .ignored_categories :
178
165
await ctx .send ("There are currently no ignored categories." )
179
166
return
@@ -185,8 +172,6 @@ async def get_category(self, ctx: commands.Context) -> None:
185
172
@ping_ignore_categories .command (name = "delete" , aliases = ("remove" , "del" , "rem" ))
186
173
async def del_category (self , ctx : commands .Context , category_to_ignore : discord .CategoryChannel ) -> None :
187
174
"""Remove a category from the list of ignored categories."""
188
- await self .init_task
189
-
190
175
if category_to_ignore .id not in self .config .ignored_categories :
191
176
await ctx .send (f":x: { category_to_ignore } isn't in the ignored categories list." )
192
177
return
@@ -208,7 +193,7 @@ async def add_ping_task(self, task: PingTask) -> None:
208
193
upsert = True ,
209
194
)
210
195
211
- async_tasks .create_task (self .maybe_ping_later (task ), self . bot . loop )
196
+ asyncio .create_task (self .maybe_ping_later (task ))
212
197
213
198
async def remove_ping_task (self , task : PingTask ) -> None :
214
199
"""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:
289
274
@commands .Cog .listener ()
290
275
async def on_thread_ready (self , thread : Thread , * args ) -> None :
291
276
"""Schedule a task to check if the bot should ping in the thread after the defined wait duration."""
292
- await self .init_task
293
277
now = datetime .utcnow ()
294
278
ping_task = PingTask (
295
279
when_to_ping = (now + timedelta (seconds = self .config .initial_wait_duration )).isoformat (),
0 commit comments