Skip to content

Commit cf7add6

Browse files
committed
Fix long scheduled close bug
1 parent 8195196 commit cf7add6

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# v2.16.1
8+
9+
### Fixed
10+
11+
An issue where a scheduled close would not execute over a long period of time if the recipient no shares any servers with the bot.
12+
713
# v2.16.0
814

915
### What's new?

bot.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = '2.16.0'
25+
__version__ = '2.16.1'
2626

2727
import asyncio
2828
import logging
@@ -412,25 +412,23 @@ async def on_ready(self):
412412
datetime.utcnow()).total_seconds()
413413
if after < 0:
414414
after = 0
415-
recipient = self.get_user(int(recipient_id))
416415

417-
thread = await self.threads.find(recipient=recipient)
416+
thread = await self.threads.find(recipient_id=int(recipient_id))
418417

419418
if not thread:
420-
# If the recipient is gone or channel is deleted
419+
# If the channel is deleted
421420
self.config.closures.pop(str(recipient_id))
422421
await self.config.update()
423422
continue
424423

425-
# TODO: Low priority,
426-
# Retrieve messages/replies when bot is down, from history?
427424
await thread.close(
428425
closer=self.get_user(items['closer_id']),
429426
after=after,
430427
silent=items['silent'],
431428
delete_channel=items['delete_channel'],
432429
message=items['message']
433430
)
431+
434432
logger.info(LINE)
435433

436434
async def convert_emoji(self, name):

core/thread.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -587,22 +587,26 @@ def __iter__(self):
587587
def __getitem__(self, item):
588588
return self.cache[item]
589589

590-
async def find(self, *, recipient=None, channel=None):
590+
async def find(self, *, recipient=None, channel=None, recipient_id=None):
591591
"""Finds a thread from cache or from discord channel topics."""
592592
if recipient is None and channel is not None:
593593
return await self._find_from_channel(channel)
594594

595595
thread = None
596+
597+
if recipient:
598+
recipient_id = recipient.id
599+
596600
try:
597-
thread = self.cache[recipient.id]
601+
thread = self.cache[recipient_id]
598602
except KeyError:
599603
channel = discord.utils.get(
600604
self.bot.modmail_guild.text_channels,
601-
topic=f'User ID: {recipient.id}'
605+
topic=f'User ID: {recipient_id}'
602606
)
603607
if channel:
604608
thread = Thread(self, recipient, channel)
605-
self.cache[recipient.id] = thread
609+
self.cache[recipient_id] = thread
606610
thread.ready = True
607611
return thread
608612

0 commit comments

Comments
 (0)