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

[utils] allowing custom cancel/accept edit msg in ConfirmChoiceView #411

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
34 changes: 28 additions & 6 deletions ballsdex/core/utils/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ def __init__(
self,
interaction: discord.Interaction,
user: Optional[discord.User] = None,
accept_message: Optional[str] = None,
cancel_message: Optional[str] = None,
):
super().__init__(timeout=90)
self.value = None
self.interaction = interaction
self.user = user or interaction.user
self.interaction_response: discord.Interaction
self.accept_message = accept_message
self.cancel_message = cancel_message

async def interaction_check(self, interaction: discord.Interaction) -> bool:
self.interaction_response = interaction
Expand Down Expand Up @@ -46,9 +50,18 @@ async def on_timeout(self):
async def confirm_button(self, interaction: discord.Interaction, button: Button):
for item in self.children:
item.disabled = True # type: ignore
await interaction.response.edit_message(
content=interaction.message.content + "\nConfirmed", view=self # type: ignore
)

if interaction.message:
content = interaction.message.content or ""
else:
content = ""

if not self.accept_message:
await interaction.response.edit_message(content=content + "\nConfirmed", view=self)
else:
await interaction.response.edit_message(
content=content + f"\n{self.accept_message}", view=self
)
self.value = True
self.stop()

Expand All @@ -59,8 +72,17 @@ async def confirm_button(self, interaction: discord.Interaction, button: Button)
async def cancel_button(self, interaction: discord.Interaction, button: Button):
for item in self.children:
item.disabled = True # type: ignore
await interaction.response.edit_message(
content=interaction.message.content + "\nCancelled", view=self # type: ignore
)

if interaction.message:
content = interaction.message.content or ""
else:
content = ""

if not self.cancel_message:
await interaction.response.edit_message(content=content + "\nCancelled", view=self)
else:
await interaction.response.edit_message(
content=content + f"\n{self.cancel_message}", view=self
)
self.value = False
self.stop()
6 changes: 5 additions & 1 deletion ballsdex/packages/admin/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,11 @@ async def balls_reset(
f"Are you sure you want to delete {percentage}% of "
f"{user}'s {settings.plural_collectible_name}?"
)
view = ConfirmChoiceView(interaction)
view = ConfirmChoiceView(
interaction,
accept_message=f"Confirmed, deleting the {settings.plural_collectible_name}...",
cancel_message="Request cancelled.",
)
await interaction.followup.send(
text,
view=view,
Expand Down
6 changes: 5 additions & 1 deletion ballsdex/packages/balls/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ async def give(
)
return
if countryball.favorite:
view = ConfirmChoiceView(interaction)
view = ConfirmChoiceView(
interaction,
accept_message=f"{settings.collectible_name.title()} donated.",
cancel_message="This request has been cancelled.",
)
await interaction.response.send_message(
f"This {settings.collectible_name} is a favorite, "
"are you sure you want to donate it?",
Expand Down
13 changes: 11 additions & 2 deletions ballsdex/packages/players/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,13 @@ async def friend_add(self, interaction: discord.Interaction, user: discord.User)
)
return
else:
view = ConfirmChoiceView(
interaction,
user=user,
accept_message="Friend request accepted!",
cancel_message="Friend request declined.",
)
await interaction.response.defer(thinking=True)
view = ConfirmChoiceView(interaction, user=user)
await interaction.followup.send(
f"{user.mention}, {interaction.user} has sent you a friend request!",
view=view,
Expand Down Expand Up @@ -367,7 +372,11 @@ async def block_add(self, interaction: discord.Interaction, user: discord.User):

friended = await player1.is_friend(player2)
if friended:
view = ConfirmChoiceView(interaction)
view = ConfirmChoiceView(
interaction,
accept_message="User has been blocked.",
cancel_message=f"Request cancelled, {user.name} is still your friend.",
)
await interaction.followup.send(
"This user is your friend, are you sure you want to block them?",
view=view,
Expand Down
6 changes: 5 additions & 1 deletion ballsdex/packages/trade/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ async def add(
return
await interaction.response.defer(ephemeral=True, thinking=True)
if countryball.favorite:
view = ConfirmChoiceView(interaction)
view = ConfirmChoiceView(
interaction,
accept_message=f"{settings.collectible_name.title()} added.",
cancel_message="This request has been cancelled.",
)
await interaction.followup.send(
f"This {settings.collectible_name} is a favorite, "
"are you sure you want to trade it?",
Expand Down
Loading