diff --git a/moderation_tool.py b/moderation_tool.py index 90723ee..a893023 100755 --- a/moderation_tool.py +++ b/moderation_tool.py @@ -56,6 +56,7 @@ while pass_token == False: print("18) Delete rate limit of a user account.\t67) Get blocked status for room.") print("19) Check if user account exists.\t\t68) Block a room.") print("20) Shadow ban a user.\t\t\t\t69) Unblock a room.") + print("21) Find a user by their 3PID.") print("\n#### Server Commands ####\t\t\t\t\t#### Report Generation ####") print("100) Delete and block a specific media.\t\t\t\t150) Generate user report.") print("101) Purge remote media repository up to a certain date.\t151) Lookup homeserver admin contact details.") @@ -129,6 +130,9 @@ while pass_token == False: elif menu_input == "20": shadow_ban_dict = user_commands.shadow_ban_account('') print(json.dumps(shadow_ban_dict, indent=4, sort_keys=True)) + elif menu_input == "21": + user_dict = user_commands.find_account_with_threepid() + print(f"\n{json.dumps(user_dict, indent=4, sort_keys=True)}") elif menu_input == "50": room_details_dict = room_commands.get_room_details('') print(json.dumps(room_details_dict, indent=4, sort_keys=True)) diff --git a/rdlist_commands.py b/rdlist_commands.py index d7e6424..84820b0 100644 --- a/rdlist_commands.py +++ b/rdlist_commands.py @@ -43,8 +43,9 @@ def get_rdlist_tags(preset_internal_ID): # Git clone the rdlist repo to specified directory sync_rdlist() - # Load the summaries JSON file - summaries_path = os.path.join("rdlist", "dist", "summaries.json") + # Expand the user in the path and load the summaries JSON file + summaries_dir = os.path.expanduser(hardcoded_variables.rdlist_dir) + summaries_path = os.path.join(summaries_dir, "dist", "summaries.json") with open(summaries_path, 'r') as file: data = json.load(file) diff --git a/user_commands.py b/user_commands.py index fcca2d4..cce4605 100644 --- a/user_commands.py +++ b/user_commands.py @@ -537,3 +537,28 @@ def shadow_ban_account(preset_username): # Example: # curl -XPOST -H "Content-Type: application/json" 'https://matrix.perthchat.org/_synapse/admin/v1/users/@dogpoo:perthchat.org/shadow_ban?access_token=ACCESS_TOKEN' + +def find_account_with_threepid(medium="", address=""): + # prompt user to enter values if they're not provided + if medium == "": + print("\nPlease enter the medium (either 'email' or 'msisdn' for mobile number): ") + medium = input() + if address == "": + print("\nPlease enter the address (the email or mobile number): ") + address = input() + + url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/threepid/{medium}/users/{address}?access_token={hardcoded_variables.access_token}" + + response = requests.get(url, verify=True) + + if response.status_code == 200: + # User exists + return response.json() + elif response.status_code == 404: + # User not found + return {"errcode":"M_NOT_FOUND", "error":"User not found"} + else: + print(f"Error querying account: {response.status_code}, {response.text}") + +# Example: +# $ curl -X GET 'https://matrix.perthchat.org/_synapse/admin/v1/threepid/email/users/dogpoo@protonmail.com?access_token=ACCESS_TOKEN'