Refactor duel request handling and add accept duel functionality
This commit is contained in:
parent
ffa298631a
commit
528e21db23
2 changed files with 28 additions and 4 deletions
|
@ -116,14 +116,13 @@ def insert_duel_request(username: str, target: str, duel_type: str) -> None:
|
||||||
player_1_1d = get_player(username)
|
player_1_1d = get_player(username)
|
||||||
player_2_id = get_player(target)
|
player_2_id = get_player(target)
|
||||||
|
|
||||||
# sets the creation date
|
|
||||||
created_at = datetime.now().isoformat()
|
|
||||||
|
|
||||||
competitive = duel_type
|
competitive = duel_type
|
||||||
|
|
||||||
# insert the duel request
|
# insert the duel request
|
||||||
CURSOR.execute(
|
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:
|
def insert_player(username: str) -> int:
|
||||||
|
|
|
@ -216,7 +216,32 @@ def duel_request(author: str, args: list[str]) -> BotResponse:
|
||||||
'attachment_urls': None
|
'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:
|
def delete_account(author: str) -> BotResponse:
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Reference in a new issue