bot works as echo (adding templates s functional)

tpl_list dont
This commit is contained in:
2025-08-19 05:13:16 +09:00
parent a8d860ed87
commit 18a92ca526
7 changed files with 274 additions and 47 deletions

View File

@@ -29,7 +29,7 @@ DEFAULT_TTL = 3600 # 1 час
# Настройка логирования
logger = logging.getLogger(__name__)
async def main():
async def run_bot():
"""Запуск бота."""
app = Application.builder().token(settings.editor_bot_token).build()
@@ -39,23 +39,17 @@ async def main():
# Запуск бота
await app.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
import asyncio
def main():
"""Основная функция запуска."""
try:
asyncio.run(main())
asyncio.run(run_bot())
except KeyboardInterrupt:
logger.info("Бот остановлен")
except Exception as e:
logger.error(f"Ошибка: {e}", exc_info=True)
finally:
# Убедимся, что все циклы закрыты
loop = asyncio.get_event_loop()
if loop.is_running():
loop.stop()
if not loop.is_closed():
loop.close()
except Exception as e:
logger.error(f"Ошибка: {e}", exc_info=True)
if __name__ == "__main__":
main()
from app.core.config import settings
from .editor.session import SessionStore
@@ -67,12 +61,7 @@ from .editor.handlers.templates import (
handle_template_keyboard,
list_templates
)
from .editor.handlers.posts import (
newpost,
handle_post_template,
handle_post_channel,
handle_post_schedule
)
from .editor.handlers.posts import newpost
from .editor.states import BotStates
# Настройка логирования
@@ -624,7 +613,7 @@ async def tpl_new_content(update: Update, context: Context) -> int:
"title": session.template_name,
"content": content,
"type": session.type,
"owner_id": user.id,
"tg_user_id": user.id, # Передаем telegram user id вместо owner_id
"parse_mode": session.parse_mode,
"keyboard_tpl": session.keyboard
}
@@ -633,8 +622,9 @@ async def tpl_new_content(update: Update, context: Context) -> int:
await create_template(template_data)
await message.reply_text("Шаблон успешно сохранен")
return ConversationHandler.END
except ValueError as e:
await message.reply_text(f"Ошибка создания шаблона: {e}")
except Exception as e:
logger.error(f"Ошибка создания шаблона: {e}", exc_info=True)
await message.reply_text(f"Ошибка создания шаблона. Пожалуйста, попробуйте позже.")
return BotStates.TPL_NEW_CONTENT
async def list_user_templates(update: Update, context: Context) -> None: