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,
|
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"])
|
@commands.command(aliases=["l", "leader", "ranking"])
|
||||||
async def leaderboard(self, ctx: commands.Context, board: str = "users") -> None:
|
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):
|
class MeView(discord.ui.View):
|
||||||
status: int = 0
|
status: int = 0
|
||||||
|
|
||||||
def __init__(self, user_id: int) -> None:
|
def __init__(self, user: models.User) -> None:
|
||||||
"""Initializes the view.
|
"""Initializes the view.
|
||||||
|
|
||||||
Args:
|
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)
|
super().__init__(disable_on_timeout=True)
|
||||||
|
|
||||||
@discord.ui.button(
|
async def callback(interaction: discord.Interaction) -> None:
|
||||||
label="Delete My Activity Data", style=discord.ButtonStyle.danger
|
"""Handles the interaction of the button."""
|
||||||
)
|
|
||||||
async def callback(
|
|
||||||
self, button: discord.Button, 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(
|
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:
|
if not user.is_deleting:
|
||||||
self.children[0].label = "Confirm?"
|
button = discord.ui.Button(
|
||||||
await interaction.response.edit_message(view=self)
|
style=discord.ButtonStyle.danger, label="Delete My Activity Data"
|
||||||
|
)
|
||||||
|
button.callback = callback
|
||||||
|
|
||||||
self.status += 1
|
else:
|
||||||
return
|
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.add_item(button)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user