Update 86 files

- /rag/commands/expert.py
- /core/services/__init__.py
- /core/services/embedding_service.py
- /core/services/file_service.py
- /core/services/giga_client.py
- /core/services/kb_service.py
- /core/services/postgres_service.py
- /core/services/qdrant_service.py
- /core/services/reranker_service.py
- /core/functions/__init__.py
- /core/functions/check_consistency.py
- /core/functions/check_spelling.py
- /core/functions/critique_answer.py
- /core/functions/expand_query.py
- /core/functions/extract_metrics.py
- /core/functions/file_processor.py
- /core/functions/generate_document.py
- /core/functions/intent_classify.py
- /core/functions/rerank_context.py
- /core/functions/summarize_document.py
- /core/utils/__init__.py
- /core/utils/arg_parser.py
- /core/utils/config_loader.py
- /core/utils/layout_converter.py
- /core/utils/logger.py
- /core/utils/text_utils.py
- /core/utils/web_utils.py
- /bots/commands/__init__.py
- /bots/commands/base.py
- /bots/commands/create.py
- /core/commands/global_remove.py
- /core/commands/help.py
- /core/commands/info.py
- /core/commands/kb.py
- /core/commands/learn.py
- /core/commands/other.py
- /core/commands/registry.py
- /core/commands/stats.py
- /core/commands/template.py
- /core/handlers/__init__.py
- /core/handlers/message_handler.py
- /core/workers/__init__.py
- /core/workers/indexing_worker.py
- /core/xmpp/__init__.py
- /core/xmpp/client.py
- /bots/commands/global_remove.py
- /bots/commands/help.py
- /bots/commands/info.py
- /bots/commands/kb.py
- /bots/commands/registry.py
- /bots/commands/other.py
- /bots/commands/template.py
- /bots/commands/learn.py
- /bots/commands/stats.py
- /bots/handlers/message_handler.py
- /bots/handlers/__init__.py
- /bots/workers/__init__.py
- /bots/workers/indexing_worker.py
- /bots/xmpp/__init__.py
- /bots/xmpp/client.py
- /rag/services/qdrant_service.py
- /rag/services/giga_client.py
- /rag/services/embedding_service.py
- /rag/services/reranker_service.py
- /rag/services/__init__.py
- /rag/services/file_service.py
- /rag/services/postgres_service.py
- /rag/services/kb_service.py
- /rag/functions/check_spelling.py
- /rag/functions/__init__.py
- /rag/functions/extract_metrics.py
- /rag/functions/generate_document.py
- /rag/functions/expand_query.py
- /rag/functions/critique_answer.py
- /rag/functions/file_processor.py
- /rag/functions/check_consistency.py
- /rag/functions/summarize_document.py
- /rag/functions/rerank_context.py
- /rag/functions/intent_classify.py
- /rag/utils/__init__.py
- /rag/utils/layout_converter.py
- /rag/utils/text_utils.py
- /rag/utils/arg_parser.py
- /rag/utils/config_loader.py
- /rag/utils/logger.py
- /rag/utils/web_utils.py
This commit is contained in:
Markov Andrey
2026-06-30 10:33:28 +00:00
parent ea0d42de9c
commit 63900feece
45 changed files with 0 additions and 265 deletions

132
bots/commands/template.py Normal file
View File

@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
import os
import hashlib
import shutil
import logging
from core.commands.base import Command
logger = logging.getLogger(__name__)
class TemplateSaveCommand(Command):
name = "!template_save"
aliases = ["/template_save"]
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
if not room_jid:
reply = msg.reply("⚠️ Команда !template_save работает только в комнатах.")
if reply:
reply.send()
return
if args.startswith(self.name):
args = args[len(self.name):].lstrip()
name = args.strip()
if name.startswith('"') and name.endswith('"'):
name = name[1:-1]
if not name:
reply = msg.reply("Укажите название шаблона: !template_save \"Название\"")
if reply:
reply.send()
return
key = (user_jid, room_jid) if room_jid is not None else user_jid
original_path = self.bot._last_file_path.get(key)
if not original_path or not os.path.exists(original_path):
reply = msg.reply("❌ Нет загруженного файла. Сначала отправьте DOCX-шаблон.")
if reply:
reply.send()
return
if not original_path.lower().endswith('.docx'):
reply = msg.reply("❌ Шаблон должен быть в формате .docx.")
if reply:
reply.send()
return
with open(original_path, 'rb') as f:
file_hash = hashlib.sha256(f.read()).hexdigest()
templates_dir = self.bot.config.data_dir / "templates"
templates_dir.mkdir(parents=True, exist_ok=True)
safe_room = room_jid.replace('/', '_').replace('@', '_')
dest_name = f"{safe_room}_{name}.docx"
dest_path = templates_dir / dest_name
shutil.copy2(original_path, dest_path)
await self.bot.db.save_template(room_jid, name, str(dest_path), file_hash)
reply = msg.reply(f"✅ Шаблон '{name}' сохранён.")
if reply:
reply.send()
def get_help(self) -> str:
return (
"Сохраняет текущий DOCX-файл как шаблон с указанным именем. "
"Использование: `!template_save \"Имя шаблона\"` (только в комнате)"
)
class TemplateListCommand(Command):
name = "!template_list"
aliases = ["/template_list"]
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
if not room_jid:
reply = msg.reply("⚠️ Команда !template_list работает только в комнатах.")
if reply:
reply.send()
return
if args.startswith(self.name):
args = args[len(self.name):].lstrip()
templates = await self.bot.db.list_templates(room_jid)
if not templates:
reply = msg.reply("📭 В этой комнате нет сохранённых шаблонов.")
else:
lines = ["📋 Шаблоны комнаты:"] + [f"{t}" for t in templates]
reply = msg.reply("\n".join(lines))
if reply:
reply.send()
def get_help(self) -> str:
return (
"Показывает список сохранённых шаблонов в текущей комнате. "
"Использование: `!template_list` (только в комнате)"
)
class TemplateDeleteCommand(Command):
name = "!template_delete"
aliases = ["/template_delete"]
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
if not room_jid:
reply = msg.reply("⚠️ Команда !template_delete работает только в комнатах.")
if reply:
reply.send()
return
if args.startswith(self.name):
args = args[len(self.name):].lstrip()
name = args.strip()
if name.startswith('"') and name.endswith('"'):
name = name[1:-1]
if not name:
reply = msg.reply("Укажите название шаблона: !template_delete \"Название\"")
if reply:
reply.send()
return
if await self.bot.db.delete_template(room_jid, name):
reply = msg.reply(f"🗑 Шаблон '{name}' удалён.")
else:
reply = msg.reply(f"❌ Шаблон '{name}' не найден.")
if reply:
reply.send()
def get_help(self) -> str:
return (
"Удаляет шаблон по имени. "
"Использование: `!template_delete \"Имя шаблона\"` (только в комнате)"
)