Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trade History] Change to hex id and add trade lookup #168

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ballsdex/core/utils/trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, entries: Iterable[Trade], header, bot):
async def format_page(self, menu, trade: Trade) -> discord.Embed:
embed = discord.Embed(
title=f"Trade History for {self.header}",
description=f"Trade ID: {trade.id}",
description=f"Trade ID: {trade.pk:0X}",
timestamp=trade.date,
)
player1balls = await trade.tradeobjects.filter(player=trade.player2).prefetch_related(
Expand Down
42 changes: 40 additions & 2 deletions ballsdex/packages/admin/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ballsdex.core.utils.buttons import ConfirmChoiceView
from ballsdex.core.utils.logging import log_action
from ballsdex.core.utils.paginator import FieldPageSource, Pages, TextPageSource
from ballsdex.core.utils.trades import TradeViewFormat
from ballsdex.core.utils.trades import TradeViewFormat, get_embed
from ballsdex.core.utils.transformers import (
BallTransform,
EconomyTransform,
Expand Down Expand Up @@ -1226,7 +1226,7 @@ async def history_user(
if not history:
await interaction.followup.send("No history found.", ephemeral=True)
return
source = TradeViewFormat(history, interaction.user.name, self.bot)
source = TradeViewFormat(history, user.display_name, self.bot)
pages = Pages(source=source, interaction=interaction)
await pages.start(ephemeral=True)

Expand Down Expand Up @@ -1278,3 +1278,41 @@ async def history_ball(
source = TradeViewFormat(trades, f"{settings.collectible_name} {ball}", self.bot)
pages = Pages(source=source, interaction=interaction)
await pages.start(ephemeral=True)

@history.command(name="trade")
@app_commands.checks.has_any_role(*settings.root_role_ids)
async def trade_info(
self,
interaction: discord.Interaction["BallsDexBot"],
tradeid: str,
):
"""
Show the contents of a certain trade.
"""
try:
pk = int(tradeid, 16)
except ValueError:
await interaction.response.send_message(
"The trade ID you gave is not valid.", ephemeral=True
)
return
trade = await Trade.get(id=pk).prefetch_related("player1", "player2")
if not trade:
await interaction.response.send_message(
"The trade ID you gave does not exist.", ephemeral=True
)
return
embed = discord.Embed(
title=f"Trade {trade.pk:0X}",
description=f"Trade ID: {trade.pk:0X}",
timestamp=trade.date,
)
player1balls = await trade.tradeobjects.filter(player=trade.player2).prefetch_related(
"ballinstance"
)
player2balls = await trade.tradeobjects.filter(player=trade.player1).prefetch_related(
"ballinstance"
)
embed.set_footer(text="Trade date: ")
embed = await get_embed(embed, trade, player1balls, player2balls, self.bot)
await interaction.response.send_message(embed=embed, ephemeral=True)
Loading