Update duel request functionality and schema to include competitive flag and creation date

This commit is contained in:
w 2025-07-06 15:18:48 -03:00
parent 03f6f1b80c
commit ffa298631a
2 changed files with 17 additions and 7 deletions

View file

@ -111,17 +111,19 @@ def insert_duel_request(username: str, target: str, duel_type: str) -> None:
''' '''
# get the player ids
player_1_1d = get_player(username) player_1_1d = get_player(username)
player_2_id = get_player(target) player_2_id = get_player(target)
# picks a random attacker # sets the creation date
attacker_id = choices([player_1_1d, player_2_id], k=1)[0] created_at = datetime.now().isoformat()
# sets the last round date to the current time competitive = duel_type
last_round_dt = datetime.now().isoformat()
# insert the duel request
CURSOR.execute( CURSOR.execute(
'INSERT INTO duels (player_1_id, player_2_id, attacker_id,last_round_dt) VALUES (?, ?, ?, ?)', 'INSERT INTO duels (player_1_id, player_2_id, attacker_id,last_round_dt,competitive) VALUES (?, ?, ?, ?)',
) )
def insert_player(username: str) -> int: def insert_player(username: str) -> int:

View file

@ -29,6 +29,14 @@ CREATE TABLE duels (
last_round_dt TEXT, last_round_dt TEXT,
is_finished BOOLEAN NOT NULL DEFAULT 0, is_finished BOOLEAN NOT NULL DEFAULT 0,
points INTEGER NOT NULL DEFAULT 0, points INTEGER NOT NULL DEFAULT 0,
winner_id INTEGER DEFAULT NULL, winner_id INTEGER DEFAULT NULL
accepted BOOLEAN NOT NULL DEFAULT 0 );
CREATE TABLE duel_requests (
duel_request_id INTEGER PRIMARY KEY AUTOINCREMENT,
player_1_id INTEGER NOT NULL,
player_2_id INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
accepted BOOLEAN NOT NULL DEFAULT 0,
competitive BOOLEAN NOT NULL DEFAULT 0
); );