Генерируем айди, за вместо того, чтобы писать его попорядку
This commit is contained in:
parent
bbee49d2d8
commit
2cf18b878a
|
|
@ -6,9 +6,9 @@ class SQLQueries:
|
||||||
|
|
||||||
INSERT_USER = """
|
INSERT_USER = """
|
||||||
INSERT INTO users
|
INSERT INTO users
|
||||||
(phone, telegram_id, firstname, lastname, username,
|
(id, phone, telegram_id, firstname, lastname, username,
|
||||||
profileoptions, options, accountstatus, updatetime, lastseen)
|
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 = """
|
INSERT_USER_DATA = """
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
import json, time
|
import json
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import hashlib
|
||||||
|
|
||||||
class Tools:
|
class Tools:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -284,3 +287,17 @@ class Tools:
|
||||||
async def auth_required(self, userPhone, coro, *args):
|
async def auth_required(self, userPhone, coro, *args):
|
||||||
if userPhone:
|
if userPhone:
|
||||||
await coro(*args)
|
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
|
||||||
|
|
@ -360,12 +360,12 @@ class Processors:
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO users
|
INSERT INTO users
|
||||||
(phone, telegram_id, firstname, lastname, username,
|
(id, phone, telegram_id, firstname, lastname, username,
|
||||||
profileoptions, options, accountstatus, updatetime, lastseen)
|
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"]),
|
json.dumps([]), json.dumps(["ONEME"]),
|
||||||
0, str(now_ms), str(now_s),
|
0, str(now_ms), str(now_s),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@ from telebot.async_telebot import AsyncTeleBot
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from common.static import Static
|
from common.static import Static
|
||||||
from common.sql_queries import SQLQueries
|
from common.sql_queries import SQLQueries
|
||||||
|
from common.tools import Tools
|
||||||
|
|
||||||
class TelegramBot:
|
class TelegramBot:
|
||||||
def __init__(self, token, enabled, db_pool, whitelist_ids=None):
|
def __init__(self, token, enabled, db_pool, whitelist_ids=None):
|
||||||
self.bot = AsyncTeleBot(token)
|
self.bot = AsyncTeleBot(token)
|
||||||
|
self.tools = Tools()
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.db_pool = db_pool
|
self.db_pool = db_pool
|
||||||
self.whitelist_ids = whitelist_ids if whitelist_ids is not None else []
|
self.whitelist_ids = whitelist_ids if whitelist_ids is not None else []
|
||||||
|
|
@ -72,6 +74,7 @@ class TelegramBot:
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
self.sql_queries.INSERT_USER,
|
self.sql_queries.INSERT_USER,
|
||||||
(
|
(
|
||||||
|
self.tools.generate_user_id(),
|
||||||
new_phone, # phone
|
new_phone, # phone
|
||||||
tg_id, # telegram_id
|
tg_id, # telegram_id
|
||||||
message.from_user.first_name[:59], # firstname
|
message.from_user.first_name[:59], # firstname
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
CREATE TABLE `users` (
|
CREATE TABLE `users` (
|
||||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
`id` INT PRIMARY KEY,
|
||||||
`phone` VARCHAR(20) UNIQUE,
|
`phone` VARCHAR(20) UNIQUE,
|
||||||
`telegram_id` VARCHAR(64) UNIQUE,
|
`telegram_id` VARCHAR(64) UNIQUE,
|
||||||
`firstname` VARCHAR(59) NOT NULL,
|
`firstname` VARCHAR(59) NOT NULL,
|
||||||
|
|
@ -33,7 +33,7 @@ CREATE TABLE `auth_tokens` (
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE `user_data` (
|
CREATE TABLE `user_data` (
|
||||||
`phone` VARCHAR(20) NOT NULL UNIQUE,
|
`phone` VARCHAR(20) NOT NULL UNIQUE PRIMARY KEY,
|
||||||
`chats` JSON NOT NULL,
|
`chats` JSON NOT NULL,
|
||||||
`contacts` JSON NOT NULL,
|
`contacts` JSON NOT NULL,
|
||||||
`folders` JSON NOT NULL,
|
`folders` JSON NOT NULL,
|
||||||
|
|
@ -42,7 +42,7 @@ CREATE TABLE `user_data` (
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE `chats` (
|
CREATE TABLE `chats` (
|
||||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
`id` INT NOT NULL PRIMARY KEY,
|
||||||
`owner` INT NOT NULL,
|
`owner` INT NOT NULL,
|
||||||
`type` VARCHAR(16) NOT NULL,
|
`type` VARCHAR(16) NOT NULL,
|
||||||
`participants` JSON NOT NULL
|
`participants` JSON NOT NULL
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue