fix(bot): 🐛 Prevent users from marking their account for deletion multiple times.
This commit is contained in:
@@ -512,7 +512,7 @@ class Users(base.Cog):
|
||||
thumbnail=profile.avatar_url,
|
||||
)
|
||||
|
||||
await ctx.send(embed=embed, view=views.MeView(ctx.author.id))
|
||||
await ctx.send(embed=embed, view=views.MeView(user))
|
||||
|
||||
@commands.command(aliases=["l", "leader", "ranking"])
|
||||
async def leaderboard(self, ctx: commands.Context, board: str = "users") -> None:
|
||||
|
||||
@@ -6,55 +6,64 @@ from payphone.db import models
|
||||
class MeView(discord.ui.View):
|
||||
status: int = 0
|
||||
|
||||
def __init__(self, user_id: int) -> None:
|
||||
def __init__(self, user: models.User) -> None:
|
||||
"""Initializes the view.
|
||||
|
||||
Args:
|
||||
user_id (int): The ID of the user to
|
||||
user (models.user): The user to show the view for.
|
||||
"""
|
||||
|
||||
self.user_id = user_id
|
||||
|
||||
super().__init__(disable_on_timeout=True)
|
||||
|
||||
@discord.ui.button(
|
||||
label="Delete My Activity Data", style=discord.ButtonStyle.danger
|
||||
)
|
||||
async def callback(
|
||||
self, button: discord.Button, interaction: discord.Interaction
|
||||
) -> None:
|
||||
"""Handles the interaction of the button."""
|
||||
async def callback(interaction: discord.Interaction) -> None:
|
||||
"""Handles the interaction of the button."""
|
||||
|
||||
if interaction.user.id != self.user_id:
|
||||
if interaction.user.id != user.id:
|
||||
await interaction.response.send_message(
|
||||
"❌ You cannot delete other person's account.", ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
if self.status == 0:
|
||||
self.children[0].label = "Confirm?"
|
||||
await interaction.response.edit_message(view=self)
|
||||
|
||||
self.status += 1
|
||||
return
|
||||
|
||||
user.is_deleting = True
|
||||
await user.save()
|
||||
|
||||
self.disable_all_items()
|
||||
self.children[0].label = "Your account will be deleted"
|
||||
await interaction.response.send_message(
|
||||
"❌ You cannot delete other person's account.", ephemeral=True
|
||||
(
|
||||
"👋 Your account was scheduled for deletion. It may take up to 24 hours for "
|
||||
"your account information to be deleted.\n\n"
|
||||
"What will be deleted:\n"
|
||||
"- Your messages\n"
|
||||
"- Your calls\n"
|
||||
"- Your profiles and user information\n"
|
||||
"- Your stats\n"
|
||||
"- Your reports\n\n"
|
||||
"What won't be deleted:\n"
|
||||
"- Your bans and ban history"
|
||||
),
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
await interaction.message.edit(view=self)
|
||||
|
||||
if self.status == 0:
|
||||
self.children[0].label = "Confirm?"
|
||||
await interaction.response.edit_message(view=self)
|
||||
if not user.is_deleting:
|
||||
button = discord.ui.Button(
|
||||
style=discord.ButtonStyle.danger, label="Delete My Activity Data"
|
||||
)
|
||||
button.callback = callback
|
||||
|
||||
self.status += 1
|
||||
return
|
||||
else:
|
||||
button = discord.ui.Button(
|
||||
style=discord.ButtonStyle.danger,
|
||||
label="Your account is being deleted",
|
||||
disabled=True,
|
||||
)
|
||||
|
||||
await models.User.filter(id=self.user_id).update(is_deleting=True)
|
||||
|
||||
self.disable_all_items()
|
||||
self.children[0].label = "Your account will be deleted"
|
||||
await interaction.response.send_message(
|
||||
(
|
||||
"👋 Your account was scheduled for deletion. It may take up to 24 hours for your "
|
||||
"account information to be deleted.\n\n"
|
||||
"What will be deleted:\n"
|
||||
"- Your messages\n"
|
||||
"- Your calls\n"
|
||||
"- Your profiles and user information\n"
|
||||
"- Your stats\n"
|
||||
"- Your reports\n\n"
|
||||
"What won't be deleted:\n"
|
||||
"- Your bans and ban history"
|
||||
),
|
||||
ephemeral=True,
|
||||
)
|
||||
await interaction.message.edit(view=self)
|
||||
self.add_item(button)
|
||||
|
||||
Reference in New Issue
Block a user