Редактировать create.py
This commit is contained in:
60
bots/commands/create.py
Normal file
60
bots/commands/create.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from core.commands.base import Command
|
||||
from core.functions.generate_document import generate_document_from_template
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateCommand(Command):
|
||||
name = "!create"
|
||||
aliases = ["/create"]
|
||||
|
||||
async def execute(self, msg, args: str, user_jid: str, room_jid: str = None):
|
||||
if not room_jid:
|
||||
reply = msg.reply("⚠️ Команда !create работает только в комнатах.")
|
||||
if reply:
|
||||
reply.send()
|
||||
return
|
||||
|
||||
clean_args = args.strip()
|
||||
if clean_args.startswith(self.name):
|
||||
clean_args = clean_args[len(self.name):].lstrip()
|
||||
name = clean_args.strip()
|
||||
if name.startswith('"') and name.endswith('"'):
|
||||
name = name[1:-1]
|
||||
|
||||
if not name:
|
||||
reply = msg.reply("Укажите название шаблона: !create \"Название\"")
|
||||
if reply:
|
||||
reply.send()
|
||||
return
|
||||
|
||||
template_info = await self.bot.db.get_template(room_jid, name)
|
||||
if not template_info:
|
||||
reply = msg.reply(f"❌ Шаблон '{name}' не найден.")
|
||||
if reply:
|
||||
reply.send()
|
||||
return
|
||||
|
||||
reply = msg.reply("🔄 Начинаю генерацию документа. Это может занять несколько минут. Я сообщу, когда будет готово.")
|
||||
if reply:
|
||||
reply.send()
|
||||
|
||||
asyncio.create_task(
|
||||
generate_document_from_template(
|
||||
bot=self.bot,
|
||||
msg=msg,
|
||||
room_jid=room_jid,
|
||||
template_path=template_info['file_path'],
|
||||
template_name=name,
|
||||
user_jid=user_jid
|
||||
)
|
||||
)
|
||||
|
||||
def get_help(self) -> str:
|
||||
return (
|
||||
"Генерирует документ по шаблону из базы знаний. "
|
||||
"Использование: `!create \"Название шаблона\"` (только в комнате)"
|
||||
)
|
||||
Reference in New Issue
Block a user