diff --git a/cogs/refractor.py b/cogs/refractor.py index 410adb3..a1f2f63 100644 --- a/cogs/refractor.py +++ b/cogs/refractor.py @@ -167,13 +167,17 @@ class Refractor(commands.Cog): ) return - params = [("team_id", team["id"]), ("limit", 500)] + page = max(1, page) + offset = (page - 1) * PAGE_SIZE + params = [("team_id", team["id"]), ("limit", PAGE_SIZE), ("offset", offset)] if card_type: params.append(("card_type", card_type)) if season is not None: params.append(("season", season)) if tier is not None: params.append(("tier", tier)) + if progress: + params.append(("progress", progress)) data = await db_get("refractor/cards", params=params) if not data: @@ -183,21 +187,23 @@ class Refractor(commands.Cog): return items = data if isinstance(data, list) else data.get("items", []) + total_count = ( + data.get("count", len(items)) if isinstance(data, dict) else len(items) + ) if not items: - await interaction.edit_original_response( - content="No refractor data found for your team." - ) - return - - if progress == "close": - items = apply_close_filter(items) - if not items: + if progress == "close": await interaction.edit_original_response( content="No cards are currently close to a tier advancement." ) - return + else: + await interaction.edit_original_response( + content="No refractor data found for your team." + ) + return - page_items, total_pages = paginate(items, page) + total_pages = max(1, (total_count + PAGE_SIZE - 1) // PAGE_SIZE) + page = min(page, total_pages) + page_items = items lines = [format_refractor_entry(state) for state in page_items] embed = discord.Embed( @@ -205,7 +211,9 @@ class Refractor(commands.Cog): description="\n\n".join(lines), color=0x6F42C1, ) - embed.set_footer(text=f"Page {page}/{total_pages} · {len(items)} card(s) total") + embed.set_footer( + text=f"Page {page}/{total_pages} · {total_count} card(s) total" + ) await interaction.edit_original_response(embed=embed)