account deletion

This commit is contained in:
w 2025-06-01 23:25:18 -03:00
parent a0ed6ded41
commit dce2c9072b
2 changed files with 51 additions and 1 deletions

View file

@ -42,6 +42,34 @@ def insert_player(username):
)
return CURSOR.lastrowid
def delete_player(username):
'''Permanently deletes a user and all their pulls.'''
CURSOR.execute(
'SELECT id FROM users WHERE username = ?',
(username,)
)
user = CURSOR.fetchone()
if not user:
return False # No such user
user_id = user[0]
# Delete pulls
CURSOR.execute(
'DELETE FROM pulls WHERE user_id = ?',
(user_id,)
)
# Delete user
CURSOR.execute(
'DELETE FROM users WHERE id = ?',
(user_id,)
)
return True
def insert_character(name: str, rarity: int, weight: float, file_id: str) -> int:
'''Inserts a character'''
CURSOR.execute(

View file

@ -1,5 +1,5 @@
from datetime import datetime, timedelta, timezone
from db_utils import get_player, insert_player, insert_pull, get_last_rolled_at, get_random_character
from db_utils import get_player, insert_player, delete_player, insert_pull, get_last_rolled_at, get_random_character
from add_character import add_character
from config import GACHA_ROLL_INTERVAL
@ -94,8 +94,26 @@ def do_help(full_user):
return f'{full_user} Here\'s what I can do:\n \
- `roll` Pulls a random character.\
- `create <name> <rarity> <weight>` Creates a character using a given image.\
- `signup` Registers your account.\
- `delete_account` Deletes your account.\
- `help` Shows this message'
def delete_account(full_user):
return (
f'@{full_user} ⚠️ This will permanently delete your account and all your cards.\n'
'If youre sure, reply with `confirm_delete` to proceed.\n\n'
'**There is no undo.** Your gacha luck will be lost to the void... 💀✨'
)
def confirm_delete(full_user):
success = delete_player(full_user)
if not success:
return f'@{full_user} ❌ No account found to delete. Maybe its already gone?'
return f'@{full_user} 🧼 Your account and all your cards have been deleted. RIP your gacha history 🕊️✨'
def generate_response(parsed_command):
'''Given a command with arguments, processes the game state and
returns a response'''
@ -110,5 +128,9 @@ def generate_response(parsed_command):
return do_help(command)
case 'signup':
return do_signup(full_user)
case 'delete_account':
return delete_account(full_user)
case 'confirm_delete':
return confirm_delete(full_user)
case _:
return None