From e5c7196fa9861ff09d57cd94d32b0e06a6ed432a Mon Sep 17 00:00:00 2001 From: w Date: Fri, 4 Jul 2025 00:01:55 -0300 Subject: [PATCH] Add duel request functionality and update duel table schema --- bot/response.py | 30 ++++++++++++++++++++++++++++++ migrations/0007_duelv1.sql | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bot/response.py b/bot/response.py index 8ec698e..5c7f35f 100644 --- a/bot/response.py +++ b/bot/response.py @@ -181,6 +181,31 @@ def do_help(author: str) -> BotResponse: 'attachment_urls': None } +def duel_request(author: str, args: list[str]) -> BotResponse: + '''Sends a duel request to another user.''' + if len(args) == 0: + return { + 'message': f'{author} Please specify a user to duel.', + '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 challenging to a duel.', + 'attachment_urls': None + } + duel_type = 'casual' + if len(args) == 1 and args[0] == "competitive": + 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 delete_account(author: str) -> BotResponse: return { @@ -325,6 +350,11 @@ def generate_response(notification: ParsedNotification) -> BotResponse | None: res = delete_account(author) case 'confirm_delete_account': res = confirm_delete(author) + case 'duel_request': + res = duel_request( + author, + notification['arguments'] + ) case _: pass diff --git a/migrations/0007_duelv1.sql b/migrations/0007_duelv1.sql index 16b5e7d..34e6918 100644 --- a/migrations/0007_duelv1.sql +++ b/migrations/0007_duelv1.sql @@ -29,5 +29,6 @@ CREATE TABLE duel ( last_round_dt TEXT, is_finished BOOLEAN NOT NULL DEFAULT 0, points INTEGER NOT NULL DEFAULT 0, - winner_id INTEGER + winner_id INTEGER, + accepted BOOLEAN NOT NULL DEFAULT 0 );