Cliffbot/send_cliff.sh
2025-02-14 23:21:30 +13:00

35 lines
811 B
Bash

#!/bin/bash
# .env variables:
# BNRHOOK: discord webhook for the channel
# API: api url for heathcliff image
# create file if it doesn't exist
LAST_URL_PATH='/home/bread/servers/cliff/latest_url.txt'
touch $LAST_URL_PATH
# get the last image url
last_img_url=$(cat $LAST_URL_PATH)
# get current image url
new_img_url=$(curl $API)
echo "got new URL: $new_img_url"
if [[ "$last_img_url" == "$new_img_url" ]]; then
# if it's the same image just exit
echo "new URL matches previous URL; exiting."
exit 1
else
# send message to discord
curl --request POST \
--url "$BNRHOOK" \
--header 'Content-Type: application/json' \
--data '{
"content": "'"$new_img_url"'"
}'
# write new url to file
echo $new_img_url > $LAST_URL_PATH
exit 0
fi