Merge pull request #25 from machka-pasla/codex/refactor-.env-variables-for-consistency
Fix panel user sync and clarify traffic settings
This commit is contained in:
+6
-6
@@ -78,13 +78,13 @@ REFEREE_BONUS_DAYS_12_MONTHS=15
|
|||||||
PANEL_API_URL=http://your_panel_api_url/api
|
PANEL_API_URL=http://your_panel_api_url/api
|
||||||
PANEL_API_KEY=your_panel_api_key
|
PANEL_API_KEY=your_panel_api_key
|
||||||
|
|
||||||
# Default settings for NEW panel users
|
# User traffic limits (applied for all users)
|
||||||
PANEL_USER_DEFAULT_EXPIRE_DAYS=1
|
# 0 means unlimited
|
||||||
PANEL_USER_DEFAULT_TRAFFIC_BYTES=0
|
USER_TRAFFIC_LIMIT_GB=0
|
||||||
PANEL_USER_DEFAULT_TRAFFIC_STRATEGY="NO_RESET"
|
USER_TRAFFIC_STRATEGY="NO_RESET"
|
||||||
|
|
||||||
# Default Inbounds for Panel Users (Optional, comma-separated UUIDs)
|
# Default Inbounds for Users (Optional, comma-separated UUIDs)
|
||||||
PANEL_USER_DEFAULT_INBOUND_UUIDS=uuid1,uuid2,uuid3
|
USER_INBOUND_UUIDS=uuid1,uuid2,uuid3
|
||||||
|
|
||||||
# Trial Settings
|
# Trial Settings
|
||||||
TRIAL_ENABLED=True
|
TRIAL_ENABLED=True
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ This Telegram bot is designed to automate the sale and management of subscriptio
|
|||||||
* **Panel API Settings:**
|
* **Panel API Settings:**
|
||||||
* `PANEL_API_URL`: Full URL to your Remnawave panel's API (e.g., `http://remnawave:3000/api` or `https://panel.yourdomain.com/api`).
|
* `PANEL_API_URL`: Full URL to your Remnawave panel's API (e.g., `http://remnawave:3000/api` or `https://panel.yourdomain.com/api`).
|
||||||
* `PANEL_API_KEY`: API Key for authenticating with the Remnawave panel.
|
* `PANEL_API_KEY`: API Key for authenticating with the Remnawave panel.
|
||||||
* `PANEL_USER_DEFAULT_INBOUND_UUIDS`: (Optional) Comma-separated list of inbound UUIDs from your panel to assign to users. If empty, `activateAllInbounds: true` (panel default) is used for new users.
|
* `USER_INBOUND_UUIDS`: (Optional) Comma-separated list of inbound UUIDs from your panel to assign to users. If empty, `activateAllInbounds: true` (panel default) is used for new users.
|
||||||
|
* `USER_TRAFFIC_LIMIT_GB` and `USER_TRAFFIC_STRATEGY`: Default traffic limit in gigabytes (0 for unlimited) and the reset strategy applied when updating users on the panel.
|
||||||
* `TRIAL_ENABLED`, `TRIAL_DURATION_DAYS`, `TRIAL_TRAFFIC_LIMIT_GB`: Settings for the trial period.
|
* `TRIAL_ENABLED`, `TRIAL_DURATION_DAYS`, `TRIAL_TRAFFIC_LIMIT_GB`: Settings for the trial period.
|
||||||
* `WEB_SERVER_HOST`, `WEB_SERVER_PORT`: Host and port for the bot's internal webhook server.
|
* `WEB_SERVER_HOST`, `WEB_SERVER_PORT`: Host and port for the bot's internal webhook server.
|
||||||
* `LOGS_PAGE_SIZE`: For admin panel log pagination.
|
* `LOGS_PAGE_SIZE`: For admin panel log pagination.
|
||||||
|
|||||||
@@ -137,8 +137,7 @@ class ReferralService:
|
|||||||
"status_from_panel":
|
"status_from_panel":
|
||||||
"ACTIVE_BONUS",
|
"ACTIVE_BONUS",
|
||||||
"traffic_limit_bytes":
|
"traffic_limit_bytes":
|
||||||
self.settings.
|
self.settings.user_traffic_limit_bytes,
|
||||||
PANEL_USER_DEFAULT_TRAFFIC_BYTES,
|
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
await subscription_dal.deactivate_other_active_subscriptions(
|
await subscription_dal.deactivate_other_active_subscriptions(
|
||||||
|
|||||||
@@ -99,6 +99,26 @@ class SubscriptionService:
|
|||||||
logging.warning(
|
logging.warning(
|
||||||
f"Local panel_uuid {current_local_panel_uuid} for TG user {user_id} also not found on panel. User might be deleted from panel or UUID desynced."
|
f"Local panel_uuid {current_local_panel_uuid} for TG user {user_id} also not found on panel. User might be deleted from panel or UUID desynced."
|
||||||
)
|
)
|
||||||
|
logging.info(
|
||||||
|
f"Creating new panel user '{panel_username_on_panel_standard}' for TG user {user_id}."
|
||||||
|
)
|
||||||
|
creation_response = await self.panel_service.create_panel_user(
|
||||||
|
username_on_panel=panel_username_on_panel_standard,
|
||||||
|
telegram_id=user_id,
|
||||||
|
specific_inbound_uuids=self.settings.parsed_user_inbound_uuids,
|
||||||
|
default_traffic_limit_bytes=self.settings.user_traffic_limit_bytes,
|
||||||
|
default_traffic_limit_strategy=self.settings.USER_TRAFFIC_STRATEGY,
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
creation_response
|
||||||
|
and not creation_response.get("error")
|
||||||
|
and creation_response.get("response")
|
||||||
|
):
|
||||||
|
panel_user_obj_from_api = creation_response.get("response")
|
||||||
|
panel_user_created_or_linked_now = True
|
||||||
|
else:
|
||||||
|
await self._notify_admin_panel_user_creation_failed(user_id)
|
||||||
|
return None, None, None, False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@@ -108,7 +128,9 @@ class SubscriptionService:
|
|||||||
creation_response = await self.panel_service.create_panel_user(
|
creation_response = await self.panel_service.create_panel_user(
|
||||||
username_on_panel=panel_username_on_panel_standard,
|
username_on_panel=panel_username_on_panel_standard,
|
||||||
telegram_id=user_id,
|
telegram_id=user_id,
|
||||||
specific_inbound_uuids=self.settings.parsed_default_panel_user_inbound_uuids,
|
specific_inbound_uuids=self.settings.parsed_user_inbound_uuids,
|
||||||
|
default_traffic_limit_bytes=self.settings.user_traffic_limit_bytes,
|
||||||
|
default_traffic_limit_strategy=self.settings.USER_TRAFFIC_STRATEGY,
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
creation_response
|
creation_response
|
||||||
@@ -333,11 +355,11 @@ class SubscriptionService:
|
|||||||
),
|
),
|
||||||
"status": "ACTIVE",
|
"status": "ACTIVE",
|
||||||
"trafficLimitBytes": self.settings.trial_traffic_limit_bytes,
|
"trafficLimitBytes": self.settings.trial_traffic_limit_bytes,
|
||||||
"trafficLimitStrategy": self.settings.PANEL_USER_DEFAULT_TRAFFIC_STRATEGY,
|
"trafficLimitStrategy": self.settings.USER_TRAFFIC_STRATEGY,
|
||||||
}
|
}
|
||||||
if self.settings.parsed_default_panel_user_inbound_uuids:
|
if self.settings.parsed_user_inbound_uuids:
|
||||||
panel_update_payload["activeUserInbounds"] = (
|
panel_update_payload["activeUserInbounds"] = (
|
||||||
self.settings.parsed_default_panel_user_inbound_uuids
|
self.settings.parsed_user_inbound_uuids
|
||||||
)
|
)
|
||||||
elif panel_user_created_now:
|
elif panel_user_created_now:
|
||||||
panel_update_payload["activateAllInbounds"] = True
|
panel_update_payload["activateAllInbounds"] = True
|
||||||
@@ -460,7 +482,7 @@ class SubscriptionService:
|
|||||||
"duration_months": months,
|
"duration_months": months,
|
||||||
"is_active": True,
|
"is_active": True,
|
||||||
"status_from_panel": "ACTIVE",
|
"status_from_panel": "ACTIVE",
|
||||||
"traffic_limit_bytes": self.settings.PANEL_USER_DEFAULT_TRAFFIC_BYTES,
|
"traffic_limit_bytes": self.settings.user_traffic_limit_bytes,
|
||||||
"provider": provider,
|
"provider": provider,
|
||||||
"skip_notifications": provider == "tribute",
|
"skip_notifications": provider == "tribute",
|
||||||
}
|
}
|
||||||
@@ -481,12 +503,12 @@ class SubscriptionService:
|
|||||||
"+00:00", "Z"
|
"+00:00", "Z"
|
||||||
),
|
),
|
||||||
"status": "ACTIVE",
|
"status": "ACTIVE",
|
||||||
"trafficLimitBytes": self.settings.PANEL_USER_DEFAULT_TRAFFIC_BYTES,
|
"trafficLimitBytes": self.settings.user_traffic_limit_bytes,
|
||||||
"trafficLimitStrategy": self.settings.PANEL_USER_DEFAULT_TRAFFIC_STRATEGY,
|
"trafficLimitStrategy": self.settings.USER_TRAFFIC_STRATEGY,
|
||||||
}
|
}
|
||||||
if self.settings.parsed_default_panel_user_inbound_uuids:
|
if self.settings.parsed_user_inbound_uuids:
|
||||||
panel_update_payload["activeUserInbounds"] = (
|
panel_update_payload["activeUserInbounds"] = (
|
||||||
self.settings.parsed_default_panel_user_inbound_uuids
|
self.settings.parsed_user_inbound_uuids
|
||||||
)
|
)
|
||||||
elif panel_user_created_now:
|
elif panel_user_created_now:
|
||||||
panel_update_payload["activateAllInbounds"] = True
|
panel_update_payload["activateAllInbounds"] = True
|
||||||
@@ -554,7 +576,7 @@ class SubscriptionService:
|
|||||||
"duration_months": 0,
|
"duration_months": 0,
|
||||||
"is_active": True,
|
"is_active": True,
|
||||||
"status_from_panel": "ACTIVE_BONUS",
|
"status_from_panel": "ACTIVE_BONUS",
|
||||||
"traffic_limit_bytes": self.settings.PANEL_USER_DEFAULT_TRAFFIC_BYTES,
|
"traffic_limit_bytes": self.settings.user_traffic_limit_bytes,
|
||||||
}
|
}
|
||||||
await subscription_dal.deactivate_other_active_subscriptions(
|
await subscription_dal.deactivate_other_active_subscriptions(
|
||||||
session, panel_uuid, panel_sub_uuid
|
session, panel_uuid, panel_sub_uuid
|
||||||
|
|||||||
+13
-7
@@ -86,10 +86,9 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
PANEL_API_URL: Optional[str] = None
|
PANEL_API_URL: Optional[str] = None
|
||||||
PANEL_API_KEY: Optional[str] = None
|
PANEL_API_KEY: Optional[str] = None
|
||||||
PANEL_USER_DEFAULT_EXPIRE_DAYS: int = Field(default=1)
|
USER_TRAFFIC_LIMIT_GB: Optional[float] = Field(default=0.0)
|
||||||
PANEL_USER_DEFAULT_TRAFFIC_BYTES: int = Field(default=0)
|
USER_TRAFFIC_STRATEGY: str = Field(default="NO_RESET")
|
||||||
PANEL_USER_DEFAULT_TRAFFIC_STRATEGY: str = Field(default="NO_RESET")
|
USER_INBOUND_UUIDS: Optional[str] = Field(
|
||||||
PANEL_USER_DEFAULT_INBOUND_UUIDS: Optional[str] = Field(
|
|
||||||
default=None,
|
default=None,
|
||||||
description=
|
description=
|
||||||
"Comma-separated UUIDs of inbounds to activate for new panel users")
|
"Comma-separated UUIDs of inbounds to activate for new panel users")
|
||||||
@@ -139,11 +138,18 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
@property
|
@property
|
||||||
def parsed_default_panel_user_inbound_uuids(self) -> Optional[List[str]]:
|
def user_traffic_limit_bytes(self) -> int:
|
||||||
if self.PANEL_USER_DEFAULT_INBOUND_UUIDS:
|
if self.USER_TRAFFIC_LIMIT_GB is None or self.USER_TRAFFIC_LIMIT_GB <= 0:
|
||||||
|
return 0
|
||||||
|
return int(self.USER_TRAFFIC_LIMIT_GB * (1024**3))
|
||||||
|
|
||||||
|
@computed_field
|
||||||
|
@property
|
||||||
|
def parsed_user_inbound_uuids(self) -> Optional[List[str]]:
|
||||||
|
if self.USER_INBOUND_UUIDS:
|
||||||
return [
|
return [
|
||||||
uuid.strip()
|
uuid.strip()
|
||||||
for uuid in self.PANEL_USER_DEFAULT_INBOUND_UUIDS.split(',')
|
for uuid in self.USER_INBOUND_UUIDS.split(',')
|
||||||
if uuid.strip()
|
if uuid.strip()
|
||||||
]
|
]
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user