Skip to content

Instantly share code, notes, and snippets.

@Cadair
Created December 26, 2017 11:15
Show Gist options
  • Save Cadair/9bd988bbf07f9de06428ff9a837119eb to your computer and use it in GitHub Desktop.
Save Cadair/9bd988bbf07f9de06428ff9a837119eb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from matrix_client.api import MatrixHttpApi"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"access_token = \"\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# SunPy\n",
"room_id = \"!MeRdFpEonLoCwhoHeT:matrix.org\"\n",
"user_id = \"@freenode_jorg255:matrix.org\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def mass_redact(room_id, user_id, access_token, limit=100):\n",
" jfilter = {\n",
" \"event_format\": \"client\",\n",
" \"account_data\": {\n",
" \"limit\": 0,\n",
" \"types\": []\n",
" },\n",
" \"presence\": {\n",
" \"limit\": 0,\n",
" \"types\": []\n",
" },\n",
" \"room\": {\n",
" \"rooms\": [room_id],\n",
" \"account_data\": {\n",
" \"types\": []\n",
" },\n",
" \"timeline\": {\n",
" \"limit\": 150,\n",
" \"types\": [\"m.room.message\"],\n",
" \"senders\": [user_id]\n",
" },\n",
" \"ephemeral\": {\n",
" \"types\": []\n",
" },\n",
" \"state\": {\n",
" \"types\": []\n",
" }\n",
" }\n",
" }\n",
" api = MatrixHttpApi(\"https://matrix.org\", token=access_token)\n",
" response = api.sync(filter=json.dumps(jfilter))\n",
" messages = response['rooms']['join'][room_id]['timeline']['events']\n",
" for message in messages:\n",
" if user_id in message['sender']:\n",
" event_id = message['event_id']\n",
" print(message['event_id'])\n",
" api.redact_event(room_id, event_id, reason=\"spam\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Environment (matrix)",
"language": "python",
"name": "matrix"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment