subscribers!

This commit is contained in:
Ben Harris 2018-10-30 17:28:33 -04:00
parent 8f7bc9a396
commit c51c5e02b6
Signed by untrusted user: ben
GPG Key ID: 4E0AF802FFF7960C
2 changed files with 40 additions and 0 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ toot.json
log.txt
.bot.cfg
subscribers.txt
now_playing.txt

38
bot.sh
View File

@ -31,6 +31,9 @@ do
dj=$(parse_dj)
if [[ ! -z "${dj}" ]]; then
echo "PRIVMSG #$channel :$dj is now online! tune in now here: https://bhh.sh/listen" >> $input
while read -u 10 subscriber; do
echo "PRIVMSG $subscriber :$dj is now online! tune in now here: https://bhh.sh/listen" $input
done 10< subscribers.txt
TOOT_JSON_PATH=. toot "dj $dj is now streaming live on https://tilderadio.org! tune in here: https://bhh.sh/listen"
fi
fi
@ -53,6 +56,41 @@ do
echo "JOIN #$channel" >> $input
;;
# run when a message is seen
PRIVMSG*)
echo "$res"
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
from=$(echo "$res" | perl -pe "s/.*PRIVMSG (.*[#]?([a-zA-Z]|\-)*) :.*/\1/")
# "#" would mean it's a channel
if [ "$(echo "$from" | grep '^#')" ]; then
test "$(echo "$res" | grep ":$nick:")" || continue
else
from=$who
fi
com=$(echo "$will" | cut -d " " -f1)
case "$com" in
subscribe)
echo $from >> subscribers.txt
echo "PRIVMSG $from :i'll send you a direct message when a dj starts streaming!" >> $input
;;
unsubscribe)
sed -i "/$from/d" subscribers.txt
echo "PRIVMSG $from :i'll stop sending you updates." >> $input
;;
np)
echo "PRIVMSG $from :$now_playing" >> $input
;;
dj)
echo "PRIVMSG $from :${dj:-"no one"} is on the air now" >> $input
;;
esac
;;
# else
*)
echo "$res"