feat(bot): ✨ Add "Delete My Activity Data" button to p.me.

This commit is contained in:
Nyeki.py
2024-11-02 23:39:18 -03:00
parent c3c44a57a6
commit ddd439d6d7
7 changed files with 135 additions and 228 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ import httpx
from payphone import bot
from payphone.db import models, utils
from payphone.cogs import base
from payphone.core import constants
from payphone.cogs import base
from payphone.cogs.users import views
class Users(base.Cog):
@@ -511,7 +512,7 @@ class Users(base.Cog):
thumbnail=profile.avatar_url,
)
await ctx.send(embed=embed)
await ctx.send(embed=embed, view=views.MeView(ctx.author.id))
@commands.command(aliases=["l", "leader", "ranking"])
async def leaderboard(self, ctx: commands.Context, board: str = "users") -> None:
+60
View File
@@ -0,0 +1,60 @@
import discord
from payphone.db import models
class MeView(discord.ui.View):
status: int = 0
def __init__(self, user_id: int) -> None:
"""Initializes the view.
Args:
user_id (int): The ID of the user to
"""
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."""
if interaction.user.id != self.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
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)
@@ -0,0 +1,21 @@
from tortoise import BaseDBAsyncClient
async def upgrade(db: BaseDBAsyncClient) -> str:
return """
DROP INDEX "idx_report_status_d6b157";
DROP INDEX "idx_ban_user_id_37a9cf";
ALTER TABLE "user" ADD "is_deleting" BOOL NOT NULL DEFAULT False;
CREATE INDEX "idx_ban_user_id_37a9cf" ON "ban" ("user_id", "expires_at");;
CREATE INDEX "idx_report_status_d6b157" ON "report" ("status", "priority");;
CREATE INDEX "idx_user_is_dele_2b4cfd" ON "user" ("is_deleting");"""
async def downgrade(db: BaseDBAsyncClient) -> str:
return """
DROP INDEX "idx_report_status_d6b157";
DROP INDEX "idx_user_is_dele_2b4cfd";
DROP INDEX "idx_ban_user_id_37a9cf";
ALTER TABLE "user" DROP COLUMN "is_deleting";
CREATE INDEX "idx_ban_user_id_37a9cf" ON "ban" ("user_id", "expires_at");;
CREATE INDEX "idx_report_status_d6b157" ON "report" ("status", "priority");;"""
+1
View File
@@ -18,6 +18,7 @@ class User(models.Model):
username: str = fields.CharField(max_length=32, db_index=True)
is_masked: bool = fields.BooleanField(default=False)
is_moderator: bool = fields.BooleanField(default=False)
is_deleting: bool = fields.BooleanField(default=False, db_index=True)
found_easter_eggs: int = fields.IntEnumField(EasterEggCommand, default=0)
profiles: fields.BackwardFKRelation["Profile"]
call_rss: fields.BackwardFKRelation["CallUserChannelRelationship"]