Explicit account modification #42

Merged
waifu merged 7 commits from 35_Explicit_account_modification into dev 2025-06-03 19:06:14 -07:00
2 changed files with 51 additions and 1 deletions
Showing only changes of commit dce2c9072b - Show all commits

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
Review

I mean, you do expect this username to be deleted anyway, right. False if the user does exist and the operation failed for some reason. Though depends on the use-case

I mean, you do expect this username to be deleted anyway, right. False if the user does exist and the operation failed for some reason. Though depends on the use-case
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'''
Review

it'd be more readable if you unpacked the array into variables that have names. is_float(arguments[2])) is too low-level if you are not someone who wrote this function.
For example, is_float(rarity) seems better and less bug prone, since you can't fuck up accessing by a wrong index

it'd be more readable if you unpacked the array into variables that have names. `is_float(arguments[2]))` is too low-level if you are not someone who wrote this function. For example, `is_float(rarity)` seems better and less bug prone, since you can't fuck up accessing by a wrong index
@ -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