Add duel request functionality and update duel table schema
This commit is contained in:
parent
5d150bfe23
commit
fc335d4537
3 changed files with 30 additions and 1 deletions
|
@ -18,6 +18,7 @@ from random import choices
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import config
|
import config
|
||||||
from custom_types import Card
|
from custom_types import Card
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
DB_PATH = config.DB_PATH
|
DB_PATH = config.DB_PATH
|
||||||
CONNECTION: sqlite3.Connection
|
CONNECTION: sqlite3.Connection
|
||||||
|
@ -100,6 +101,28 @@ def get_player(username: str) -> int:
|
||||||
return int(player[0])
|
return int(player[0])
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def insert_duel_request(username: str, target: str, duel_type: str) -> None:
|
||||||
|
'''Inserts a duel request into the database.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
username (str): The username of the player who initiated the duel.
|
||||||
|
target (str): The username of the player being challenged.
|
||||||
|
duel_type (str): The type of duel (e.g., casual, competitive).
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
player_1_1d = get_player(username)
|
||||||
|
player_2_id = get_player(target)
|
||||||
|
|
||||||
|
# picks a random attacker
|
||||||
|
attacker_id = choices([player_1_1d, player_2_id], k=1)[0]
|
||||||
|
|
||||||
|
# sets the last round date to the current time
|
||||||
|
last_round_dt = datetime.now().isoformat()
|
||||||
|
|
||||||
|
CURSOR.execute(
|
||||||
|
'INSERT INTO duels (player_1_id, player_2_id, attacker_id,last_round_dt) VALUES (?, ?, ?, ?)',
|
||||||
|
)
|
||||||
|
|
||||||
def insert_player(username: str) -> int:
|
def insert_player(username: str) -> int:
|
||||||
'''Insert a new player with default has_rolled = False and return their
|
'''Insert a new player with default has_rolled = False and return their
|
||||||
|
|
|
@ -196,6 +196,12 @@ def duel_request(author: str, args: list[str]) -> BotResponse:
|
||||||
has not signed up, please sign up before challenging to a duel.',
|
has not signed up, please sign up before challenging to a duel.',
|
||||||
'attachment_urls': None
|
'attachment_urls': None
|
||||||
}
|
}
|
||||||
|
if target == author:
|
||||||
|
return {
|
||||||
|
'message': f'{author} You can\'t duel yourself! \
|
||||||
|
Try challenging someone else.',
|
||||||
|
'attachment_urls': None
|
||||||
|
}
|
||||||
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'
|
||||||
|
|
|
@ -29,6 +29,6 @@ CREATE TABLE duels (
|
||||||
last_round_dt TEXT,
|
last_round_dt TEXT,
|
||||||
is_finished BOOLEAN NOT NULL DEFAULT 0,
|
is_finished BOOLEAN NOT NULL DEFAULT 0,
|
||||||
points INTEGER NOT NULL DEFAULT 0,
|
points INTEGER NOT NULL DEFAULT 0,
|
||||||
winner_id INTEGER,
|
winner_id INTEGER DEFAULT NULL,
|
||||||
accepted BOOLEAN NOT NULL DEFAULT 0
|
accepted BOOLEAN NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue