Files
fckbot/bots/commands/kb.py
2026-06-30 21:37:09 +00:00

44 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
Команда !kb список документов в базе знаний (личные/комнатные + глобальные).
Использует RAGClient.
"""
import logging
from core.commands.base import Command
logger = logging.getLogger(__name__)
class KbCommand(Command):
name = "!kb"
aliases = ["/kb"]
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
try:
result = await self.bot.rag_client.list_documents(user_jid, room_jid)
sources = result.get('documents', [])
if not sources:
reply = msg.reply("📭 База знаний пуста.")
else:
global_docs = [s['source_name'] for s in sources if s.get('is_global')]
other_docs = [s['source_name'] for s in sources if not s.get('is_global')]
lines = []
if global_docs:
lines.append("🌍 Глобальные:")
lines.extend(f"{name}" for name in global_docs)
if other_docs:
if room_jid:
lines.append(f"🏠 Документы комнаты {room_jid}:")
else:
lines.append("👤 Личные документы:")
lines.extend(f"{name}" for name in other_docs)
reply = msg.reply("\n".join(lines))
except Exception as e:
logger.exception(f"Ошибка в !kb: {e}")
reply = msg.reply(f"❌ Ошибка: {e}")
if reply:
reply.send()
def get_help(self) -> str:
return "Показывает список документов в базе знаний (личные/комнатные + глобальные)."