fix duplicate name purging,
add name addition to account creation
This commit is contained in:
parent
6ec8a31100
commit
41d9fc4657
|
@ -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."""
|
""" Adds a new user to the database. Does nothing if user is already in."""
|
||||||
try:
|
try:
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"SELECT points FROM points WHERE id = ?",
|
"SELECT points, name FROM points WHERE id = ?",
|
||||||
(user_id,)
|
(user_id,)
|
||||||
)
|
)
|
||||||
if cursor.fetchone() is None:
|
user = cursor.fetchone()
|
||||||
|
if user is None:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT INTO points(id, name, points) VALUES(?, ?, 10)",
|
"INSERT INTO points(id, name, points) VALUES(?, ?, 10)",
|
||||||
(user_id, display_name)
|
(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()
|
db.commit()
|
||||||
except Error as e:
|
except Error as e:
|
||||||
print("Error occured adding user to db:", e.args[0])
|
print("Error occured adding user to db:", e.args[0])
|
||||||
|
@ -202,8 +210,8 @@ def remove_duplicate_usernames(db, user_id, username):
|
||||||
try:
|
try:
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"""UPDATE points
|
"""UPDATE points
|
||||||
SET username = NULL
|
SET name = NULL
|
||||||
WHERE username = ? AND WHERE NOT id = ?""",
|
WHERE name = ? AND NOT id = ?""",
|
||||||
(username, user_id)
|
(username, user_id)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from flask import Flask, request, json, Blueprint, current_app
|
||||||
from sqlite3 import Error
|
from sqlite3 import Error
|
||||||
from tlapbot.db import get_db
|
from tlapbot.db import get_db
|
||||||
from tlapbot.owncast_helpers import (add_user_to_database, change_display_name,
|
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
|
from tlapbot.redeems_handler import handle_redeem
|
||||||
|
|
||||||
bp = Blueprint('owncast_webhooks', __name__)
|
bp = Blueprint('owncast_webhooks', __name__)
|
||||||
|
|
Loading…
Reference in New Issue