From 59f88b8a4a36e3397948ed3b5020824d496a2a0c Mon Sep 17 00:00:00 2001 From: w Date: Sun, 6 Jul 2025 23:39:51 -0300 Subject: [PATCH] Enhance duel creation and response handling: add duel notification and card check --- bot/db_utils.py | 29 +++++++++++++++++++++++++---- bot/response.py | 9 +++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bot/db_utils.py b/bot/db_utils.py index 8de4b49..3667a93 100644 --- a/bot/db_utils.py +++ b/bot/db_utils.py @@ -197,8 +197,6 @@ def create_duel(duel_request_id: int) -> None: player_1_cards = take_cards(row['player_1_id'], 3) player_2_cards = take_cards(row['player_2_id'], 3) - if not player_1_cards or not player_2_cards: - raise ValueError("One of the players has no cards to duel with.") # Insert the duel into the database, only players ids, attacker id, cards, last round date and competitive flag @@ -221,8 +219,31 @@ def create_duel(duel_request_id: int) -> None: duel_id = CURSOR.lastrowid if duel_id: # Start duel - #start_duel(duel_id) - pass + # Initialize the duel by sending a notification to the players + from fediverse_factory import get_fediverse_service + from fediverse_types import Visibility + + fediverse_service = get_fediverse_service(config.INSTANCE_TYPE) + + + if row['competitive']==1: + duel_type = 'Competitive' + else: + duel_type = 'Casual' + + player_1_name = CURSOR.execute( + 'SELECT username FROM players WHERE id = ?', + (row['player_1_id'],) + ).fetchone()['username'] + player_2_name = CURSOR.execute( + 'SELECT username FROM players WHERE id = ?', + (row['player_2_id'],) + ).fetchone()['username'] + + fediverse_service.create_post( + text=f'⚔️ A {duel_type} Duel started between {player_1_name} and {player_2_name}!', + visibility=Visibility.HOME + ) diff --git a/bot/response.py b/bot/response.py index 96fe385..8db3595 100644 --- a/bot/response.py +++ b/bot/response.py @@ -204,6 +204,10 @@ def duel_request(author: str, args: list[str]) -> BotResponse: Try challenging someone else.', 'attachment_urls': None } + + # Check if both the users have enough cards to duel + # TODO + duel_type = 'casual' if len(args) == 1 and args[0] == "competitive": duel_type = 'competitive' @@ -404,6 +408,11 @@ def generate_response(notification: ParsedNotification) -> BotResponse | None: author, notification['arguments'] ) + case 'accept_duel': + res = accept_duel( + author, + notification['arguments'] + ) case _: pass