From 528e21db23216f713f9f4fb395a272b5395bcba1 Mon Sep 17 00:00:00 2001 From: w Date: Sun, 6 Jul 2025 16:06:55 -0300 Subject: [PATCH] Refactor duel request handling and add accept duel functionality --- bot/db_utils.py | 5 ++--- bot/response.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bot/db_utils.py b/bot/db_utils.py index a61df88..5ba7ee0 100644 --- a/bot/db_utils.py +++ b/bot/db_utils.py @@ -116,14 +116,13 @@ def insert_duel_request(username: str, target: str, duel_type: str) -> None: player_1_1d = get_player(username) player_2_id = get_player(target) - # sets the creation date - created_at = datetime.now().isoformat() competitive = duel_type # insert the duel request CURSOR.execute( - 'INSERT INTO duels (player_1_id, player_2_id, attacker_id,last_round_dt,competitive) VALUES (?, ?, ?, ?)', + 'INSERT INTO duel_requests (player_1_id, player_2_id, competitive) VALUES (?, ?, ?)', + (player_1_1d, player_2_id, competitive) ) def insert_player(username: str) -> int: diff --git a/bot/response.py b/bot/response.py index bdcbd5b..64053b8 100644 --- a/bot/response.py +++ b/bot/response.py @@ -209,14 +209,39 @@ def duel_request(author: str, args: list[str]) -> BotResponse: duel_type = 'competitive' db.insert_duel_request(author, target, duel_type) - + return { 'message': f'{target} You have been challenged to a {duel_type} duel by \ {author}! Reply with `accept_duel` to accept the challenge.', 'attachment_urls': None } +def accept_duel(author: str, args: list[str]) -> BotResponse: + '''Accepts a duel request from another user.''' + if len(args) == 0: + return { + 'message': f'{author} Please specify a user to accept the duel from.', + 'attachment_urls': None + } + target = args[0] + if not db.get_player(target): + return { + 'message': f'{author} User {target} does not exist or \ + has not signed up, please sign up before accepting a duel.', + 'attachment_urls': None + } + + if db.accept_duel_request(author, target): + return { + 'message': f'{author} You have accepted the duel request from {target}.', + 'attachment_urls': None + } + else: + return { + 'message': f'{author} No duel request found from {target}.', + 'attachment_urls': None + } def delete_account(author: str) -> BotResponse: return {