scripts/check-levels

60 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Define RUMPUS_DELEGATION_KEY, SEND_ADDR, and optionally USE_GPG
RCFILE="$(dirname $0)/.checklevelsrc"
if [ -f $RCFILE ]; then
source $RCFILE
fi
FOLLOWING_RES=$(curl -s -H "Rumpus-Delegation-Key: $RUMPUS_DELEGATION_KEY" https://www.bscotch.net/api/levelhead/players/@me/following)
FOLLOWING=$(jq -r '.data[] | .userId' <<< $FOLLOWING_RES)
FOLLOWING_CS=$(paste -s -d, /dev/stdin <<< $FOLLOWING)
LEVELS_RES=$(curl -s -G -H "Rumpus-Delegation-Key: $RUMPUS_DELEGATION_KEY" --data-urlencode "userIds=$FOLLOWING_CS" --data-urlencode "includeAliases=true" --data-urlencode "maxSecondsAgo=86400" https://www.bscotch.net/api/levelhead/levels)
LEVELS=$(jq -r -c '.data[] | {id: .levelId, creator: .alias.alias, title: .title}' <<< $LEVELS_RES)
if [ -z "$LEVELS" ]
then
exit 0
fi
COMPOSE=$(mktemp)
echo -e "We found some new levels... be sure to check them out!\n" > $COMPOSE
while read -r LEVEL; do
LEVEL_ID=$(jq -r '.id' <<< $LEVEL)
LEVEL_CREATOR=$(jq -r '.creator' <<< $LEVEL)
LEVEL_TITLE=$(jq -r '.title' <<< $LEVEL)
echo "Found new level: $LEVEL_TITLE ($LEVEL_ID) by $LEVEL_CREATOR!" >> $COMPOSE
done <<< $LEVELS
if [ ! -z "$USE_GPG" ]
then
gpg --refresh-keys
sendmail $SEND_ADDR <<EOF
Subject: New Levelhead Levels
Content-Type: multipart/encrypted;
protocol="application/pgp-encrypted";
boundary="contentboundary"
This message is encrypted with PGP/MIME.
--contentboundary
Content-Type: application/pgp-encrypted
Version: 1
--contentboundary
Content-Type: application/octet-stream; name="encrypted.asc"
$(gpg --batch --armor --recipient "$SEND_ADDR" -o- --encrypt "$COMPOSE")
--contentboundary--
EOF
else
mail -s "New Levelhead Levels" "$SEND_ADDR" < "$COMPOSE"
fi
rm $COMPOSE