Skip to content

Commit ef2c10b

Browse files
committed
Add fallback method of searching through cache when channel topic is invalid
1 parent 986b744 commit ef2c10b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

core/thread.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ async def setup(self, *, creator=None, category=None):
127127
log_url = log_count = None
128128
# ensure core functionality still works
129129

130-
topic = f"User ID: {recipient.id}"
131130
if creator:
132131
mention = None
133132
else:
@@ -147,7 +146,7 @@ async def send_genesis_message():
147146
self.ready = True
148147
self.bot.dispatch("thread_ready", self)
149148

150-
await channel.edit(topic=topic)
149+
await channel.edit(topic=f"User ID: {recipient.id}")
151150
self.bot.loop.create_task(send_genesis_message())
152151

153152
# Once thread is ready, tell the recipient.
@@ -735,7 +734,13 @@ async def find(
735734
) -> Thread:
736735
"""Finds a thread from cache or from discord channel topics."""
737736
if recipient is None and channel is not None:
738-
return self._find_from_channel(channel)
737+
thread = self._find_from_channel(channel)
738+
if thread is None:
739+
id, thread = next(((k, v) for k, v in self.cache.items() if v.channel == channel), (-1, None))
740+
if thread is not None:
741+
logger.debug('Found thread with tempered ID.')
742+
await channel.edit(topic=f"User ID: {id}")
743+
return thread
739744

740745
thread = None
741746

core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def match_user_id(text: str) -> int:
188188
int
189189
The user ID if found. Otherwise, -1.
190190
"""
191-
match = re.match(r"^User ID: (\d+)$", text)
191+
match = re.search(r"\bUser ID: (\d+)\b", text)
192192
if match is not None:
193193
return int(match.group(1))
194194
return -1

0 commit comments

Comments
 (0)