mirror of
https://github.com/openmax-server/server.git
synced 2026-05-22 19:41:41 +03:00
Генерируем айди пользователей рандомно (опять, да)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user