import random, re import config def parse_notification(notification,client): '''Parses any notifications received by the bot and sends any commands to gacha_response()''' # Get the full Activitypub ID of the user user = notification.get("user", {}) username = user.get("username", "unknown") host = user.get("host") # Local users may not have a hostname attached full_user = f"@{username}" if not host else f"@{username}@{host}" note_obj = notification.get("note", {}) note_text = note_obj.get("text") note_id = note_obj.get("id") note = note_text.strip().lower() if note_text else "" # 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 username_variants): return # Find command and arguments after the mention # Removes all mentions (regex = mentions that start with @ and may contain @domain) cleaned_text = re.sub(r"@\w+(?:@\S+)?", "", note).strip() parts = cleaned_text.split() command = parts[0].lower() if parts else None arguments = parts[1:] if len(parts) > 1 else [] return [command,full_user, arguments, note_obj]