it's version 0.8 Добавлена возможность выключения хранения логов и баз данных
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
from .DB import get_db
|
||||
from config import Config
|
||||
|
||||
_DEFAULT_GROUP = "30тс"
|
||||
|
||||
|
||||
def save_user(user_id: int, group: str = _DEFAULT_GROUP):
|
||||
if Config.DISABLE_STORAGE:
|
||||
return
|
||||
from .DB import get_db
|
||||
|
||||
def save_user(user_id: int, group: str = "30тс"):
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
cur.execute("INSERT INTO users (user_id, user_group) VALUES (?, ?)", (user_id, group))
|
||||
@@ -8,19 +15,20 @@ def save_user(user_id: int, group: str = "30тс"):
|
||||
cur.close()
|
||||
db.close()
|
||||
|
||||
def set_group(user_id: int, group: str = "30тс"):
|
||||
|
||||
def set_group(user_id: int, group: str = _DEFAULT_GROUP):
|
||||
if Config.DISABLE_STORAGE:
|
||||
return
|
||||
from .DB import get_db
|
||||
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
|
||||
# проверяем, есть ли пользователь
|
||||
cur.execute("SELECT 1 FROM users WHERE user_id = ?", (user_id,))
|
||||
exists = cur.fetchone()
|
||||
|
||||
if exists:
|
||||
# если есть — обновляем группу
|
||||
cur.execute("UPDATE users SET user_group = ? WHERE user_id = ?", (group, user_id))
|
||||
else:
|
||||
# если нет — регистрируем нового пользователя
|
||||
cur.execute("INSERT INTO users (user_id, user_group) VALUES (?, ?)", (user_id, group))
|
||||
|
||||
db.commit()
|
||||
@@ -28,7 +36,11 @@ def set_group(user_id: int, group: str = "30тс"):
|
||||
db.close()
|
||||
|
||||
|
||||
def get_group(user_id: int, default: str = "30тс") -> str:
|
||||
def get_group(user_id: int, default: str = _DEFAULT_GROUP) -> str:
|
||||
if Config.DISABLE_STORAGE:
|
||||
return default
|
||||
from .DB import get_db
|
||||
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
cur.execute("SELECT user_group FROM users WHERE user_id = ?", (user_id,))
|
||||
@@ -36,7 +48,6 @@ def get_group(user_id: int, default: str = "30тс") -> str:
|
||||
if row:
|
||||
group = row[0]
|
||||
else:
|
||||
# если пользователя нет — регистрируем с дефолтной группой
|
||||
cur.execute("INSERT INTO users (user_id, user_group) VALUES (?, ?)", (user_id, default))
|
||||
db.commit()
|
||||
group = default
|
||||
|
||||
Reference in New Issue
Block a user