runtime settings loaded from DB/ refactoring admin-panel/ minor fixes and improvements
This commit is contained in:
+36
-17
@@ -15,6 +15,7 @@ from config import (
|
||||
SHOW_START_MENU_ONCE,
|
||||
TRIAL_TIME_DISABLE,
|
||||
)
|
||||
from core.bootstrap import BUTTONS_CONFIG, MODES_CONFIG
|
||||
from database import get_balance, get_key_count, get_trial
|
||||
from handlers.buttons import (
|
||||
ABOUT_VPN,
|
||||
@@ -68,9 +69,18 @@ async def process_callback_view_profile(
|
||||
)
|
||||
balance_rub = balance_rub or 0
|
||||
|
||||
fmt_task = asyncio.create_task(format_for_user(session, chat_id, balance_rub, getattr(user, "language_code", None)))
|
||||
profile_menu_task = asyncio.create_task(run_hooks("profile_menu", chat_id=chat_id, admin=admin, session=session))
|
||||
profile_text_task = asyncio.create_task(
|
||||
balance_text_task = asyncio.create_task(
|
||||
format_for_user(
|
||||
session,
|
||||
chat_id,
|
||||
balance_rub,
|
||||
getattr(user, "language_code", None),
|
||||
)
|
||||
)
|
||||
profile_menu_buttons_task = asyncio.create_task(
|
||||
run_hooks("profile_menu", chat_id=chat_id, admin=admin, session=session)
|
||||
)
|
||||
profile_text_hooks_task = asyncio.create_task(
|
||||
run_hooks(
|
||||
"profile_text",
|
||||
username=username,
|
||||
@@ -81,48 +91,57 @@ async def process_callback_view_profile(
|
||||
)
|
||||
)
|
||||
|
||||
balance_text = await fmt_task
|
||||
balance_text = await balance_text_task
|
||||
|
||||
profile_message = profile_message_send(username, chat_id, balance_text, key_count)
|
||||
profile_message += ADD_SUBSCRIPTION_HINT if key_count == 0 else f"\n<blockquote><i>{NEWS_MESSAGE}</i></blockquote>"
|
||||
if key_count == 0:
|
||||
profile_message += ADD_SUBSCRIPTION_HINT
|
||||
else:
|
||||
profile_message += f"\n<blockquote><i>{NEWS_MESSAGE}</i></blockquote>"
|
||||
|
||||
text_hooks = await profile_text_task
|
||||
text_hooks = await profile_text_hooks_task
|
||||
if text_hooks:
|
||||
profile_message = text_hooks[0]
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
trial_time_disabled = bool(MODES_CONFIG.get("TRIAL_TIME_DISABLED", TRIAL_TIME_DISABLE))
|
||||
|
||||
if key_count > 0:
|
||||
subs_label = MY_SUB if key_count == 1 else MY_SUBS
|
||||
builder.row(InlineKeyboardButton(text=subs_label, callback_data="view_keys"))
|
||||
elif trial_status == 0 and not TRIAL_TIME_DISABLE:
|
||||
subscriptions_button_text = MY_SUB if key_count == 1 else MY_SUBS
|
||||
builder.row(InlineKeyboardButton(text=subscriptions_button_text, callback_data="view_keys"))
|
||||
elif trial_status == 0 and not trial_time_disabled:
|
||||
builder.row(InlineKeyboardButton(text=TRIAL_SUB, callback_data="create_key"))
|
||||
else:
|
||||
builder.row(InlineKeyboardButton(text=ADD_SUB, callback_data="create_key"))
|
||||
|
||||
if BALANCE_BUTTON:
|
||||
if BUTTONS_CONFIG.get("BALANCE_BUTTON_ENABLE", BALANCE_BUTTON):
|
||||
builder.row(InlineKeyboardButton(text=BALANCE, callback_data="balance"))
|
||||
|
||||
extra_buttons = []
|
||||
if REFERRAL_BUTTON:
|
||||
if BUTTONS_CONFIG.get("REFERRAL_BUTTON_ENABLE", REFERRAL_BUTTON):
|
||||
extra_buttons.append(InlineKeyboardButton(text=INVITE, callback_data="invite"))
|
||||
if GIFT_BUTTON:
|
||||
if BUTTONS_CONFIG.get("GIFT_BUTTON_ENABLE", GIFT_BUTTON):
|
||||
extra_buttons.append(InlineKeyboardButton(text=GIFTS, callback_data="gifts"))
|
||||
if extra_buttons:
|
||||
builder.row(*extra_buttons)
|
||||
|
||||
module_buttons = await profile_menu_task
|
||||
builder = insert_hook_buttons(builder, module_buttons)
|
||||
profile_menu_buttons = await profile_menu_buttons_task
|
||||
builder = insert_hook_buttons(builder, profile_menu_buttons)
|
||||
|
||||
if INSTRUCTIONS_BUTTON:
|
||||
if BUTTONS_CONFIG.get("INSTRUCTIONS_BUTTON_ENABLE", INSTRUCTIONS_BUTTON):
|
||||
builder.row(InlineKeyboardButton(text=INSTRUCTIONS, callback_data="instructions"))
|
||||
|
||||
if admin:
|
||||
builder.row(
|
||||
InlineKeyboardButton(text="📊 Администратор", callback_data=AdminPanelCallback(action="admin").pack())
|
||||
InlineKeyboardButton(
|
||||
text="📊 Администратор",
|
||||
callback_data=AdminPanelCallback(action="admin").pack(),
|
||||
)
|
||||
)
|
||||
|
||||
if SHOW_START_MENU_ONCE:
|
||||
show_start_menu_once = bool(MODES_CONFIG.get("SHOW_START_MENU_ONLY_ONCE", SHOW_START_MENU_ONCE))
|
||||
if show_start_menu_once:
|
||||
builder.row(InlineKeyboardButton(text=ABOUT_VPN, callback_data="about_vpn"))
|
||||
else:
|
||||
builder.row(InlineKeyboardButton(text=BACK, callback_data="start"))
|
||||
|
||||
Reference in New Issue
Block a user