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

37 lines
1.6 KiB
Python

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 "Показывает список документов в базе знаний (личные/комнатные + глобальные)."