@@ -23,8 +23,6 @@ def __init__(self, manager, recipient):
23
23
self .recipient = recipient
24
24
self .channel = None
25
25
self .ready_event = asyncio .Event ()
26
- self .close_task = None
27
- self .close_after = 0 # seconds
28
26
29
27
def __repr__ (self ):
30
28
return f'Thread(recipient="{ self .recipient } ", channel={ self .channel .id } )'
@@ -42,21 +40,18 @@ def ready(self, flag):
42
40
if flag is True :
43
41
self .ready_event .set ()
44
42
45
- async def _close_after (self , after , ** kwargs ):
46
- await asyncio .sleep (after )
47
- kwargs ['scheduled' ] = True
48
- await self .close (** kwargs )
43
+ async def _close_after (self , closer , silent , delete_channel , message ):
44
+ return self .bot .loop .create_task (self ._close (closer , silent , delete_channel , message , True ))
49
45
50
- async def close (self , * , closer , after = 0 , silent = False , delete_channel = True , message = None , scheduled = False ):
46
+ async def close (self , * , closer , after = 0 , silent = False , delete_channel = True , message = None ):
51
47
'''Close a thread now or after a set time in seconds'''
52
- if self .close_task is not None and not self .close_task .cancelled ():
53
- if not scheduled or after > 0 :
54
- self .close_task .cancel ()
55
48
56
49
if after > 0 :
57
- self .close_task = asyncio .create_task (self ._close_after (after , closer = closer , silent = silent , message = message ))
58
- return
50
+ return await self .bot .loop .call_later (after , silent , delete_channel , message )
51
+
52
+ return await self ._close (closer , silent , delete_channel , message )
59
53
54
+ async def _close (self , closer , silent = False , delete_channel = True , message = None , scheduled = False ):
60
55
del self .manager .cache [self .id ]
61
56
if str (self .id ) in self .bot .config .subscriptions :
62
57
del self .bot .config .subscriptions [str (self .id )]
@@ -73,7 +68,8 @@ async def close(self, *, closer, after=0, silent=False, delete_channel=True, mes
73
68
})
74
69
75
70
if isinstance (log_data , str ):
76
- print (log_data ) # errored somehow on server
71
+ print (log_data ) # errored somehow on server
72
+ return
77
73
78
74
if self .bot .selfhosted :
79
75
log_url = f'{ self .bot .config .log_url } /logs/{ log_data ["key" ]} '
0 commit comments