Template
mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-08-28 16:07:43 +00:00
-Update
This commit is contained in:
@@ -6,6 +6,7 @@ from aiogram.types import Message, CallbackQuery
|
|||||||
from tgbot.keyboards.inline_main import menu_finl
|
from tgbot.keyboards.inline_main import menu_finl
|
||||||
from tgbot.keyboards.inline_misc import user_inl
|
from tgbot.keyboards.inline_misc import user_inl
|
||||||
from tgbot.keyboards.reply_misc import user_rep
|
from tgbot.keyboards.reply_misc import user_rep
|
||||||
|
from tgbot.utils.const_functions import convert_date
|
||||||
from tgbot.utils.misc.bot_models import FSM, RS
|
from tgbot.utils.misc.bot_models import FSM, RS
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ def add_userx(user_id, user_login, user_name, user_surname, user_fullname):
|
|||||||
with sqlite3.connect(PATH_DATABASE) as con:
|
with sqlite3.connect(PATH_DATABASE) as con:
|
||||||
con.row_factory = dict_factory
|
con.row_factory = dict_factory
|
||||||
con.execute("INSERT INTO storage_users "
|
con.execute("INSERT INTO storage_users "
|
||||||
"(user_id, user_login, user_name, user_surname, user_fullname, user_date, user_unix) "
|
"(user_id, user_login, user_name, user_surname, user_fullname, user_unix) "
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
[user_id, user_login, user_name, user_surname, user_fullname, get_date(), get_unix()])
|
[user_id, user_login, user_name, user_surname, user_fullname, get_unix()])
|
||||||
|
|
||||||
|
|
||||||
# Получение пользователя
|
# Получение пользователя
|
||||||
@@ -102,7 +102,7 @@ def create_dbx():
|
|||||||
con.row_factory = dict_factory
|
con.row_factory = dict_factory
|
||||||
|
|
||||||
# Таблица с хранением пользователей
|
# Таблица с хранением пользователей
|
||||||
if len(con.execute("PRAGMA table_info(storage_users)").fetchall()) == 8:
|
if len(con.execute("PRAGMA table_info(storage_users)").fetchall()) == 7:
|
||||||
print("DB was found(1/1)")
|
print("DB was found(1/1)")
|
||||||
else:
|
else:
|
||||||
con.execute("CREATE TABLE storage_users("
|
con.execute("CREATE TABLE storage_users("
|
||||||
@@ -112,7 +112,6 @@ def create_dbx():
|
|||||||
"user_name TEXT,"
|
"user_name TEXT,"
|
||||||
"user_surname TEXT,"
|
"user_surname TEXT,"
|
||||||
"user_fullname TEXT,"
|
"user_fullname TEXT,"
|
||||||
"user_date TIMESTAMP,"
|
|
||||||
"user_unix INTEGER"
|
"user_unix INTEGER"
|
||||||
")")
|
")")
|
||||||
print("DB was not found(1/1) | Creating...")
|
print("DB was not found(1/1) | Creating...")
|
||||||
|
|||||||
@@ -120,18 +120,34 @@ def split_messages(get_list: list, count: int) -> list[list]:
|
|||||||
|
|
||||||
|
|
||||||
# Получение даты
|
# Получение даты
|
||||||
def get_date() -> str:
|
def get_date(full: bool = True) -> str:
|
||||||
return datetime.now(pytz.timezone(BOT_TIMEZONE)).strftime("%d.%m.%Y %H:%M:%S")
|
if full: # Полная дата с временем
|
||||||
|
return datetime.now(pytz.timezone(BOT_TIMEZONE)).strftime("%d.%m.%Y %H:%M:%S")
|
||||||
|
else: # Только дата без времени
|
||||||
|
return datetime.now(pytz.timezone(BOT_TIMEZONE)).strftime("%d.%m.%Y")
|
||||||
|
|
||||||
|
|
||||||
# Получение юникс даты
|
# Получение unix времени
|
||||||
def get_unix(full: bool = False) -> int:
|
def get_unix(full: bool = False) -> int:
|
||||||
if full:
|
if full: # Время в наносекундах
|
||||||
return time.time_ns()
|
return time.time_ns()
|
||||||
else:
|
else: # Время в секундах
|
||||||
return int(time.time())
|
return int(time.time())
|
||||||
|
|
||||||
|
|
||||||
|
# Конвертация unix в дату и наоборот, дату в unix
|
||||||
|
def convert_date(from_time):
|
||||||
|
if str(from_time).isdigit():
|
||||||
|
to_time = datetime.fromtimestamp(from_time, pytz.timezone(BOT_TIMEZONE)).strftime("%d.%m.%Y %H:%M:%S")
|
||||||
|
else:
|
||||||
|
if " " in str(from_time):
|
||||||
|
to_time = int(datetime.strptime(from_time, "%d.%m.%Y %H:%M:%S").timestamp())
|
||||||
|
else:
|
||||||
|
to_time = int(datetime.strptime(from_time, "%d.%m.%Y").timestamp())
|
||||||
|
|
||||||
|
return to_time
|
||||||
|
|
||||||
|
|
||||||
# Генерация пароля
|
# Генерация пароля
|
||||||
def gen_password(len_password: int = 16, type_password: str = "default") -> str: # default, number, letter, onechar
|
def gen_password(len_password: int = 16, type_password: str = "default") -> str: # default, number, letter, onechar
|
||||||
if type_password == "default":
|
if type_password == "default":
|
||||||
|
|||||||
Reference in New Issue
Block a user