From 2cf18b878af2fe59543dd2b96abeab4ba4b247a2 Mon Sep 17 00:00:00 2001 From: Alexey Polyakov Date: Thu, 19 Mar 2026 23:13:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=20=D0=B0=D0=B9=D0=B4=D0=B8,=20=D0=B7=D0=B0?= =?UTF-8?q?=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=B5=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=8F=D0=B4=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/sql_queries.py | 4 ++-- src/common/tools.py | 19 ++++++++++++++++++- src/oneme/processors.py | 6 +++--- src/telegrambot/bot.py | 3 +++ tables.sql | 6 +++--- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/common/sql_queries.py b/src/common/sql_queries.py index 4847261..7b47a03 100644 --- a/src/common/sql_queries.py +++ b/src/common/sql_queries.py @@ -6,9 +6,9 @@ class SQLQueries: INSERT_USER = """ INSERT INTO users - (phone, telegram_id, firstname, lastname, username, + (id, phone, telegram_id, firstname, lastname, username, profileoptions, options, accountstatus, updatetime, lastseen) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ INSERT_USER_DATA = """ diff --git a/src/common/tools.py b/src/common/tools.py index 35d93d6..9c2c785 100644 --- a/src/common/tools.py +++ b/src/common/tools.py @@ -1,4 +1,7 @@ -import json, time +import json +import time +import random +import hashlib class Tools: def __init__(self): @@ -284,3 +287,17 @@ class Tools: async def auth_required(self, userPhone, coro, *args): if userPhone: await coro(*args) + + def generate_user_id(self): + # Получаем время в юниксе + timestamp = int(time.time()) + + # Генерируем дополнительно рандомное число + random_number = random.randint(0, 9999) + + # Собираем их вместе и вычисляем хеш + combined = f"{timestamp}{random_number}".encode() + unique_id = int(hashlib.md5(combined).hexdigest(), 16) % 1000000000 + + # Возвращаем + return unique_id \ No newline at end of file diff --git a/src/oneme/processors.py b/src/oneme/processors.py index 5156fb3..605b465 100644 --- a/src/oneme/processors.py +++ b/src/oneme/processors.py @@ -360,12 +360,12 @@ class Processors: await cursor.execute( """ INSERT INTO users - (phone, telegram_id, firstname, lastname, username, + (id, phone, telegram_id, firstname, lastname, username, profileoptions, options, accountstatus, updatetime, lastseen) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, ( - phone, None, first_name, last_name, None, + self.tools.generate_user_id(), phone, None, first_name, last_name, None, json.dumps([]), json.dumps(["ONEME"]), 0, str(now_ms), str(now_s), ) diff --git a/src/telegrambot/bot.py b/src/telegrambot/bot.py index c89891d..b3f8118 100644 --- a/src/telegrambot/bot.py +++ b/src/telegrambot/bot.py @@ -6,10 +6,12 @@ from telebot.async_telebot import AsyncTeleBot from textwrap import dedent from common.static import Static from common.sql_queries import SQLQueries +from common.tools import Tools class TelegramBot: def __init__(self, token, enabled, db_pool, whitelist_ids=None): self.bot = AsyncTeleBot(token) + self.tools = Tools() self.enabled = enabled self.db_pool = db_pool self.whitelist_ids = whitelist_ids if whitelist_ids is not None else [] @@ -72,6 +74,7 @@ class TelegramBot: await cursor.execute( self.sql_queries.INSERT_USER, ( + self.tools.generate_user_id(), new_phone, # phone tg_id, # telegram_id message.from_user.first_name[:59], # firstname diff --git a/tables.sql b/tables.sql index ead6959..daa510f 100644 --- a/tables.sql +++ b/tables.sql @@ -1,5 +1,5 @@ CREATE TABLE `users` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, + `id` INT PRIMARY KEY, `phone` VARCHAR(20) UNIQUE, `telegram_id` VARCHAR(64) UNIQUE, `firstname` VARCHAR(59) NOT NULL, @@ -33,7 +33,7 @@ CREATE TABLE `auth_tokens` ( ); CREATE TABLE `user_data` ( - `phone` VARCHAR(20) NOT NULL UNIQUE, + `phone` VARCHAR(20) NOT NULL UNIQUE PRIMARY KEY, `chats` JSON NOT NULL, `contacts` JSON NOT NULL, `folders` JSON NOT NULL, @@ -42,7 +42,7 @@ CREATE TABLE `user_data` ( ); CREATE TABLE `chats` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, + `id` INT NOT NULL PRIMARY KEY, `owner` INT NOT NULL, `type` VARCHAR(16) NOT NULL, `participants` JSON NOT NULL