RSS bot: drop /new command — purely publishing
Remove the /new command, the on-connect latest-items send, the _rss_send_latest helper and the now-unused rss_items cache. The bot only watches the feed and broadcasts new posts to its channel. Update welcome + UI copy to drop /new. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -159,7 +159,6 @@ class RunningBot:
|
||||
histories: dict[int, list[dict]] = field(default_factory=dict)
|
||||
# RSS bot state
|
||||
rss_seen: set = field(default_factory=set) # entry ids already posted
|
||||
rss_items: list = field(default_factory=list) # latest fetched entries (newest first)
|
||||
rss_next_poll: float = 0.0
|
||||
rss_gid: int | None = None # broadcast channel group id
|
||||
|
||||
@@ -504,7 +503,6 @@ async def _rss_poll(b: "RunningBot", chat: Any, gid: int | None, config: dict, s
|
||||
log.error("rss fetch error: %s", e)
|
||||
_append_log(b, f"RSS fetch error: {e}")
|
||||
return
|
||||
b.rss_items = entries
|
||||
new = [e for e in entries if e["id"] not in b.rss_seen]
|
||||
for e in new:
|
||||
b.rss_seen.add(e["id"])
|
||||
@@ -521,22 +519,6 @@ async def _rss_poll(b: "RunningBot", chat: Any, gid: int | None, config: dict, s
|
||||
_append_log(b, f"RSS posted {len(new)} new item(s)")
|
||||
|
||||
|
||||
async def _rss_send_latest(chat: Any, item: dict, b: "RunningBot", n: int = 3) -> None:
|
||||
"""Reply to a direct request (e.g. /new) with the latest feed items."""
|
||||
items = b.rss_items[:n]
|
||||
if not items:
|
||||
try:
|
||||
await chat.api_send_text_reply(item, "No items yet — check back soon.")
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
for e in items:
|
||||
try:
|
||||
await chat.api_send_text_reply(item, _rss_format(e))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
async def _run_bot(
|
||||
profile_id: int,
|
||||
name: str,
|
||||
@@ -599,7 +581,7 @@ async def _run_bot(
|
||||
# auto-reply greets each new contact (default lists allowed publishers)
|
||||
settings["autoReply"] = {"type": "text", "text": _bc_welcome(config, name)}
|
||||
elif bot_type == "rss":
|
||||
welcome = config.get("welcome_message") or f"Subscribed to {name}. Send /new for the latest posts."
|
||||
welcome = config.get("welcome_message") or f"You're subscribed to {name}."
|
||||
settings["autoReply"] = {"type": "text", "text": welcome}
|
||||
elif bot_type in ("echo", "llm", "directory", "deadmans"):
|
||||
welcome = config.get("welcome_message", f"Connected to {name}.")
|
||||
@@ -679,16 +661,7 @@ async def _run_bot(
|
||||
_append_log(b, f"Contact connected: {ct_name}")
|
||||
|
||||
# echo replies on message; broadcast/others greet via the auto-reply
|
||||
# configured in address settings. RSS also sends the latest items on connect.
|
||||
if bot_type == "rss":
|
||||
cid = ct.get("contactId")
|
||||
if cid is not None: # send the latest items directly to the new contact
|
||||
for e in b.rss_items[:3]:
|
||||
try:
|
||||
await chat.api_send_text_message(
|
||||
{"chatType": "direct", "chatId": cid}, _rss_format(e))
|
||||
except Exception:
|
||||
pass
|
||||
# configured in address settings, so nothing to do on connect here.
|
||||
|
||||
elif tag == "newChatItems":
|
||||
items = evt.get("chatItems", [])
|
||||
@@ -743,10 +716,6 @@ async def _run_bot(
|
||||
b, chat, config, item, chat_info, text, DEFAULT_LLM_PROMPT
|
||||
)
|
||||
|
||||
elif bot_type == "rss" and text:
|
||||
if text.strip().lower() == "/new":
|
||||
await _rss_send_latest(chat, item, b)
|
||||
|
||||
elif bot_type == "directory" and text:
|
||||
await _handle_directory_message(
|
||||
b, chat, config, name, item, chat_info, text
|
||||
|
||||
Reference in New Issue
Block a user