diff --git a/bot/bot_app.py b/bot/bot_app.py index 264c031..5806478 100644 --- a/bot/bot_app.py +++ b/bot/bot_app.py @@ -1,4 +1,5 @@ import time +import traceback import misskey from parsing import parse_notification from db_utils import get_or_create_user, add_pull, get_config, set_config @@ -68,7 +69,7 @@ def stream_notifications(): time.sleep(5) except Exception as e: - print(f"Error: {e}") + print(f"An exception has occured: {e}\n{traceback.format_exc()}") time.sleep(5) diff --git a/bot/db_utils.py b/bot/db_utils.py index aefe395..a143f4a 100644 --- a/bot/db_utils.py +++ b/bot/db_utils.py @@ -17,10 +17,10 @@ def get_or_create_user(username): conn.row_factory = sqlite3.Row cur = conn.cursor() cur.execute('SELECT id FROM users WHERE username = ?', (username,)) - user = cur.fetchone()[0] + user = cur.fetchone() if user: conn.close() - return user + return user[0] # New user starts with has_rolled = False cur.execute( diff --git a/bot/gacha_response.py b/bot/gacha_response.py index 0e12a99..e703aff 100644 --- a/bot/gacha_response.py +++ b/bot/gacha_response.py @@ -18,6 +18,14 @@ def get_character(): return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity'] +def is_float(val): + try: + float(val) + return True + except ValueError: + return False + + # TODO: See issue #3, separate command parsing from game logic. def gacha_response(command,full_user, arguments,note_obj): '''Parses a given command with arguments, processes the game state and @@ -34,7 +42,7 @@ def gacha_response(command,full_user, arguments,note_obj): add_pull(user_id,character_id) stars = '⭐️' * rarity - return([f"@{full_user} 🎲 Congrats! You rolled **{character_name}** she's {stars} stars! She's all yours now~ 💖✨",[file_id]]) + return([f"@{full_user} 🎲 Congrats! You rolled {stars} **{character_name}**\nShe's all yours now~ 💖✨",[file_id]]) if command == "create": # Example call from bot logic @@ -42,6 +50,15 @@ def gacha_response(command,full_user, arguments,note_obj): if not image_url: return "You need an image to create a character, dumbass." + if len(arguments) != 3: + return "Please specify the following attributes in order: name, rarity, drop weighting" + + if not (arguments[1].isnumeric() and 1 <= int(arguments[1]) <= 5): + return f"Invalid rarity: '{arguments[1]}' must be a number between 1 and 5" + + if not (is_float(arguments[2]) and 0.0 < float(arguments[2]) <= 1.0): + return f"Invalid drop weight: '{arguments[2]}' must be a decimal value between 0.0 and 1.0" + character_id, file_id = add_character( name=arguments[0], rarity=int(arguments[1]), diff --git a/bot/parsing.py b/bot/parsing.py index a4895b8..e0cf652 100644 --- a/bot/parsing.py +++ b/bot/parsing.py @@ -1,4 +1,5 @@ import random, re +import config from gacha_response import gacha_response def parse_notification(notification,client): @@ -31,15 +32,14 @@ def parse_notification(notification,client): note = note_text.strip().lower() if note_text else "" - # Will want to move bot name to a config file or find a way to derermine - # AP ID at runtime - waifumelon_variants = [ - "@waifumelon", # simple mention - "@waifumelon@mai.waifuism.life", # fully qualified + # Check for both short and fully-qualified name mentions + username_variants = [ + config.USER, + f'@{config.USER.split('@')[1]}' ] # Make sure the notification text explicitly mentions the bot - if not any(variant in note for variant in waifumelon_variants): + if not any(variant in note for variant in username_variants): return # Find command and arguments after the mention