#!/bin/bash
# 
# remove a list of events from a specific room
#
# create event list like:
#  sudo -u postgres psql synapse -Atc \
#   "SELECT event_id FROM events e LEFT JOIN event_json ej USING(event_id) WHERE e.room_id='"'!'"NrRVEWbxnLuHdvlPhM:grin.hu' AND ej.json ~ 'gorelol.ori-club.xyz'" > events.data
#
#
. ./_config.sh

room_id="!NrRVEWbxnLuHdvlPhM:grin.hu"
reason="spamming"

f_event="events.data"

cat $f_event | while read evt; do
	#echo "== event: $evt =="
	method='PUT'
	data="{\"reason\":\"${reason}\"}"
	cmd="/_matrix/client/v3/rooms/${room_id}/redact/${evt}/"`uuid`
	#echo "${method} $cmd $data"
	curl -d "${data}" -X "${method}" -H "Authorization: Bearer ${T}" "${SRV}${cmd}"
done

