radiobot/bot.sh

52 lines
1.1 KiB
Bash

#!/bin/bash
. bot.properties
input=".bot.cfg"
now_playing=$(<$now_playing_file)
dj=$(parse_dj)
echo "Starting session: $(date "+[%y:%m:%d %T]")">$log
echo "NICK $nick" > $input
echo "USER $user" >> $input
echo "JOIN #$channel" >> $input
function parse_dj {
echo $now_playing | grep -Eo '^\([^)]*\)' | sed 's/[()]//g'
}
tail -f $input | telnet $server $port | while read res
do
# log the session
echo "$(date "+[%y:%m:%d %T]")$res" >> $log
# now playing
if [[ $now_playing != "$(<$now_playing_file)" ]]; then
now_playing=$(<$now_playing_file)
echo "PRIVMSG #tilderadio :$now_playing" >> $input
fi
if [[ $dj != $(parse_dj) ]]; then
[ -z ${dj+x} ] && continue
dj=$(parse_dj)
echo "PRIVMSG #tilderadio :$dj is now online!" >> $input
TOOT_JSON_PATH=. toot "dj $dj is now streaming live at https://tilderadio.org!"
fi
# do things when you see output
case "$res" in
# respond to ping requests from the server
PING*)
echo "$res" | sed "s/I/O/" >> $input
;;
# make sure we're joined
*376*|*404*)
echo "JOIN #$channel" >> $input
;;
# else
*)
echo "$res"
;;
esac
done