Compare commits
3 commits
e1e6808b0a
...
8c5c860ef6
Author | SHA1 | Date | |
---|---|---|---|
8c5c860ef6 | |||
cce941471f | |||
7b75a7eea9 |
2 changed files with 40 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
# Kemoverse - a gacha-style bot for the Fediverse.
|
# Kemoverse - a gacha-style bot for the Fediverse.
|
||||||
# Copyright © 2025 Waifu VD15, Moon, and contributors.
|
# Copyright © 2025 Waifu, VD15, Moon, and contributors.
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -75,6 +75,19 @@ def get_random_card() -> Card | None:
|
||||||
'image_url': chosen['file_id']
|
'image_url': chosen['file_id']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_cards(card_ids: list[int]) -> list[tuple]:
|
||||||
|
'''
|
||||||
|
Retrieves stats for a list of card IDs.
|
||||||
|
Returns a list of tuples: (id, name, rarity, file_id, power, charm, wit, ...)
|
||||||
|
'''
|
||||||
|
if not card_ids:
|
||||||
|
return []
|
||||||
|
|
||||||
|
placeholders = ','.join('?' for _ in card_ids)
|
||||||
|
query = f'SELECT * FROM cards WHERE id IN ({placeholders})'
|
||||||
|
|
||||||
|
CURSOR.execute(query, card_ids)
|
||||||
|
return CURSOR.fetchall()
|
||||||
|
|
||||||
def get_player(username: str) -> int:
|
def get_player(username: str) -> int:
|
||||||
'''Retrieve a player ID by username, or return None if not found.'''
|
'''Retrieve a player ID by username, or return None if not found.'''
|
||||||
|
@ -166,12 +179,25 @@ def is_player_administrator(username: str) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def insert_card(
|
def insert_card(
|
||||||
name: str, rarity: int, file_id: str) -> int:
|
name: str, rarity: int, file_id: str,
|
||||||
|
power: int =None, charm: int = None, wit: int = None) -> int:
|
||||||
'''Inserts a card'''
|
'''Inserts a card'''
|
||||||
CURSOR.execute(
|
if power is not None and charm is not None and wit is not None:
|
||||||
'INSERT INTO cards (name, rarity, file_id) VALUES (?, ?, ?)',
|
CURSOR.execute(
|
||||||
(name, rarity, file_id)
|
'''
|
||||||
)
|
INSERT INTO card (name, rarity, file_id, power, charm, wit)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
''',
|
||||||
|
(name, rarity, file_id, power, charm, wit)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
CURSOR.execute(
|
||||||
|
'''
|
||||||
|
INSERT INTO card (name, rarity, file_id)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
''',
|
||||||
|
(name, rarity, file_id)
|
||||||
|
)
|
||||||
card_id = CURSOR.lastrowid
|
card_id = CURSOR.lastrowid
|
||||||
return card_id if card_id else 0
|
return card_id if card_id else 0
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@ You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see https://www.gnu.org/licenses/.
|
along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS card_stats (
|
ALTER TABLE card
|
||||||
card_id INTEGER PRIMARY KEY,
|
ADD COLUMN power INTEGER NOT NULL DEFAULT (abs(random() % 9999));
|
||||||
power INTEGER NOT NULL DEFAULT abs(random() % 9999),
|
|
||||||
charm INTEGER NOT NULL DEFAULT abs(random() % 9999),,
|
ALTER TABLE card
|
||||||
FOREIGN KEY(card_id) REFERENCES card(id)
|
ADD COLUMN charm INTEGER NOT NULL DEFAULT (abs(random() % 9999));
|
||||||
)
|
|
||||||
|
ALTER TABLE card
|
||||||
|
ADD COLUMN wit INTEGER NOT NULL DEFAULT (abs(random() % 9999));
|
Loading…
Add table
Reference in a new issue