Enhance duel creation and response handling: add duel notification and card check

This commit is contained in:
w 2025-07-06 23:39:51 -03:00
parent b8bf9449ba
commit 59f88b8a4a
2 changed files with 34 additions and 4 deletions

View file

@ -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
)

View file

@ -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