From 8c5c860ef6d77ea6c5748497f9b4d807cb4e066f Mon Sep 17 00:00:00 2001 From: w <waifuism@tutanota.com> Date: Wed, 25 Jun 2025 00:21:37 -0300 Subject: [PATCH] get cards function --- bot/db_utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bot/db_utils.py b/bot/db_utils.py index b8d00b1..933ec48 100644 --- a/bot/db_utils.py +++ b/bot/db_utils.py @@ -1,5 +1,5 @@ # 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 # 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'] } +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: '''Retrieve a player ID by username, or return None if not found.'''