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] adding confirmation to cancel + clear proposal buttons #537

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
59 changes: 51 additions & 8 deletions ballsdex/packages/trade/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,55 @@ async def lock(self, interaction: discord.Interaction, button: Button):
@button(label="Reset", emoji="\N{DASH SYMBOL}", style=discord.ButtonStyle.secondary)
async def clear(self, interaction: discord.Interaction, button: Button):
trader = self.trade._get_trader(interaction.user)
await interaction.response.defer(thinking=True, ephemeral=True)

if trader.locked:
await interaction.response.send_message(
await interaction.followup.send(
"You have locked your proposal, it cannot be edited! "
"You can click the cancel button to stop the trade instead.",
ephemeral=True,
)
else:
for countryball in trader.proposal:
await countryball.unlock()
trader.proposal.clear()
await interaction.response.send_message("Proposal cleared.", ephemeral=True)

view = ConfirmChoiceView(
interaction,
accept_message="Clearing your proposal...",
cancel_message="This request has been cancelled.",
)
await interaction.followup.send(
"Are you sure you want to clear your proposal?", view=view, ephemeral=True
)
await view.wait()
if not view.value:
return

for countryball in trader.proposal:
await countryball.unlock()

trader.proposal.clear()
await interaction.followup.send("Proposal cleared.", ephemeral=True)

@button(
label="Cancel trade",
emoji="\N{HEAVY MULTIPLICATION X}\N{VARIATION SELECTOR-16}",
style=discord.ButtonStyle.danger,
)
async def cancel(self, interaction: discord.Interaction, button: Button):
await interaction.response.defer(thinking=True, ephemeral=True)

view = ConfirmChoiceView(
interaction,
accept_message="Cancelling the trade...",
cancel_message="This request has been cancelled.",
)
await interaction.followup.send(
"Are you sure you want to cancel this trade?", view=view, ephemeral=True
)
await view.wait()
if not view.value:
return

await self.trade.user_cancel(self.trade._get_trader(interaction.user))
await interaction.response.send_message("Trade has been cancelled.", ephemeral=True)
await interaction.followup.send("Trade has been cancelled.", ephemeral=True)


class ConfirmView(View):
Expand Down Expand Up @@ -151,8 +180,22 @@ async def accept_button(self, interaction: discord.Interaction, button: Button):
emoji="\N{HEAVY MULTIPLICATION X}\N{VARIATION SELECTOR-16}",
)
async def deny_button(self, interaction: discord.Interaction, button: Button):
await interaction.response.defer(thinking=True, ephemeral=True)

view = ConfirmChoiceView(
interaction,
accept_message="Cancelling the trade...",
cancel_message="This request has been cancelled.",
)
await interaction.followup.send(
"Are you sure you want to cancel this trade?", view=view, ephemeral=True
)
await view.wait()
if not view.value:
return

await self.trade.user_cancel(self.trade._get_trader(interaction.user))
await interaction.response.send_message("Trade has been cancelled.", ephemeral=True)
await interaction.followup.send("Trade has been cancelled.", ephemeral=True)


class TradeMenu:
Expand Down