chat_moderator_bot/handlers/ban_media.py
2024-07-17 23:35:45 +03:00

66 lines
1.7 KiB
Python

from aiogram import Router, F
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery
from templates import commands as tcommands
from utils.db import Postgres, Redis
router = Router()
@router.callback_query(F.data.startswith('enable_ban_media_'))
async def enable_ban_media_btn(call: CallbackQuery, state: FSMContext):
"""
Ловит кнопку Включить
:param call: CallbackQuery
:param state: FSMContext
:return:
"""
state_data = await state.get_data()
p = Postgres()
r = Redis()
await p.update_data(
table_name='ban_media',
new_data={call.data[17:]: True},
query_filter={}
)
await r.update_dict(
key='ban_media',
value={call.data[17:]: 'yes'}
)
print('new redis data', {call.data[17:]: 'yes'})
await state_data['last_msg'].edit_text(
text=tcommands.start_text,
reply_markup=await tcommands.start_ikb()
)
@router.callback_query(F.data.startswith('disable_ban_media_'))
async def disable_ban_media_btn(call: CallbackQuery, state: FSMContext):
"""
Ловит кнопку Выключить
:param call: CallbackQuery
:param state: FSMContext
:return:
"""
state_data = await state.get_data()
p = Postgres()
r = Redis()
await p.update_data(
table_name='ban_media',
new_data={call.data[18:]: False},
query_filter={}
)
await r.update_dict(
key='ban_media',
value={call.data[18:]: ''}
)
print('new redis data', {call.data[18:]: ''})
await state_data['last_msg'].edit_text(
text=tcommands.start_text,
reply_markup=await tcommands.start_ikb()
)