Skip to content

Commit 5cb06a5

Browse files
committed
fix: 渠道优先级 — 支持用户显式指定提醒渠道
1 parent d7045f1 commit 5cb06a5

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

scripts/srs.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,12 +2271,16 @@ def _cron_exists(name: str) -> bool:
22712271
return False
22722272

22732273

2274-
def _get_user_delivery() -> tuple[str, str] | None:
2274+
def _get_user_delivery(channel_filter: str = "") -> tuple[str, str] | None:
22752275
"""Detect the user's delivery target from OpenClaw sessions.
22762276
22772277
Parses the session key format: agent:main:{channel}:{kind}:{chat_id}
22782278
to extract both the channel provider and the user's chat ID.
22792279
2280+
Args:
2281+
channel_filter: If provided, only match sessions from this channel.
2282+
E.g., "openclaw-weixin" to find the WeChat session.
2283+
22802284
Returns:
22812285
(channel, chat_id) tuple, e.g., ("openclaw-weixin", "o9cq80...@im.wechat"),
22822286
or None if not detected.
@@ -2308,6 +2312,9 @@ def _get_user_delivery() -> tuple[str, str] | None:
23082312
if len(parts) >= 5:
23092313
channel = parts[2] # e.g., "openclaw-weixin"
23102314
chat_id = ":".join(parts[4:]) # e.g., "o9cq80...@im.wechat" (may contain colons)
2315+
# If filter specified, only return matching channel
2316+
if channel_filter and channel != channel_filter:
2317+
continue
23112318
return (channel, chat_id)
23122319
return None
23132320
except (subprocess.TimeoutExpired, json.JSONDecodeError, FileNotFoundError):
@@ -2422,10 +2429,27 @@ def cmd_setup_reminder(args: list[str]) -> None:
24222429

24232430
hour = reminder_time.split(":")[0]
24242431

2425-
# Detect user delivery target (channel + chat_id)
2426-
user_delivery = _get_user_delivery()
2427-
user_channel = user_delivery[0] if user_delivery else None
2428-
user_to = f"{user_delivery[0]}:{user_delivery[1]}" if user_delivery else None
2432+
# Resolve delivery target with priority:
2433+
# 1. config.active_channel (user-explicit) → find that channel's session
2434+
# 2. Current session channel + chat_id (auto-detect)
2435+
# 3. No --to (legacy fallback)
2436+
active_channel = config.get("active_channel", "")
2437+
if active_channel:
2438+
# User explicitly chose a channel — find that channel's session
2439+
channel_delivery = _get_user_delivery(channel_filter=active_channel)
2440+
if channel_delivery:
2441+
user_channel = channel_delivery[0]
2442+
user_to = f"{channel_delivery[0]}:{channel_delivery[1]}"
2443+
else:
2444+
# Active channel set but no session found for it — fall back to current
2445+
session_delivery = _get_user_delivery()
2446+
user_channel = session_delivery[0] if session_delivery else None
2447+
user_to = f"{session_delivery[0]}:{session_delivery[1]}" if session_delivery else None
2448+
else:
2449+
# No explicit channel — auto-detect from current session
2450+
session_delivery = _get_user_delivery()
2451+
user_channel = session_delivery[0] if session_delivery else None
2452+
user_to = f"{session_delivery[0]}:{session_delivery[1]}" if session_delivery else None
24292453

24302454
# Setup daily reminder
24312455
if _cron_exists("retaincraft-reminder"):

0 commit comments

Comments
 (0)