@@ -50,10 +50,8 @@ async def close(self, *, closer, after=0, silent=False,
50
50
delete_channel = True , message = None ):
51
51
"""Close a thread now or after a set time in seconds"""
52
52
53
- if self .close_task is not None :
54
- # restarts the after timer
55
- self .close_task .cancel ()
56
- self .close_task = None
53
+ # restarts the after timer
54
+ await self .cancel_closure ()
57
55
58
56
if after > 0 :
59
57
# TODO: Add somewhere to clean up broken closures
@@ -82,9 +80,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
82
80
message = None , scheduled = False ):
83
81
del self .manager .cache [self .id ]
84
82
85
- if scheduled :
86
- self .bot .config .closures .pop (str (self .id ), None )
87
- await self .bot .config .update ()
83
+ await self .cancel_closure ()
88
84
89
85
if str (self .id ) in self .bot .config .subscriptions :
90
86
del self .bot .config .subscriptions [str (self .id )]
@@ -112,7 +108,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
112
108
log_url = f"https://logs.modmail.tk/" \
113
109
f"{ log_data ['user_id' ]} /{ log_data ['key' ]} "
114
110
115
- user = self .recipient .mention if self .recipient else str ( self .id )
111
+ user = self .recipient .mention if self .recipient else f'` { self .id } `'
116
112
117
113
if log_data ['messages' ]:
118
114
msg = str (log_data ['messages' ][0 ]['content' ])
@@ -148,6 +144,15 @@ async def _close(self, closer, silent=False, delete_channel=True,
148
144
149
145
await asyncio .gather (* tasks )
150
146
147
+ async def cancel_closure (self ):
148
+ if self .close_task is not None :
149
+ self .close_task .cancel ()
150
+ self .close_task = None
151
+
152
+ to_update = self .bot .config .closures .pop (str (self .id ), None )
153
+ if to_update is not None :
154
+ await self .bot .config .update ()
155
+
151
156
@staticmethod
152
157
async def _edit_thread_message (channel , message_id , message ):
153
158
async for msg in channel .history ():
@@ -188,8 +193,7 @@ async def reply(self, message):
188
193
189
194
if self .close_task is not None :
190
195
# cancel closing if a thread message is sent.
191
- self .close_task .cancel ()
192
- self .close_task = None
196
+ await self .cancel_closure ()
193
197
tasks .append (self .channel .send (
194
198
embed = discord .Embed (color = discord .Color .red (),
195
199
description = 'Scheduled close has '
@@ -200,8 +204,7 @@ async def reply(self, message):
200
204
async def send (self , message , destination = None , from_mod = False ):
201
205
if self .close_task is not None :
202
206
# cancel closing if a thread message is sent.
203
- self .close_task .cancel ()
204
- self .close_task = None
207
+ await self .cancel_closure ()
205
208
await self .channel .send (embed = discord .Embed (
206
209
color = discord .Color .red (),
207
210
description = 'Scheduled close has been cancelled.' ))
0 commit comments