It's version 0.6.1 I fixed the set command before, if the user didn't exist, it wouldn't record him.
This commit is contained in:
@@ -11,11 +11,23 @@ def save_user(user_id: int, group: str = "30тс"):
|
||||
def set_group(user_id: int, group: str = "30тс"):
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
cur.execute("UPDATE users SET user_group = ? WHERE user_id = ?", (group, user_id))
|
||||
|
||||
# проверяем, есть ли пользователь
|
||||
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()
|
||||
cur.close()
|
||||
db.close()
|
||||
|
||||
|
||||
def get_group(user_id: int, default: str = "30тс") -> str:
|
||||
db = get_db()
|
||||
cur = db.cursor()
|
||||
|
||||
Reference in New Issue
Block a user