Skip to content

Commit 9756425

Browse files
committed
Close cancel also cancels auto close
1 parent 288e13f commit 9756425

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

cogs/modmail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async def close(self, ctx, *, after: UserFriendlyTime = None):
252252
if cancel:
253253

254254
if thread.close_task is not None:
255-
await thread.cancel_closure()
255+
await thread.cancel_closure(all=True)
256256
embed = discord.Embed(
257257
color=discord.Color.red(),
258258
description="Scheduled close has been cancelled.",

core/thread.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,17 @@ async def setup(self, *, creator=None, category=None):
102102
overwrites=overwrites,
103103
reason="Creating a thread channel",
104104
)
105-
except discord.HTTPException as e: # Failed to create due to 50 channel limit.
105+
except discord.HTTPException as e: # Failed to create due to 50 channel limit.
106106
del self.manager.cache[self.id]
107107
log_channel = self.bot.log_channel
108108

109109
em = discord.Embed(color=discord.Color.red())
110-
em.title = 'Error while trying to create a thread'
110+
em.title = "Error while trying to create a thread"
111111
em.description = e.message
112-
em.add_field(name='Recipient', value=recipient.mention)
112+
em.add_field(name="Recipient", value=recipient.mention)
113113

114114
if log_channel is not None:
115115
return await log_channel.send(embed=em)
116-
117116

118117
self._channel = channel
119118

@@ -191,7 +190,7 @@ async def close(
191190
silent: bool = False,
192191
delete_channel: bool = True,
193192
message: str = None,
194-
auto_close: bool = False
193+
auto_close: bool = False,
195194
) -> None:
196195
"""Close a thread now or after a set time in seconds"""
197196

@@ -333,12 +332,11 @@ async def _close(
333332

334333
await asyncio.gather(*tasks)
335334

336-
async def cancel_closure(self, auto_close: bool = False) -> None:
337-
338-
if self.close_task is not None and not auto_close:
335+
async def cancel_closure(self, auto_close: bool = False, all: bool = False) -> None:
336+
if self.close_task is not None and not auto_close or both:
339337
self.close_task.cancel()
340338
self.close_task = None
341-
elif self.auto_close_task is not None:
339+
if self.auto_close_task is not None and auto_close or both:
342340
self.auto_close_task.cancel()
343341
self.auto_close_task = None
344342

@@ -415,7 +413,9 @@ async def _restart_close_timer(self):
415413
f" '{time_marker_regex}' to specify time."
416414
)
417415

418-
await self.close(closer=self.bot.user, after=seconds, message=close_message, auto_close=True)
416+
await self.close(
417+
closer=self.bot.user, after=seconds, message=close_message, auto_close=True
418+
)
419419

420420
async def edit_message(self, message_id: int, message: str) -> None:
421421
recipient_msg, channel_msg = await asyncio.gather(
@@ -503,7 +503,6 @@ async def reply(self, message: discord.Message, anonymous: bool = False) -> None
503503
)
504504
)
505505

506-
507506
# Cancel closing if a thread message is sent.
508507
if self.close_task is not None:
509508
await self.cancel_closure()
@@ -529,7 +528,9 @@ async def send(
529528
anonymous: bool = False,
530529
) -> None:
531530

532-
self.bot.loop.create_task(self._restart_close_timer()) # Start or restart thread auto close
531+
self.bot.loop.create_task(
532+
self._restart_close_timer()
533+
) # Start or restart thread auto close
533534

534535
if self.close_task is not None:
535536
# cancel closing if a thread message is sent.
@@ -549,7 +550,6 @@ async def send(
549550
if not from_mod and not note:
550551
self.bot.loop.create_task(self.bot.api.append_log(message, self.channel.id))
551552

552-
553553
destination = destination or self.channel
554554

555555
author = message.author

0 commit comments

Comments
 (0)