formatting/3x-ui db import/cosmetic fixes
This commit is contained in:
+3
-1
@@ -1,14 +1,16 @@
|
||||
from aiohttp.web_urldispatcher import UrlDispatcher
|
||||
|
||||
import bot
|
||||
|
||||
from config import TBLOCKER_WEBHOOK_PATH
|
||||
|
||||
from .tblocker import tblocker_webhook
|
||||
from .wata_payment import wata_payment_webhook
|
||||
|
||||
|
||||
WATA_WEBHOOK_PATH = "/wata/webhook"
|
||||
|
||||
|
||||
async def register_web_routes(router: UrlDispatcher) -> None:
|
||||
router.add_post(TBLOCKER_WEBHOOK_PATH, tblocker_webhook)
|
||||
router.add_post(WATA_WEBHOOK_PATH, wata_payment_webhook)
|
||||
|
||||
|
||||
+9
-21
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from aiogram.exceptions import TelegramBadRequest, TelegramForbiddenError
|
||||
@@ -13,6 +14,7 @@ from handlers.buttons import MAIN_MENU
|
||||
from handlers.texts import TORRENT_BLOCKED_MSG, TORRENT_UNBLOCKED_MSG
|
||||
from logger import logger
|
||||
|
||||
|
||||
last_unblock_data = {}
|
||||
|
||||
|
||||
@@ -50,27 +52,19 @@ def handle_telegram_errors(func):
|
||||
|
||||
|
||||
@handle_telegram_errors
|
||||
async def send_notification(
|
||||
tg_id: int, username: str, ip: str, server: str, action: str, timestamp: str
|
||||
):
|
||||
async def send_notification(tg_id: int, username: str, ip: str, server: str, action: str, timestamp: str):
|
||||
country = get_country_from_server(server)
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
||||
|
||||
if action == "block":
|
||||
message = TORRENT_BLOCKED_MSG.format(
|
||||
username=username, country=country, duration=BLOCK_DURATION
|
||||
)
|
||||
message = TORRENT_BLOCKED_MSG.format(username=username, country=country, duration=BLOCK_DURATION)
|
||||
else:
|
||||
message = TORRENT_UNBLOCKED_MSG.format(username=username, country=country)
|
||||
|
||||
await bot.send_message(
|
||||
chat_id=tg_id, text=message, parse_mode="HTML", reply_markup=builder.as_markup()
|
||||
)
|
||||
logger.info(
|
||||
f"Отправлено уведомление пользователю {tg_id} о {action} для подписки {username}"
|
||||
)
|
||||
await bot.send_message(chat_id=tg_id, text=message, parse_mode="HTML", reply_markup=builder.as_markup())
|
||||
logger.info(f"Отправлено уведомление пользователю {tg_id} о {action} для подписки {username}")
|
||||
return True
|
||||
|
||||
|
||||
@@ -93,17 +87,13 @@ async def tblocker_webhook(request: web.Request):
|
||||
current_time = datetime.now().timestamp()
|
||||
|
||||
last_unblock_data = {
|
||||
k: v
|
||||
for k, v in last_unblock_data.items()
|
||||
if current_time - v["received_at"] <= TIMESTAMP_TTL
|
||||
k: v for k, v in last_unblock_data.items() if current_time - v["received_at"] <= TIMESTAMP_TTL
|
||||
}
|
||||
|
||||
cache_key = f"{username}:{server}"
|
||||
if action == "unblock" and cache_key in last_unblock_data:
|
||||
if timestamp == last_unblock_data[cache_key]["timestamp"]:
|
||||
return web.json_response(
|
||||
{"status": "ok", "message": "duplicate unblock skipped"}
|
||||
)
|
||||
return web.json_response({"status": "ok", "message": "duplicate unblock skipped"})
|
||||
|
||||
if action == "unblock":
|
||||
last_unblock_data[cache_key] = {
|
||||
@@ -129,9 +119,7 @@ async def tblocker_webhook(request: web.Request):
|
||||
)
|
||||
|
||||
if not success:
|
||||
logger.warning(
|
||||
f"Не удалось отправить уведомление пользователю {key_info['tg_id']}"
|
||||
)
|
||||
logger.warning(f"Не удалось отправить уведомление пользователю {key_info['tg_id']}")
|
||||
|
||||
return web.json_response({"status": "ok"})
|
||||
|
||||
|
||||
+13
-13
@@ -1,13 +1,16 @@
|
||||
import base64
|
||||
import aiohttp
|
||||
from aiohttp import web
|
||||
import json
|
||||
from database import async_session_maker, update_balance, add_payment
|
||||
from handlers.payments.utils import send_payment_success_notification
|
||||
from logger import logger
|
||||
|
||||
import aiohttp
|
||||
|
||||
from aiohttp import web
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
from database import add_payment, async_session_maker, update_balance
|
||||
from handlers.payments.utils import send_payment_success_notification
|
||||
from logger import logger
|
||||
|
||||
|
||||
PUBLIC_KEY_URL = "https://api.wata.pro/api/h2h/public-key"
|
||||
@@ -24,12 +27,7 @@ async def verify_signature(raw_json: bytes, signature: str, public_key_pem: byte
|
||||
try:
|
||||
public_key = serialization.load_pem_public_key(public_key_pem, backend=default_backend())
|
||||
signature_bytes = base64.b64decode(signature)
|
||||
public_key.verify(
|
||||
signature_bytes,
|
||||
raw_json,
|
||||
padding.PKCS1v15(),
|
||||
hashes.SHA512()
|
||||
)
|
||||
public_key.verify(signature_bytes, raw_json, padding.PKCS1v15(), hashes.SHA512())
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка проверки подписи WATA: {e}")
|
||||
@@ -50,7 +48,9 @@ async def wata_payment_webhook(request: web.Request):
|
||||
return web.Response(status=400)
|
||||
|
||||
logger.info(f"WATA webhook: {json.dumps(data, ensure_ascii=False)}")
|
||||
logger.info(f"transactionId={data.get('transactionId')}, status={data.get('transactionStatus')}, orderId={data.get('orderId')}, amount={data.get('amount')}, currency={data.get('currency')}, errorCode={data.get('errorCode')}, errorDescription={data.get('errorDescription')}")
|
||||
logger.info(
|
||||
f"transactionId={data.get('transactionId')}, status={data.get('transactionStatus')}, orderId={data.get('orderId')}, amount={data.get('amount')}, currency={data.get('currency')}, errorCode={data.get('errorCode')}, errorDescription={data.get('errorDescription')}"
|
||||
)
|
||||
if data.get("transactionStatus") == "Paid":
|
||||
tg_id = data.get("orderId")
|
||||
amount = data.get("amount")
|
||||
|
||||
Reference in New Issue
Block a user