diff --git a/main.py b/main.py index 812d086..cf67acf 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ class ReactorClient(discord.Client): self.display = display self.undo = undo self.known_channel_targets: dict[int, Target] = {} + self.known_guild_targets: dict[int, Target] = {} self._started = False async def on_ready(self): @@ -92,6 +93,7 @@ class ReactorClient(discord.Client): cutoff, react_fn, display=self.display, ) else: + self.known_guild_targets[target.target_id] = target for channel in get_scannable_channels(self, target.target_id): self.known_channel_targets[channel.id] = target await scan_channel_backlog( @@ -107,6 +109,20 @@ class ReactorClient(discord.Client): if self.undo: return 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: return if message.author.id != self.cfg.friend_id: