epimetheus: DM auto-respond gating (Rio suggestion)
DMs (private chats): conversation window auto-responds — always 1-on-1, no false positives. Groups (supergroup/group): conversation window tracks context silently, reply-to only trigger. Simple msg.chat.type check. Pentagon-Agent: Epimetheus <3D35839A-7722-4740-B93D-51157F7D5E70>
This commit is contained in:
parent
a75c14e536
commit
251caa3695
1 changed files with 18 additions and 7 deletions
|
|
@ -430,18 +430,29 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
if len(text) < MIN_MESSAGE_LENGTH:
|
if len(text) < MIN_MESSAGE_LENGTH:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Conversation window: track history silently, don't auto-respond
|
# Conversation window behavior depends on chat type (Rio: DMs vs groups)
|
||||||
# (Ganymede: window = context, not trigger. Reply-to is the only follow-up trigger.)
|
# DMs: auto-respond (always 1-on-1, no false positives)
|
||||||
|
# Groups: silent context only (reply-to is the only follow-up trigger)
|
||||||
user = msg.from_user
|
user = msg.from_user
|
||||||
|
is_dm = msg.chat.type == "private"
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
key = (msg.chat_id, user.id)
|
key = (msg.chat_id, user.id)
|
||||||
if key in unanswered_count:
|
if key in unanswered_count:
|
||||||
unanswered_count[key] += 1
|
unanswered_count[key] += 1
|
||||||
# Record message in conversation history for context (silent — no response)
|
|
||||||
history = conversation_history.setdefault(key, [])
|
if is_dm and unanswered_count[key] < CONVERSATION_WINDOW:
|
||||||
history.append({"user": text[:500], "bot": ""})
|
# DM: auto-respond — conversation window fires
|
||||||
if len(history) > MAX_HISTORY:
|
logger.info("DM conversation window: @%s msg %d/%d",
|
||||||
history.pop(0)
|
user.username or "?", unanswered_count[key], CONVERSATION_WINDOW)
|
||||||
|
await handle_tagged(update, context)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# Group: silent context tracking only
|
||||||
|
history = conversation_history.setdefault(key, [])
|
||||||
|
history.append({"user": text[:500], "bot": ""})
|
||||||
|
if len(history) > MAX_HISTORY:
|
||||||
|
history.pop(0)
|
||||||
# Expire window after CONVERSATION_WINDOW unanswered messages
|
# Expire window after CONVERSATION_WINDOW unanswered messages
|
||||||
if unanswered_count[key] >= CONVERSATION_WINDOW:
|
if unanswered_count[key] >= CONVERSATION_WINDOW:
|
||||||
del unanswered_count[key]
|
del unanswered_count[key]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue