@@ -40,8 +40,8 @@ def __init__(
40
40
self ._channel = channel
41
41
self .genesis_message = None
42
42
self ._ready_event = asyncio .Event ()
43
- self ._close_task = None
44
- self ._auto_close_task = None
43
+ self .close_task = None
44
+ self .auto_close_task = None
45
45
46
46
def __repr__ (self ):
47
47
return (
@@ -57,14 +57,6 @@ async def wait_until_ready(self) -> None:
57
57
def id (self ) -> int :
58
58
return self ._id
59
59
60
- @property
61
- def close_task (self ) -> asyncio .TimerHandle :
62
- return self ._close_task
63
-
64
- @close_task .setter
65
- def close_task (self , val : asyncio .TimerHandle ):
66
- self ._close_task = val
67
-
68
60
@property
69
61
def channel (self ) -> typing .Union [discord .TextChannel , discord .DMChannel ]:
70
62
return self ._channel
@@ -199,11 +191,12 @@ async def close(
199
191
silent : bool = False ,
200
192
delete_channel : bool = True ,
201
193
message : str = None ,
194
+ auto_close : bool = False
202
195
) -> None :
203
196
"""Close a thread now or after a set time in seconds"""
204
197
205
198
# restarts the after timer
206
- await self .cancel_closure ()
199
+ await self .cancel_closure (auto_close )
207
200
208
201
if after > 0 :
209
202
# TODO: Add somewhere to clean up broken closures
@@ -221,9 +214,14 @@ async def close(
221
214
self .bot .config .closures [str (self .id )] = items
222
215
await self .bot .config .update ()
223
216
224
- self . close_task = self .bot .loop .call_later (
217
+ task = self .bot .loop .call_later (
225
218
after , self ._close_after , closer , silent , delete_channel , message
226
219
)
220
+
221
+ if auto_close :
222
+ self .auto_close_task = task
223
+ else :
224
+ self .close_task = task
227
225
else :
228
226
await self ._close (closer , silent , delete_channel , message )
229
227
@@ -235,8 +233,6 @@ async def _close(
235
233
await self .cancel_closure ()
236
234
237
235
# Cancel auto closing the thread if closed by any means.
238
- if self ._auto_close_task :
239
- self ._auto_close_task .cancel ()
240
236
241
237
if str (self .id ) in self .bot .config .subscriptions :
242
238
del self .bot .config .subscriptions [str (self .id )]
@@ -337,10 +333,14 @@ async def _close(
337
333
338
334
await asyncio .gather (* tasks )
339
335
340
- async def cancel_closure (self ) -> None :
341
- if self .close_task is not None :
336
+ async def cancel_closure (self , auto_close : bool = False ) -> None :
337
+
338
+ if self .close_task is not None and not auto_close :
342
339
self .close_task .cancel ()
343
340
self .close_task = None
341
+ elif self .auto_close_task is not None :
342
+ self .auto_close_task .cancel ()
343
+ self .auto_close_task = None
344
344
345
345
to_update = self .bot .config .closures .pop (str (self .id ), None )
346
346
if to_update is not None :
@@ -415,7 +415,7 @@ async def _restart_close_timer(self):
415
415
f" '{ time_marker_regex } ' to specify time."
416
416
)
417
417
418
- await self .close (closer = self .bot .user , after = seconds , message = close_message )
418
+ await self .close (closer = self .bot .user , after = seconds , message = close_message , auto_close = True )
419
419
420
420
async def edit_message (self , message_id : int , message : str ) -> None :
421
421
recipient_msg , channel_msg = await asyncio .gather (
@@ -505,15 +505,16 @@ async def reply(self, message: discord.Message, anonymous: bool = False) -> None
505
505
506
506
507
507
# Cancel closing if a thread message is sent.
508
- await self .cancel_closure ()
509
- tasks .append (
510
- self .channel .send (
511
- embed = discord .Embed (
512
- color = discord .Color .red (),
513
- description = "Scheduled close has been cancelled." ,
508
+ if self .close_task is not None :
509
+ await self .cancel_closure ()
510
+ tasks .append (
511
+ self .channel .send (
512
+ embed = discord .Embed (
513
+ color = discord .Color .red (),
514
+ description = "Scheduled close has been cancelled." ,
515
+ )
514
516
)
515
517
)
516
- )
517
518
518
519
await self ._restart_close_timer ()
519
520
@@ -547,9 +548,6 @@ async def send(
547
548
if not from_mod and not note :
548
549
self .bot .loop .create_task (self .bot .api .append_log (message , self .channel .id ))
549
550
550
- # Cancel auto closing if we get a new message from user
551
- if self ._auto_close_task :
552
- self ._auto_close_task .cancel ()
553
551
554
552
destination = destination or self .channel
555
553
0 commit comments