add: android tv connection for remnawave
This commit is contained in:
@@ -611,9 +611,9 @@ async def handle_sync_cluster(
|
|||||||
traffic_limit_bytes = int(tariff.traffic_limit * 1024**3)
|
traffic_limit_bytes = int(tariff.traffic_limit * 1024**3)
|
||||||
hwid_limit = tariff.device_limit
|
hwid_limit = tariff.device_limit
|
||||||
else:
|
else:
|
||||||
logger.warning(f"[Sync] Ключ {key['client_id']} с несуществующим тарифом ID={key['tariff_id']} — обновим без лимитов")
|
logger.warning(
|
||||||
|
f"[Sync] Ключ {key['client_id']} с несуществующим тарифом ID={key['tariff_id']} — обновим без лимитов"
|
||||||
valid_email = f"{key['email']}@fake.local"
|
)
|
||||||
|
|
||||||
inbound_ids = [
|
inbound_ids = [
|
||||||
s["inbound_id"]
|
s["inbound_id"]
|
||||||
@@ -621,16 +621,41 @@ async def handle_sync_cluster(
|
|||||||
if s.get("inbound_id")
|
if s.get("inbound_id")
|
||||||
]
|
]
|
||||||
|
|
||||||
await remna.update_user(
|
success = await remna.update_user(
|
||||||
uuid=key["client_id"],
|
uuid=key["client_id"],
|
||||||
expire_at=expire_iso,
|
expire_at=expire_iso,
|
||||||
telegram_id=key["tg_id"],
|
telegram_id=key["tg_id"],
|
||||||
email=valid_email,
|
email=f"{key['email']}@fake.local",
|
||||||
active_user_inbounds=inbound_ids,
|
active_user_inbounds=inbound_ids,
|
||||||
traffic_limit_bytes=traffic_limit_bytes,
|
traffic_limit_bytes=traffic_limit_bytes,
|
||||||
hwid_device_limit=hwid_limit,
|
hwid_device_limit=hwid_limit,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
logger.warning(f"[Sync] ошибка обновления, пробуем пересоздать")
|
||||||
|
|
||||||
|
await delete_key_from_cluster(
|
||||||
|
cluster_name, key["email"], key["client_id"], session
|
||||||
|
)
|
||||||
|
|
||||||
|
await session.execute(
|
||||||
|
delete(Key).where(
|
||||||
|
Key.tg_id == key["tg_id"],
|
||||||
|
Key.client_id == key["client_id"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await create_key_on_cluster(
|
||||||
|
cluster_name,
|
||||||
|
key["tg_id"],
|
||||||
|
key["client_id"],
|
||||||
|
key["email"],
|
||||||
|
key["expiry_time"],
|
||||||
|
plan=key["tariff_id"],
|
||||||
|
session=session,
|
||||||
|
remnawave_link=key["remnawave_link"],
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
await delete_key_from_cluster(
|
await delete_key_from_cluster(
|
||||||
cluster_name, key["email"], key["client_id"], session
|
cluster_name, key["email"], key["client_id"], session
|
||||||
|
|||||||
@@ -144,12 +144,19 @@ async def process_macos_menu(callback_query: CallbackQuery, session: Any):
|
|||||||
|
|
||||||
|
|
||||||
@router.callback_query(F.data.startswith("connect_tv|"))
|
@router.callback_query(F.data.startswith("connect_tv|"))
|
||||||
async def process_connect_tv(callback_query: CallbackQuery):
|
async def process_connect_tv(callback_query: CallbackQuery, session: Any):
|
||||||
key_name = callback_query.data.split("|")[1]
|
data = callback_query.data.split("|")
|
||||||
|
key_name = data[1]
|
||||||
|
callback_data = callback_query.data
|
||||||
|
|
||||||
|
if key_name == "direct" and len(data) > 2:
|
||||||
|
callback_data = f"continue_tv|{key_name}|{data[2]}"
|
||||||
|
else:
|
||||||
|
callback_data = callback_data.replace("connect_tv", "continue_tv")
|
||||||
|
|
||||||
builder = InlineKeyboardBuilder()
|
builder = InlineKeyboardBuilder()
|
||||||
builder.row(
|
builder.row(
|
||||||
InlineKeyboardButton(text=TV_CONTINUE, callback_data=f"continue_tv|{key_name}")
|
InlineKeyboardButton(text=TV_CONTINUE, callback_data=callback_data)
|
||||||
)
|
)
|
||||||
builder.row(InlineKeyboardButton(text=BACK, callback_data=f"view_key|{key_name}"))
|
builder.row(InlineKeyboardButton(text=BACK, callback_data=f"view_key|{key_name}"))
|
||||||
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
||||||
@@ -165,19 +172,20 @@ async def process_connect_tv(callback_query: CallbackQuery):
|
|||||||
|
|
||||||
@router.callback_query(F.data.startswith("continue_tv|"))
|
@router.callback_query(F.data.startswith("continue_tv|"))
|
||||||
async def process_continue_tv(callback_query: CallbackQuery, session: Any):
|
async def process_continue_tv(callback_query: CallbackQuery, session: Any):
|
||||||
key_name = callback_query.data.split("|")[1]
|
data = callback_query.data.split("|")
|
||||||
|
key_name = data[1]
|
||||||
|
subscription_link = None
|
||||||
|
|
||||||
|
if key_name == "direct" and len(data) > 2:
|
||||||
|
subscription_link = data[2]
|
||||||
|
else:
|
||||||
|
record = await get_key_details(session, key_name)
|
||||||
|
subscription_link = record["key"]
|
||||||
|
|
||||||
record = await get_key_details(session, key_name)
|
|
||||||
subscription_link = record["key"]
|
|
||||||
message_text = SUBSCRIPTION_DETAILS_TEXT.format(subscription_link=subscription_link)
|
message_text = SUBSCRIPTION_DETAILS_TEXT.format(subscription_link=subscription_link)
|
||||||
|
|
||||||
builder = InlineKeyboardBuilder()
|
builder = InlineKeyboardBuilder()
|
||||||
builder.row(
|
builder.row(InlineKeyboardButton(text=BACK, callback_data=f"connect_tv|{key_name}|{subscription_link}" if subscription_link else f"connect_tv|{key_name}"))
|
||||||
InlineKeyboardButton(
|
|
||||||
text=TV_INSTRUCTIONS, url="https://vpn4tv.com/quick-guide.html"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
builder.row(InlineKeyboardButton(text=BACK, callback_data=f"connect_tv|{key_name}"))
|
|
||||||
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
||||||
|
|
||||||
await edit_or_send_message(
|
await edit_or_send_message(
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ async def key_cluster_mode(
|
|||||||
text=CONNECT_DEVICE, web_app=WebAppInfo(url=final_link)
|
text=CONNECT_DEVICE, web_app=WebAppInfo(url=final_link)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
builder.row(
|
||||||
|
InlineKeyboardButton(text=TV_BUTTON, callback_data=f"connect_tv|direct|{final_link}")
|
||||||
|
)
|
||||||
elif CONNECT_PHONE_BUTTON:
|
elif CONNECT_PHONE_BUTTON:
|
||||||
builder.row(
|
builder.row(
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
|
|||||||
@@ -528,6 +528,9 @@ async def finalize_key_creation(
|
|||||||
web_app=WebAppInfo(url=public_link or remnawave_link),
|
web_app=WebAppInfo(url=public_link or remnawave_link),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
builder.row(
|
||||||
|
InlineKeyboardButton(text=TV_BUTTON, callback_data=f"connect_tv|direct|{public_link or remnawave_link}")
|
||||||
|
)
|
||||||
elif CONNECT_PHONE_BUTTON:
|
elif CONNECT_PHONE_BUTTON:
|
||||||
builder.row(
|
builder.row(
|
||||||
InlineKeyboardButton(text=CONNECT_PHONE, callback_data=f"connect_phone|{key_name}")
|
InlineKeyboardButton(text=CONNECT_PHONE, callback_data=f"connect_phone|{key_name}")
|
||||||
|
|||||||
@@ -326,6 +326,9 @@ async def render_key_info(
|
|||||||
text=CONNECT_DEVICE, web_app=WebAppInfo(url=final_link)
|
text=CONNECT_DEVICE, web_app=WebAppInfo(url=final_link)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
builder.row(
|
||||||
|
InlineKeyboardButton(text=TV_BUTTON, callback_data=f"connect_tv|direct|{final_link}")
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if CONNECT_PHONE_BUTTON:
|
if CONNECT_PHONE_BUTTON:
|
||||||
builder.row(
|
builder.row(
|
||||||
|
|||||||
Reference in New Issue
Block a user