refactor(discord): inline backfill gate and document intent

Drop the _needed_mention local variable now that it has only one use,
inline its expression as _has_mention_gap, and add a comment explaining
the three backfill cases (mention-gated channel, thread, DM skip).

Behaviorally identical to the prior commit; cleanup only.

Co-authored-by: liuhao1024 <liuhao1024@users.noreply.github.com>
This commit is contained in:
teknium1 2026-05-28 03:42:34 -07:00 committed by Teknium
parent eafe11d456
commit 68ddd6b338

View file

@ -4811,14 +4811,17 @@ class DiscordAdapter(BasePlatformAdapter):
# to keep the partition rule clean.
_channel_context = None
_is_dm = isinstance(message.channel, discord.DMChannel)
if not _is_dm:
_needed_mention = (
require_mention
and not is_free_channel
and not in_bot_thread
)
_backfill_enabled = self._discord_history_backfill()
if _backfill_enabled and (_needed_mention or is_thread):
if not _is_dm and self._discord_history_backfill():
# Run backfill when there's a real gap to fill:
# - mention-gated channels with no free-response override
# (messages between bot turns aren't in the transcript)
# - any thread (in_bot_thread bypasses the mention check, but
# processing-window gaps and post-restart context still need
# recovery)
# DMs skip entirely because every DM message triggers the bot,
# so the session transcript already has everything.
_has_mention_gap = require_mention and not is_free_channel and not in_bot_thread
if _has_mention_gap or is_thread:
_backfill_text = await self._fetch_channel_context(
message.channel, before=message,
)