add example of remote media purging, create new function for sending server notices (untested).

This commit is contained in:
PC-Admin 2023-08-23 18:36:40 +08:00
parent d986fb424e
commit 7475e38388
3 changed files with 86 additions and 5 deletions

View File

@ -45,8 +45,24 @@ Process Flow:
Example: Example:
```bash ```bash
$ date --date '149 days ago' +%s $ python3 moderation_tool.py
$ curl -X POST --header "Authorization: Bearer ACCESS_TOKEN" '... Matrix Synapse purge endpoint ...'
101
Enter the number of days to purge from: 30
Enter the number of days to purge too: -2
{"deleted":0}
{"deleted":0}
{"deleted":3}
{"deleted":360}
{"deleted":469}
...
{"deleted":1020}
{"deleted":2440}
{"deleted":0}
{"deleted":0}
Done! :)
``` ```
102) **Prepare Database for Copying Events of Multiple Rooms** 102) **Prepare Database for Copying Events of Multiple Rooms**

View File

@ -80,9 +80,10 @@ while pass_token == False:
print("103) Show last 10 reported events.\t\t\t\t#### Report Generation ####") print("103) Show last 10 reported events.\t\t\t\t#### Report Generation ####")
print("104) Get all reported events.\t\t\t\t\t150) Generate user report.") print("104) Get all reported events.\t\t\t\t\t150) Generate user report.")
print("105) Get details of a reported event.\t\t\t\t151) Lookup homeserver admin contact details.") print("105) Get details of a reported event.\t\t\t\t151) Lookup homeserver admin contact details.")
print("\t\t\t\t\t\t\t\t152) Send a test email (to yourself).") print("106) Send a server notice.\t\t\t\t\t152) Send a test email (to yourself).")
print("#### rdlist - General ####\t\t\t\t\t153) Send a test Matrix message (to yourself).") print("\t\t\t\t\t\t\t\t\t153) Send a test Matrix message (to yourself).")
print("120) Block all rooms with specific rdlist tags.\t\t\t154) Send test incident reports (to yourself).") print("\n#### rdlist - General ####\t\t\t\t\t154) Send test incident reports (to yourself).")
print("120) Block all rooms with specific rdlist tags.")
print("121) Get rdlist tags for a room.") print("121) Get rdlist tags for a room.")
print("\n#### rdlist - Recommended Tags ####") print("\n#### rdlist - Recommended Tags ####")
print("For rdlist rooms with recommended tags, the following actions are available:") print("For rdlist rooms with recommended tags, the following actions are available:")
@ -212,6 +213,9 @@ while pass_token == False:
elif menu_input == "105": elif menu_input == "105":
report_details = server_commands.get_event_report_details() report_details = server_commands.get_event_report_details()
print(json.dumps(report_details, indent=4, sort_keys=True)) print(json.dumps(report_details, indent=4, sort_keys=True))
elif menu_input == "106":
server_commands.send_server_notice()
print("\nServer notice sent.\n")
elif menu_input == "120": elif menu_input == "120":
rdlist_commands.block_all_rooms_with_rdlist_tags(False,'','','') rdlist_commands.block_all_rooms_with_rdlist_tags(False,'','','')
elif menu_input == "121": elif menu_input == "121":

View File

@ -203,3 +203,64 @@ def get_event_report_details(preset_report_id=''):
else: else:
print(f"Error fetching event report details: {response.status_code}, {response.text}") print(f"Error fetching event report details: {response.status_code}, {response.text}")
return None return None
def send_server_notice(preset_user_id='', preset_message='', txnId=None, event_type="m.room.message", state_key=None):
"""
Sends a server notice to a given user.
Args:
- user_id (str): The Matrix ID of the user to send the notice to, e.g. "@target_user:server_name".
- message (str): The message to be sent as a notice.
- txnId (str, optional): A unique transaction ID. If provided, retransmissions with the same txnId will be ignored.
- event_type (str, optional): The type of event. Defaults to "m.room.message".
- state_key (str, optional): Setting this will result in a state event being sent.
Returns:
- dict: A dictionary containing the response from the server.
"""
# Take user_id from user if not provided
if preset_user_id == '':
user_id = input("\nEnter the user_id of the user you would like to send the server notice to: ")
elif preset_user_id != '':
user_id = preset_user_id
# Take message from user if not provided
if preset_message == '':
message = input("\nEnter the message you would like to send to the user: ")
elif preset_message != '':
message = preset_message
# Construct the URL based on whether a txnId is provided
if txnId:
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/send_server_notice/{txnId}"
else:
url = f"https://{hardcoded_variables.homeserver_url}/_synapse/admin/v1/send_server_notice"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {hardcoded_variables.access_token}"
}
# Construct the request body
data = {
"user_id": user_id,
"content": {
"msgtype": "m.text",
"body": message
}
}
if event_type:
data["type"] = event_type
if state_key:
data["state_key"] = state_key
# Send the request
response = requests.put(url, headers=headers, json=data) if txnId else requests.post(url, headers=headers, json=data)
if response.status_code == 200:
return response.json()
else:
print(f"Error sending server notice: {response.status_code}, {response.text}")
return None