Update InlineKeyboardBuilder

This commit is contained in:
Zakhar Izmaylov
2024-11-24 01:57:42 +03:00
parent a672a0ddb0
commit 53dc006f2d
+31 -48
View File
@@ -2,6 +2,7 @@ import asyncio
from datetime import datetime, timedelta from datetime import datetime, timedelta
from aiogram import Bot, Router, types from aiogram import Bot, Router, types
from aiogram.utils.keyboard import InlineKeyboardBuilder
import asyncpg import asyncpg
from py3xui import AsyncApi from py3xui import AsyncApi
@@ -97,28 +98,12 @@ async def notify_10h_keys(
if not await is_bot_blocked(bot, tg_id): if not await is_bot_blocked(bot, tg_id):
try: try:
keyboard = types.InlineKeyboardMarkup( keyboard = types.InlineKeyboardBuilder()
inline_keyboard=[ keyboard.button(text="🔄 Продлить VPN", callback_data=f'renew_key|{record["client_id"]}')
[ keyboard.button(text="💳 Пополнить баланс", callback_data="pay")
types.InlineKeyboardButton( keyboard.button(text="👤 Личный кабинет", callback_data="profile")
text="🔄 Продлить VPN", keyboard.adjust(1)
callback_data=f'renew_key|{record["client_id"]}', keyboard = keyboard.as_markup()
)
],
[
types.InlineKeyboardButton(
text="💳 Пополнить баланс",
callback_data="pay",
)
],
[
types.InlineKeyboardButton(
text="👤 Личный кабинет",
callback_data="profile",
)
],
]
)
await bot.send_message(tg_id, message, reply_markup=keyboard) await bot.send_message(tg_id, message, reply_markup=keyboard)
logger.info(f"Уведомление отправлено пользователю {tg_id}.") logger.info(f"Уведомление отправлено пользователю {tg_id}.")
except Exception as e: except Exception as e:
@@ -177,28 +162,26 @@ async def notify_24h_keys(
if not await is_bot_blocked(bot, tg_id): if not await is_bot_blocked(bot, tg_id):
try: try:
keyboard = types.InlineKeyboardMarkup( builder = InlineKeyboardBuilder()
inline_keyboard=[ builder.row(
[ types.InlineKeyboardButton(
types.InlineKeyboardButton( text="🔄 Продлить VPN",
text="🔄 Продлить VPN", callback_data=f'renew_key|{record["client_id"]}',
callback_data=f'renew_key|{record["client_id"]}', )
)
],
[
types.InlineKeyboardButton(
text="💳 Пополнить баланс",
callback_data="pay",
)
],
[
types.InlineKeyboardButton(
text="👤 Личный кабинет",
callback_data="profile",
)
],
]
) )
builder.row(
types.InlineKeyboardButton(
text="💳 Пополнить баланс",
callback_data="pay",
)
)
builder.row(
types.InlineKeyboardButton(
text="👤 Личный кабинет",
callback_data="profile",
)
)
keyboard = builder.as_markup()
await bot.send_message(tg_id, message_24h, reply_markup=keyboard) await bot.send_message(tg_id, message_24h, reply_markup=keyboard)
logger.info(f"Уведомление за 24 часа отправлено пользователю {tg_id}.") logger.info(f"Уведомление за 24 часа отправлено пользователю {tg_id}.")
except Exception as e: except Exception as e:
@@ -236,12 +219,12 @@ async def notify_inactive_trial_users(bot: Bot, conn: asyncpg.Connection):
try: try:
if not await is_bot_blocked(bot, tg_id): if not await is_bot_blocked(bot, tg_id):
keyboard = types.InlineKeyboardMarkup( builder = InlineKeyboardBuilder()
inline_keyboard=[ builder.row(
[types.InlineKeyboardButton(text="🚀 Активировать пробный период", callback_data="create_key")], types.InlineKeyboardButton(text="🚀 Активировать пробный период", callback_data="create_key")
[types.InlineKeyboardButton(text="👤 Личный кабинет", callback_data="profile")],
]
) )
builder.row(types.InlineKeyboardButton(text="👤 Личный кабинет", callback_data="profile"))
keyboard = builder.as_markup()
message = ( message = (
f"👋 Привет, {username}!\n\n" f"👋 Привет, {username}!\n\n"