You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB
Bash

#!/bin/bash
domain=$2
login_data=$1
output_file=$3
if [ -z $output_file ]; then
output_file=matrix-rooms.txt
fi
if [ -z $domain -o ! -f $login_data ]; then
echo "domain: $domain login: $login_data"
echo "Usage: $0 ./path/to/matrix-login.txt \"https://matrix.server\""
exit 0
fi
token=$(cat $login_data | jq -r '.access_token')
# Queries for a list of room IDs
# jq '.rooms.join'
# Querying for a list of displaynames
# TODO why are there null's in the list?
# TODO how do I ALSO get the room ID?
# TODO can I just select() in jq to select the room IDs?
# jq '.rooms.join | .[].state.events[].content.channel' matrix-rooms.txt | grep -v null | less
# Lists all room names out of the m.room.name state event as an array
# jq '.rooms.join | [.[].state.events[] | select(.type == "m.room.name").content.name]'
# List all room IDs with room names as objects {"room_name": x, "room_id": y}
# jq '.rooms.join | to_entries[] | {"room_id": .key, "room_name": .value.state.events[] | select(.type == "m.room.name").content.name}'
echo "Querying homeserver for room data. This might take a while ..."
echo curl --globoff -XGET -H "Authorization: Bearer [YOUR TOKEN]" "$domain/_matrix/client/r0/sync?filter={"room":{"timeline":{"limit":1}}}" -o "$output_file"
curl --globoff -XGET -H "Authorization: Bearer $token" "$domain/_matrix/client/r0/sync?filter={\"room\":{\"timeline\":{\"limit\":1}}}" -o "$output_file"