71 lines
2.7 KiB
Plaintext
71 lines
2.7 KiB
Plaintext
from telegram import Update
|
||
from telegram.ext import CallbackQueryHandler, CallbackContext
|
||
from utils.logger import logger
|
||
from handlers.user_handlers import names_menu, user_start
|
||
from utils.database import save_database, USER_DATA
|
||
from handlers.database_handlers import show_names, clear_names
|
||
from utils.message_sender import send_message
|
||
from utils.user_data import get_user_info
|
||
from handlers.admin_handlers import notify_admins
|
||
|
||
|
||
async def handle_admin_buttons(update: Update, context: CallbackContext) -> None: #handlers/callback_handlers.py
|
||
query = update.callback_query
|
||
query.answer()
|
||
del context.user_data['type']
|
||
if query.data == 'admin_action1':
|
||
bot.send_message(chat_id=query.message.chat_id, text="Выполнено админ действие 1")
|
||
elif query.data == 'admin_action2':
|
||
bot.send_message(chat_id=query.message.chat_id, text="Выполнено админ действие 2")
|
||
|
||
async def handle_user_buttons(update: Update, context: CallbackContext) -> None: #handlers/callback_handlers.py
|
||
global USER_DATA
|
||
if
|
||
del context.user_data['type']
|
||
query = update.callback_query
|
||
await query.answer()
|
||
|
||
if query.data == "user_life":
|
||
context.user_data['type'] = "О здравии"
|
||
elif query.data == "user_dead":
|
||
context.user_data['type'] = "За упокой"
|
||
elif query.data == "user_comment":
|
||
context.user_data['type'] = "Комментарий"
|
||
elif query.data == "user_show":
|
||
await show_names(update, context)
|
||
return
|
||
elif query.data == "user_send":
|
||
try:
|
||
save_database(USER_DATA)
|
||
except:
|
||
logger.error("Ошибка сохранения в файл json: {e}")
|
||
return
|
||
user_info = await get_user_info(update, context)
|
||
# admin_notify(udate, context,)
|
||
await notify_admins(update, context, user_info["name"])
|
||
#Отправляем сообщение админам
|
||
return
|
||
elif query.data == "user_clear":
|
||
try:
|
||
del context.user_data['type']
|
||
except:
|
||
pass
|
||
await clear_names(update, context)
|
||
await user_start(update, context)
|
||
return
|
||
elif query.data == "user_clear_type":
|
||
await clear_names(update, context)
|
||
await names_menu(update, context)
|
||
return
|
||
# Переходим в меню имен только если выбран корректный тип
|
||
if context.user_data.get('type'):
|
||
await names_menu(update, context)
|
||
else:
|
||
await send_message(update, context,"Неверный запрос")
|
||
|
||
|
||
def register_handlers(app):
|
||
app.add_handler(CallbackQueryHandler(handle_user_buttons, pattern='^user_'))
|
||
app.add_handler(CallbackQueryHandler(handle_admin_buttons, pattern='^admin_'))
|
||
# app.add_handler(CallbackQueryHandler(handle_confirm_buttons, pattern='^confirm_'))
|