Fix traffic notifications timing and remove async hooks from gifts/coupons
This commit is contained in:
@@ -43,7 +43,7 @@ class AdminCouponsState(StatesGroup):
|
||||
IsAdminFilter(),
|
||||
)
|
||||
async def handle_coupons(callback_query: CallbackQuery):
|
||||
await callback_query.message.edit_text(text="🛠 Меню управления купонами:", reply_markup=await build_coupons_kb())
|
||||
await callback_query.message.edit_text(text="🛠 Меню управления купонами:", reply_markup=build_coupons_kb())
|
||||
|
||||
|
||||
@router.callback_query(
|
||||
|
||||
@@ -4,8 +4,6 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from handlers.buttons import BACK
|
||||
from handlers.utils import format_days
|
||||
from hooks.hooks import run_hooks
|
||||
from hooks.hook_buttons import insert_hook_buttons
|
||||
|
||||
from ..panel.keyboard import AdminPanelCallback, build_admin_back_btn
|
||||
|
||||
@@ -15,7 +13,7 @@ class AdminCouponDeleteCallback(CallbackData, prefix="admin_coupon_delete"):
|
||||
confirm: bool | None = None
|
||||
|
||||
|
||||
async def build_coupons_kb() -> InlineKeyboardMarkup:
|
||||
def build_coupons_kb() -> InlineKeyboardMarkup:
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
@@ -32,9 +30,6 @@ async def build_coupons_kb() -> InlineKeyboardMarkup:
|
||||
)
|
||||
builder.row(build_admin_back_btn())
|
||||
|
||||
module_buttons = await run_hooks("admin_coupons_keyboard")
|
||||
builder = insert_hook_buttons(builder, module_buttons)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class GiftCreationState(StatesGroup):
|
||||
@router.callback_query(AdminPanelCallback.filter(F.action == "gifts"))
|
||||
async def admin_gift_menu(callback: CallbackQuery):
|
||||
await callback.message.edit_text(
|
||||
text="🎁 <b>Подарки</b>\nВыберите, что хотите сделать:", reply_markup=await build_admin_gifts_kb()
|
||||
text="🎁 <b>Подарки</b>\nВыберите, что хотите сделать:", reply_markup=build_admin_gifts_kb()
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,11 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from database.models import Gift, Tariff
|
||||
from handlers.buttons import BACK
|
||||
from handlers.utils import format_days, format_months
|
||||
from hooks.hooks import run_hooks
|
||||
from hooks.hook_buttons import insert_hook_buttons
|
||||
|
||||
from ..panel.keyboard import AdminPanelCallback
|
||||
|
||||
|
||||
async def build_admin_gifts_kb() -> InlineKeyboardMarkup:
|
||||
def build_admin_gifts_kb() -> InlineKeyboardMarkup:
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(InlineKeyboardButton(text="🎁 Создать подарок", callback_data="admin_gift_create"))
|
||||
@@ -19,9 +17,6 @@ async def build_admin_gifts_kb() -> InlineKeyboardMarkup:
|
||||
)
|
||||
builder.row(InlineKeyboardButton(text=BACK, callback_data="admin"))
|
||||
|
||||
module_buttons = await run_hooks("admin_gifts_keyboard")
|
||||
builder = insert_hook_buttons(builder, module_buttons)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
|
||||
@@ -141,12 +141,6 @@ async def notify_users_no_traffic(bot: Bot, session: AsyncSession, current_time:
|
||||
value if isinstance(value, int | float) else 0 for value in traffic_data.get("traffic", {}).values()
|
||||
)
|
||||
|
||||
try:
|
||||
await update_key_notified(session, tg_id, client_id)
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка обновления notified для {tg_id} ({client_id}): {e}")
|
||||
continue
|
||||
|
||||
if total_traffic == 0:
|
||||
logger.info(f"⚠ У пользователя {tg_id} ({email}) 0 ГБ трафика. Отправляем уведомление.")
|
||||
builder = InlineKeyboardBuilder()
|
||||
@@ -182,6 +176,11 @@ async def notify_users_no_traffic(bot: Bot, session: AsyncSession, current_time:
|
||||
"client_id": client_id,
|
||||
})
|
||||
|
||||
try:
|
||||
await update_key_notified(session, tg_id, client_id)
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка обновления notified для {tg_id} ({client_id}): {e}")
|
||||
|
||||
if messages:
|
||||
results = await send_messages_with_limit(
|
||||
bot,
|
||||
|
||||
Reference in New Issue
Block a user