country_mode in database/ payment options
This commit is contained in:
@@ -16,6 +16,7 @@ from config import (
|
||||
REMNAWAVE_PASSWORD,
|
||||
USE_COUNTRY_SELECTION,
|
||||
)
|
||||
from core.bootstrap import MODES_CONFIG
|
||||
from database import get_servers
|
||||
from database.models import Key, Server, Tariff
|
||||
from filters.admin import IsAdminFilter
|
||||
@@ -205,7 +206,9 @@ async def handle_sync_server(
|
||||
)
|
||||
return
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
if use_country_selection:
|
||||
stmt = (
|
||||
select(
|
||||
Server.api_url,
|
||||
@@ -402,7 +405,9 @@ async def handle_sync_cluster(
|
||||
servers = await get_servers(session)
|
||||
cluster_servers = servers.get(cluster_name, [])
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
if use_country_selection:
|
||||
server_names = [s.get("server_name") for s in cluster_servers if s.get("server_name")]
|
||||
if not server_names:
|
||||
await callback_query.message.edit_text(
|
||||
@@ -474,7 +479,7 @@ async def handle_sync_cluster(
|
||||
f"обновим без лимитов"
|
||||
)
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
if use_country_selection:
|
||||
user_server = None
|
||||
for s in cluster_servers:
|
||||
if s.get("server_name") == key["server_id"]:
|
||||
@@ -573,7 +578,7 @@ async def handle_sync_cluster(
|
||||
delete(Key).where(Key.tg_id == key["tg_id"], Key.client_id == key["client_id"])
|
||||
)
|
||||
|
||||
cluster_id_for_recreate = key["server_id"] if USE_COUNTRY_SELECTION else cluster_name
|
||||
cluster_id_for_recreate = key["server_id"] if use_country_selection else cluster_name
|
||||
await create_key_on_cluster(
|
||||
cluster_id_for_recreate,
|
||||
key["tg_id"],
|
||||
@@ -594,7 +599,7 @@ async def handle_sync_cluster(
|
||||
delete(Key).where(Key.tg_id == key["tg_id"], Key.client_id == key["client_id"])
|
||||
)
|
||||
|
||||
cluster_id_for_recreate = key["server_id"] if USE_COUNTRY_SELECTION else cluster_name
|
||||
cluster_id_for_recreate = key["server_id"] if use_country_selection else cluster_name
|
||||
await create_key_on_cluster(
|
||||
cluster_id_for_recreate,
|
||||
key["tg_id"],
|
||||
|
||||
@@ -5,6 +5,7 @@ from sqlalchemy import delete, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from config import USE_COUNTRY_SELECTION
|
||||
from core.bootstrap import MODES_CONFIG
|
||||
from database.models import Key, Server
|
||||
from logger import logger
|
||||
|
||||
@@ -33,9 +34,11 @@ async def handle_server_transfer(callback_query: CallbackQuery, state: FSMContex
|
||||
|
||||
await session.commit()
|
||||
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
base_text = f"✅ Ключи успешно перенесены на сервер '{new_server_name}', сервер '{old_server_name}' удален!"
|
||||
sync_reminder = '\n\n⚠️ Не забудьте сделать "Синхронизацию".'
|
||||
final_text = base_text + (sync_reminder if USE_COUNTRY_SELECTION else "")
|
||||
final_text = base_text + (sync_reminder if use_country_selection else "")
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text=final_text,
|
||||
|
||||
@@ -2,6 +2,7 @@ from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from ..panel.keyboard import AdminPanelCallback, build_admin_back_btn
|
||||
from core.settings.money_config import get_currency_mode
|
||||
from .settings_config import (
|
||||
BUTTON_TITLES,
|
||||
MODES_TITLES,
|
||||
@@ -192,12 +193,14 @@ def build_settings_money_kb(money_state: dict[str, object]) -> InlineKeyboardMar
|
||||
).pack(),
|
||||
)
|
||||
|
||||
mode = str(money_state.get("CURRENCY_MODE") or "RUB").upper()
|
||||
if mode not in ("RUB", "USD", "RUB+USD"):
|
||||
mode = "RUB"
|
||||
mode, one_screen = get_currency_mode()
|
||||
if mode == "RUB+USD" and one_screen:
|
||||
mode_text = "RUB+USD (одним экраном)"
|
||||
else:
|
||||
mode_text = mode
|
||||
|
||||
builder.button(
|
||||
text=f"Режим валют: {mode}",
|
||||
text=f"Режим валют: {mode_text}",
|
||||
callback_data=AdminPanelCallback(
|
||||
action="settings_money_currency",
|
||||
page=0,
|
||||
@@ -214,3 +217,4 @@ def build_settings_money_kb(money_state: dict[str, object]) -> InlineKeyboardMar
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
@@ -137,19 +137,21 @@ async def open_currency_mode_menu(callback: CallbackQuery) -> None:
|
||||
money_config = MONEY_CONFIG
|
||||
mode = str(money_config.get("CURRENCY_MODE") or "RUB").upper()
|
||||
|
||||
if mode not in ("RUB", "USD", "RUB+USD"):
|
||||
if mode not in ("RUB", "USD", "RUB+USD", "RUB+USD_ONE_SCREEN"):
|
||||
mode = "RUB"
|
||||
|
||||
text = (
|
||||
"Выберите режим валют:\n\n"
|
||||
"• RUB — все цены только в рублях;\n"
|
||||
"• USD — все цены только в долларах;\n"
|
||||
"• RUB+USD — мультивалюта, оба варианта."
|
||||
"• RUB+USD — мультивалюта, выбор валюты перед оплатой;\n"
|
||||
"• RUB+USD (одним экраном) — мультивалюта, все кассы на одном экране."
|
||||
)
|
||||
|
||||
rub_checked = mode == "RUB"
|
||||
usd_checked = mode == "USD"
|
||||
multi_checked = mode == "RUB+USD"
|
||||
multi_one_screen_checked = mode == "RUB+USD_ONE_SCREEN"
|
||||
|
||||
keyboard = InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
@@ -169,6 +171,12 @@ async def open_currency_mode_menu(callback: CallbackQuery) -> None:
|
||||
callback_data=AdminPanelCallback(action="settings_money_currency_set", page=3).pack(),
|
||||
),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=("✅ RUB+USD (одним экраном)" if multi_one_screen_checked else "RUB+USD (одним экраном)"),
|
||||
callback_data=AdminPanelCallback(action="settings_money_currency_set", page=4).pack(),
|
||||
),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Назад",
|
||||
@@ -190,7 +198,7 @@ async def set_currency_mode(
|
||||
) -> None:
|
||||
mode_index = callback_data.page
|
||||
|
||||
if mode_index not in (1, 2, 3):
|
||||
if mode_index not in (1, 2, 3, 4):
|
||||
await callback.answer("Некорректный выбор", show_alert=True)
|
||||
return
|
||||
|
||||
@@ -198,8 +206,10 @@ async def set_currency_mode(
|
||||
new_mode = "RUB"
|
||||
elif mode_index == 2:
|
||||
new_mode = "USD"
|
||||
else:
|
||||
elif mode_index == 3:
|
||||
new_mode = "RUB+USD"
|
||||
else:
|
||||
new_mode = "RUB+USD_ONE_SCREEN"
|
||||
|
||||
money_config = MONEY_CONFIG.copy()
|
||||
money_config["CURRENCY_MODE"] = new_mode
|
||||
|
||||
@@ -15,6 +15,7 @@ from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from config import USE_COUNTRY_SELECTION
|
||||
from core.bootstrap import MODES_CONFIG
|
||||
from database import (
|
||||
delete_key,
|
||||
delete_user_data,
|
||||
@@ -533,7 +534,9 @@ async def confirm_admin_key_reissue(callback_query: CallbackQuery, session: Asyn
|
||||
)
|
||||
return
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
if use_country_selection:
|
||||
unique_countries = {srv["server_name"] for srv in cluster_servers}
|
||||
await state.update_data(tg_id=tg_id, email=email, cluster_id=cluster_id)
|
||||
builder = InlineKeyboardBuilder()
|
||||
@@ -809,7 +812,9 @@ async def handle_create_key_start(
|
||||
tg_id = callback_data.tg_id
|
||||
await state.update_data(tg_id=tg_id)
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
if use_country_selection:
|
||||
await state.set_state(UserEditorState.selecting_country)
|
||||
|
||||
stmt = select(Server.server_name).distinct().order_by(Server.server_name)
|
||||
@@ -935,6 +940,8 @@ async def handle_create_key_duration(callback_query: CallbackQuery, state: FSMCo
|
||||
data = await state.get_data()
|
||||
tg_id = data.get("tg_id", callback_query.from_user.id)
|
||||
|
||||
use_country_selection = bool(MODES_CONFIG.get("COUNTRY_SELECTION_ENABLED", USE_COUNTRY_SELECTION))
|
||||
|
||||
try:
|
||||
if not callback_query.data.startswith("tariff_"):
|
||||
raise ValueError("Некорректный callback_data")
|
||||
@@ -950,7 +957,7 @@ async def handle_create_key_duration(callback_query: CallbackQuery, state: FSMCo
|
||||
expiry = datetime.now(tz=timezone.utc) + timedelta(days=duration_days)
|
||||
expiry_ms = int(expiry.timestamp() * 1000)
|
||||
|
||||
if USE_COUNTRY_SELECTION and "country" in data:
|
||||
if use_country_selection and "country" in data:
|
||||
country = data["country"]
|
||||
await create_key_on_cluster(
|
||||
country,
|
||||
|
||||
Reference in New Issue
Block a user