fix duplicate name purging,

add name addition to account creation
This commit is contained in:
Lili (Tlapka) 2022-11-03 15:58:33 +01:00
parent 6ec8a31100
commit 41d9fc4657
2 changed files with 13 additions and 5 deletions

View File

@ -102,14 +102,22 @@ def add_user_to_database(db, user_id, display_name):
""" Adds a new user to the database. Does nothing if user is already in."""
try:
cursor = db.execute(
"SELECT points FROM points WHERE id = ?",
"SELECT points, name FROM points WHERE id = ?",
(user_id,)
)
if cursor.fetchone() is None:
user = cursor.fetchone()
if user is None:
cursor.execute(
"INSERT INTO points(id, name, points) VALUES(?, ?, 10)",
(user_id, display_name)
)
if user is not None and user[1] == None:
cursor.execute(
"""UPDATE points
SET name = ?
WHERE id = ?""",
(display_name, user_id)
)
db.commit()
except Error as e:
print("Error occured adding user to db:", e.args[0])
@ -202,8 +210,8 @@ def remove_duplicate_usernames(db, user_id, username):
try:
cursor = db.execute(
"""UPDATE points
SET username = NULL
WHERE username = ? AND WHERE NOT id = ?""",
SET name = NULL
WHERE name = ? AND NOT id = ?""",
(username, user_id)
)
db.commit()

View File

@ -2,7 +2,7 @@ from flask import Flask, request, json, Blueprint, current_app
from sqlite3 import Error
from tlapbot.db import get_db
from tlapbot.owncast_helpers import (add_user_to_database, change_display_name,
user_exists, send_chat, read_users_points)
user_exists, send_chat, read_users_points, remove_duplicate_usernames)
from tlapbot.redeems_handler import handle_redeem
bp = Blueprint('owncast_webhooks', __name__)