@@ -50,10 +50,8 @@ async def close(self, *, closer, after=0, silent=False,
5050 delete_channel = True , message = None ):
5151 """Close a thread now or after a set time in seconds"""
5252
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 ()
5755
5856 if after > 0 :
5957 # TODO: Add somewhere to clean up broken closures
@@ -82,9 +80,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
8280 message = None , scheduled = False ):
8381 del self .manager .cache [self .id ]
8482
85- if scheduled :
86- self .bot .config .closures .pop (str (self .id ), None )
87- await self .bot .config .update ()
83+ await self .cancel_closure ()
8884
8985 if str (self .id ) in self .bot .config .subscriptions :
9086 del self .bot .config .subscriptions [str (self .id )]
@@ -112,7 +108,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
112108 log_url = f"https://logs.modmail.tk/" \
113109 f"{ log_data ['user_id' ]} /{ log_data ['key' ]} "
114110
115- user = self .recipient .mention if self .recipient else str ( self .id )
111+ user = self .recipient .mention if self .recipient else f'` { self .id } `'
116112
117113 if log_data ['messages' ]:
118114 msg = str (log_data ['messages' ][0 ]['content' ])
@@ -148,6 +144,15 @@ async def _close(self, closer, silent=False, delete_channel=True,
148144
149145 await asyncio .gather (* tasks )
150146
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+
151156 @staticmethod
152157 async def _edit_thread_message (channel , message_id , message ):
153158 async for msg in channel .history ():
@@ -188,8 +193,7 @@ async def reply(self, message):
188193
189194 if self .close_task is not None :
190195 # cancel closing if a thread message is sent.
191- self .close_task .cancel ()
192- self .close_task = None
196+ await self .cancel_closure ()
193197 tasks .append (self .channel .send (
194198 embed = discord .Embed (color = discord .Color .red (),
195199 description = 'Scheduled close has '
@@ -200,8 +204,7 @@ async def reply(self, message):
200204 async def send (self , message , destination = None , from_mod = False ):
201205 if self .close_task is not None :
202206 # cancel closing if a thread message is sent.
203- self .close_task .cancel ()
204- self .close_task = None
207+ await self .cancel_closure ()
205208 await self .channel .send (embed = discord .Embed (
206209 color = discord .Color .red (),
207210 description = 'Scheduled close has been cancelled.' ))
0 commit comments