Pick up new channels/threads in known guilds without a restart
on_message only matched channels enumerated during the backlog scan, so a brand-new channel (or any type not scanned, like threads) was silently ignored until the next restart. Now falls back to a guild-level lookup and registers the channel for live watching going forward the first time a message arrives there.
This commit is contained in:
16
main.py
16
main.py
@@ -27,6 +27,7 @@ class ReactorClient(discord.Client):
|
|||||||
self.display = display
|
self.display = display
|
||||||
self.undo = undo
|
self.undo = undo
|
||||||
self.known_channel_targets: dict[int, Target] = {}
|
self.known_channel_targets: dict[int, Target] = {}
|
||||||
|
self.known_guild_targets: dict[int, Target] = {}
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
@@ -92,6 +93,7 @@ class ReactorClient(discord.Client):
|
|||||||
cutoff, react_fn, display=self.display,
|
cutoff, react_fn, display=self.display,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
self.known_guild_targets[target.target_id] = target
|
||||||
for channel in get_scannable_channels(self, target.target_id):
|
for channel in get_scannable_channels(self, target.target_id):
|
||||||
self.known_channel_targets[channel.id] = target
|
self.known_channel_targets[channel.id] = target
|
||||||
await scan_channel_backlog(
|
await scan_channel_backlog(
|
||||||
@@ -107,6 +109,20 @@ class ReactorClient(discord.Client):
|
|||||||
if self.undo:
|
if self.undo:
|
||||||
return
|
return
|
||||||
target = self.known_channel_targets.get(message.channel.id)
|
target = self.known_channel_targets.get(message.channel.id)
|
||||||
|
if target is None:
|
||||||
|
# Channel didn't exist (or wasn't enumerated, e.g. a thread) at
|
||||||
|
# backlog-scan time. If it belongs to an already-known mutual
|
||||||
|
# guild, start watching it now instead of requiring a restart —
|
||||||
|
# only its live messages going forward are covered, no backfill.
|
||||||
|
guild = getattr(message, "guild", None)
|
||||||
|
if guild is not None:
|
||||||
|
target = self.known_guild_targets.get(guild.id)
|
||||||
|
if target is not None:
|
||||||
|
self.known_channel_targets[message.channel.id] = target
|
||||||
|
log.info(
|
||||||
|
"New channel #%s in %s wasn't seen during backlog scan; watching it live from now on",
|
||||||
|
getattr(message.channel, "name", message.channel.id), target.name,
|
||||||
|
)
|
||||||
if target is None:
|
if target is None:
|
||||||
return
|
return
|
||||||
if message.author.id != self.cfg.friend_id:
|
if message.author.id != self.cfg.friend_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user