added RAG, Multiuser, TG bot

This commit is contained in:
2026-06-14 06:26:16 +00:00
parent c8a9429bed
commit 0c8ab6018a
24 changed files with 1280 additions and 479 deletions
+8 -24
View File
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
from aiogram import Bot
from bot.ha_client import HaClient
from bot.notice_delivery import send_notice_content
from bot.storage import LinkedUser, Storage
if TYPE_CHECKING:
@@ -14,29 +15,6 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
NOTICE_ROLES = frozenset({"notice", "character"})
TG_MAX_LEN = 4096
def split_telegram_message(text: str, limit: int = TG_MAX_LEN) -> list[str]:
if len(text) <= limit:
return [text]
chunks: list[str] = []
remaining = text
while remaining:
if len(remaining) <= limit:
chunks.append(remaining)
break
split_at = remaining.rfind("\n", 0, limit)
if split_at <= 0:
split_at = limit
chunks.append(remaining[:split_at])
remaining = remaining[split_at:].lstrip("\n")
return chunks
async def send_text(bot: Bot, chat_id: int, text: str) -> None:
for chunk in split_telegram_message(text):
await bot.send_message(chat_id, chunk)
async def advance_cursors(
@@ -113,7 +91,13 @@ async def sync_notices_for_user(
pending.sort(key=lambda item: item[0])
for _, content in pending:
try:
await send_text(bot, user.telegram_id, content)
await send_notice_content(
bot,
user.telegram_id,
content,
client,
ha_api_base=ha_base_url,
)
except Exception:
logger.exception("Failed to send notice to telegram_id=%s", user.telegram_id)