2026-03-02 10:16:30 +01:00
|
|
|
import sqlite3
|
|
|
|
|
import random
|
|
|
|
|
from data.setup_database import DB_PATH
|
|
|
|
|
|
|
|
|
|
def change_display_name(player_id, new_name):
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
cursor.execute("UPDATE players SET display_name = ? WHERE id = ?", (new_name, player_id))
|
|
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_or_create_player(discord_id, discord_name, avatar_url):
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
# REPARIERT: Wir fragen 4 Dinge ab (id, discord_name, display_name, discord_avatar_url)
|
|
|
|
|
cursor.execute("SELECT id, discord_name, display_name, discord_avatar_url FROM players WHERE discord_id = ?", (discord_id,))
|
|
|
|
|
player = cursor.fetchone()
|
|
|
|
|
|
|
|
|
|
if player is None:
|
|
|
|
|
|
|
|
|
|
# Random Silly Name Generator für neue Spieler. Damit sie angeregt werden ihren richtigen Namen einzutragen.
|
|
|
|
|
def generate_silly_name():
|
|
|
|
|
adjectives = ["Verwirrter", "Blinder", "Heulender", "Zorniger", "Chaos", "Verzweifelter", "Schreiender", "Stolpernder", "Schwitzender"]
|
|
|
|
|
nouns = ["Grot", "Kultist", "Servitor", "Snotling", "Guardmen", "Würfellecker", "Regelvergesser", "Meta-Chaser", "Klebschnüffler"]
|
|
|
|
|
adj = random.choice(adjectives)
|
|
|
|
|
noun = random.choice(nouns)
|
|
|
|
|
return f"{adj} {noun}"
|
|
|
|
|
|
|
|
|
|
silly_name = generate_silly_name()
|
|
|
|
|
cursor.execute("INSERT INTO players (discord_id, discord_name, display_name, discord_avatar_url) VALUES (?, ?, ?, ?)", (discord_id, discord_name, silly_name, avatar_url))
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
cursor.execute("SELECT id, discord_name, display_name, discord_avatar_url FROM players WHERE discord_id = ?", (discord_id,))
|
|
|
|
|
player = cursor.fetchone()
|
|
|
|
|
else:
|
|
|
|
|
# Falls sich Name oder Bild auf Discord geändert haben, machen wir ein Update
|
|
|
|
|
cursor.execute("UPDATE players SET discord_name = ?, discord_avatar_url = ? WHERE discord_id = ?", (discord_name, avatar_url, discord_id))
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
cursor.execute("SELECT id, discord_name, display_name, discord_avatar_url FROM players WHERE discord_id = ?", (discord_id,))
|
|
|
|
|
player = cursor.fetchone()
|
|
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
|
return player
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_players():
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
# Alle Spieler laden, absteigend sortiert nach MMR
|
|
|
|
|
cursor.execute("SELECT id, name, mmr, points, games FROM players ORDER BY mmr DESC")
|
|
|
|
|
players = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
# Die Daten für das Web-GUI in eine lesbare Form umwandeln (Liste von Dictionaries)
|
|
|
|
|
result = []
|
|
|
|
|
|
2026-03-02 16:17:50 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
|
from data.setup_database import DB_PATH
|
|
|
|
|
|
|
|
|
|
def get_gamesystem_data():
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
|
|
|
|
|
connection.row_factory = sqlite3.Row
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
cursor.execute("SELECT * FROM gamesystems")
|
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
# SQLite-Rows in normale Python-Dictionaries um
|
|
|
|
|
result = []
|
|
|
|
|
for row in rows:
|
|
|
|
|
result.append(dict(row))
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def get_player_statistics(player_id):
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
connection.row_factory = sqlite3.Row
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
query = """
|
|
|
|
|
SELECT
|
|
|
|
|
sys.id AS gamesystem_id,
|
|
|
|
|
sys.name AS gamesystem_name,
|
|
|
|
|
sys.*,
|
|
|
|
|
stat.mmr,
|
|
|
|
|
stat.games_in_system,
|
|
|
|
|
stat.points
|
|
|
|
|
FROM gamesystems sys
|
|
|
|
|
LEFT JOIN player_game_statistic stat
|
|
|
|
|
ON sys.id = stat.gamesystem_id AND stat.player_id = ?
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
cursor.execute(query, (player_id,))
|
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
for row in rows:
|
|
|
|
|
result.append(dict(row))
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def join_league(player_id, gamesystem_id):
|
|
|
|
|
connection = sqlite3.connect(DB_PATH)
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
|
|
# Wir fügen nur die beiden IDs ein, der Rest wird von den DEFAULT-Werten der DB erledigt
|
|
|
|
|
query = """
|
|
|
|
|
INSERT INTO player_game_statistic (player_id, gamesystem_id)
|
|
|
|
|
VALUES (?, ?)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
cursor.execute(query, (player_id, gamesystem_id))
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
|
|