Skip to content

Instantly share code, notes, and snippets.

@mdPlusPlus
Last active July 14, 2023 21:45
Show Gist options
  • Save mdPlusPlus/2e4d3c76b0c7917740d74d886dd40cb3 to your computer and use it in GitHub Desktop.
Save mdPlusPlus/2e4d3c76b0c7917740d74d886dd40cb3 to your computer and use it in GitHub Desktop.
Modping for Session communities
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# check for argument
set +u
if [ -z "${1}" ]
then
echo "Usage: modping.sh %community_link%"
echo "Example: modping.sh \"https://open.getsession.org/session?public_key=a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238\""
exit
fi
set -u
# test argument for regex
# TODO
# dissect URL
host=$(echo "${1}" | cut -d '/' -f 1,2,3)
room=$(echo "${1}" | cut -d '/' -f 4 | cut -d '?' -f 1)
# construct API URL
json_url="${host}/room/${room}"
# grab IDs of admins and mods
session_ids=$(curl -s "${json_url}" | jq .admins[],.moderators[] | sed "s/^\"/@/g" | tr -d "\"" | sort | uniq)
# count IDs
number=$(echo "${session_ids}" | wc -l)
modping="Pinging ${number} mods: ${session_ids}"
# copy modping to clipboard
echo ${modping} | xclip -selection c
echo ${modping}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment