WIP: dueling_v1 #64
2 changed files with 34 additions and 4 deletions
|
@ -197,8 +197,6 @@ def create_duel(duel_request_id: int) -> None:
|
||||||
|
|
||||||
player_1_cards = take_cards(row['player_1_id'], 3)
|
player_1_cards = take_cards(row['player_1_id'], 3)
|
||||||
player_2_cards = take_cards(row['player_2_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
|
# 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
|
duel_id = CURSOR.lastrowid
|
||||||
if duel_id:
|
if duel_id:
|
||||||
# Start duel
|
# Start duel
|
||||||
#start_duel(duel_id)
|
# Initialize the duel by sending a notification to the players
|
||||||
pass
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,10 @@ def duel_request(author: str, args: list[str]) -> BotResponse:
|
||||||
Try challenging someone else.',
|
Try challenging someone else.',
|
||||||
'attachment_urls': None
|
'attachment_urls': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if both the users have enough cards to duel
|
||||||
|
# TODO
|
||||||
|
|
||||||
duel_type = 'casual'
|
duel_type = 'casual'
|
||||||
if len(args) == 1 and args[0] == "competitive":
|
if len(args) == 1 and args[0] == "competitive":
|
||||||
duel_type = 'competitive'
|
duel_type = 'competitive'
|
||||||
|
@ -404,6 +408,11 @@ def generate_response(notification: ParsedNotification) -> BotResponse | None:
|
||||||
author,
|
author,
|
||||||
notification['arguments']
|
notification['arguments']
|
||||||
)
|
)
|
||||||
|
case 'accept_duel':
|
||||||
|
res = accept_duel(
|
||||||
|
author,
|
||||||
|
notification['arguments']
|
||||||
|
)
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue