Генерируем айди пользователей рандомно (опять, да)

This commit is contained in:
Alexey Polyakov
2026-05-09 18:16:32 +03:00
parent ddb810589f
commit d81eec5532
5 changed files with 25 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import json
import secrets
import time
import os
import geoip2.database
@@ -562,4 +562,14 @@ class Tools:
response = reader.country(ip)
return response.country.name or "Localhost Federation"
except Exception:
return "Localhost Federation"
return "Localhost Federation"
async def generate_user_id(self, db_pool):
"""Генерация id пользователя"""
async with db_pool.acquire() as conn:
async with conn.cursor() as cursor:
while True:
user_id = secrets.randbelow(2_147_383_647) + 100_000
await cursor.execute("SELECT id FROM users WHERE id = %s", (user_id,))
if not await cursor.fetchone():
return user_id