Refactor admin panel menu / fix QR code caching

This commit is contained in:
Capybara-z
2025-10-21 23:39:15 +03:00
parent 8fdd2dd3c4
commit e6313bf5a3
3 changed files with 23 additions and 23 deletions
+14 -18
View File
@@ -22,13 +22,9 @@ class AdminPanelCallback(CallbackData, prefix="admin_panel"):
async def build_panel_kb(admin_role: str) -> InlineKeyboardMarkup:
builder = InlineKeyboardBuilder()
builder.button(
text="👤 Поиск пользователя",
callback_data=AdminPanelCallback(action="search_user").pack(),
)
builder.button(
text="🔑 Поиск по подписке",
callback_data=AdminPanelCallback(action="search_key").pack(),
builder.row(
InlineKeyboardButton(text="👤 Поиск пользователя", callback_data=AdminPanelCallback(action="search_user").pack()),
InlineKeyboardButton(text="🔑 Поиск подписок", callback_data=AdminPanelCallback(action="search_key").pack()),
)
if admin_role == "superadmin":
@@ -36,6 +32,14 @@ async def build_panel_kb(admin_role: str) -> InlineKeyboardMarkup:
text="🖥️ Управление серверами",
callback_data=AdminPanelCallback(action="clusters").pack(),
)
builder.button(
text="💸Управление тарифами",
callback_data=AdminPanelCallback(action="tariffs").pack(),
)
builder.button(
text="🤖 Управление ботом",
callback_data=AdminPanelCallback(action="management").pack(),
)
builder.row(
InlineKeyboardButton(text="📢 Рассылка", callback_data=AdminPanelCallback(action="sender").pack()),
@@ -44,16 +48,8 @@ async def build_panel_kb(admin_role: str) -> InlineKeyboardMarkup:
if admin_role == "superadmin":
builder.row(
InlineKeyboardButton(text="💸 Тарифы", callback_data=AdminPanelCallback(action="tariffs").pack()),
InlineKeyboardButton(text="🎁 Подарки", callback_data=AdminPanelCallback(action="gifts").pack()),
)
builder.button(
text="🧩 Мои модули",
callback_data=AdminPanelCallback(action="modules").pack(),
)
builder.button(
text="🤖 Управление ботом",
callback_data=AdminPanelCallback(action="management").pack(),
InlineKeyboardButton(text="🧩 Мои модули", callback_data=AdminPanelCallback(action="modules").pack()),
)
builder.row(
InlineKeyboardButton(text="📊 Статистика", callback_data=AdminPanelCallback(action="stats").pack()),
@@ -74,9 +70,9 @@ async def build_panel_kb(admin_role: str) -> InlineKeyboardMarkup:
)
if admin_role == "superadmin":
builder.adjust(1, 1, 1, 1, 2, 2, 1, 1, 2, 1)
builder.adjust(2, 1, 1, 1, 2, 2, 2, 1)
else:
builder.adjust(1, 1, 1, 2, 1, 1, 1)
builder.adjust(2, 2, 1, 1)
return builder.as_markup()
+1
View File
@@ -252,6 +252,7 @@ async def show_qr_code(callback_query: types.CallbackQuery, session: AsyncSessio
text="🔲 <b>Ваш QR-код для подключения</b>",
reply_markup=builder.as_markup(),
media_path=qr_path,
disable_cache=True,
)
os.remove(qr_path)
+8 -5
View File
@@ -224,6 +224,7 @@ async def edit_or_send_message(
media_path: str = None,
disable_web_page_preview: bool = False,
force_text: bool = False,
disable_cache: bool = False,
):
if not hasattr(edit_or_send_message, "cache"):
from collections import OrderedDict
@@ -254,10 +255,12 @@ async def edit_or_send_message(
if actual_media_path:
media_type = get_media_type(actual_media_path)
async with edit_or_send_message.lock:
cached_id = edit_or_send_message.cache.get(actual_media_path)
if cached_id:
edit_or_send_message.cache.move_to_end(actual_media_path)
cached_id = None
if not disable_cache:
async with edit_or_send_message.lock:
cached_id = edit_or_send_message.cache.get(actual_media_path)
if cached_id:
edit_or_send_message.cache.move_to_end(actual_media_path)
if cached_id:
try:
@@ -307,7 +310,7 @@ async def edit_or_send_message(
elif hasattr(msg, 'animation') and msg.animation:
file_id = msg.animation.file_id
if file_id:
if file_id and not disable_cache:
async with edit_or_send_message.lock:
if actual_media_path not in edit_or_send_message.cache:
edit_or_send_message.cache[actual_media_path] = file_id