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

Merged
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
22 changes: 20 additions & 2 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: str = "Confirmed",
cancel_message: str = "Cancelled",
):
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,16 @@ 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

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

await interaction.response.edit_message(
content=interaction.message.content + "\nConfirmed", view=self # type: ignore
content=f"{content}\n{self.accept_message}", view=self
)

self.value = True
self.stop()

Expand All @@ -59,8 +70,15 @@ 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

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

await interaction.response.edit_message(
content=interaction.message.content + "\nCancelled", view=self # type: ignore
content=f"{content}\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 @@ -1162,7 +1162,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 @@ -564,7 +564,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
14 changes: 11 additions & 3 deletions ballsdex/packages/players/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,17 @@ async def friend_add(self, interaction: discord.Interaction, user: discord.User)
return

await interaction.response.defer(thinking=True)
view = ConfirmChoiceView(interaction, user=user)
view = ConfirmChoiceView(
interaction,
user=user,
accept_message="Friend request accepted!",
cancel_message="Friend request declined.",
)
await interaction.followup.send(
f"{user.mention}, {interaction.user} has sent you a friend request!",
view=view,
allowed_mentions=discord.AllowedMentions(users=player2.can_be_mentioned),
)

self.active_friend_requests[(player1.discord_id, player2.discord_id)] = True
await view.wait()

Expand Down Expand Up @@ -379,7 +383,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