just print to stdout

This commit is contained in:
Ben Harris 2020-06-17 13:39:05 -04:00
parent 7d449deb38
commit b257f25f9d
2 changed files with 14 additions and 16 deletions

View File

@ -7,4 +7,3 @@ link="https://tilderadio.org/listen"
schedule="https://tilderadio.org/schedule/"
source="https://tildegit.org/ben/radiobot"
nick="radiobot"
log="log.txt"

29
bot.sh
View File

@ -1,18 +1,13 @@
#!/bin/bash
#!/usr/bin/env bash
# read configs
. bot.properties
input=".bot.cfg"
# save current dj info on startup
now_playing=$(<$npfile)
dj=$(parse_dj)
printf "Starting session: %s\n" "$(date "+[%y:%m:%d %T]")" > $log
printf "starting %s: %s\n" "$nick" "$(date "+[%y:%m:%d %T]")"
function send {
printf "> %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$1" >> $log
printf "%s\r\n" "$1" >> $input
printf "> %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$1"
printf "%s\r\n" "$1" >> input.txt
}
function msg {
@ -23,18 +18,22 @@ function parse_dj {
grep -Eo '^\([^)]*\)' $npfile | sed 's/[()]//g' | xargs
}
# save current dj info on startup
now_playing=$(<$npfile)
dj=$(parse_dj)
# connect and register
send "NICK $nick"
send "USER $nick 0 * :$nick"
send "MODE $nick +B"
# main loop
tail -f $input | telnet $server $port | while read -r buf
tail -f input.txt | telnet $server $port | while read -r buf
do
# trim \r's
line=$(printf "%b" "$buf" | tr -d $'\r')
line=$(printf %b "$buf" | tr -d $'\r')
# log the received line
printf "< %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$line" >> $log
printf "< %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$line"
# now playing
if [ "$now_playing" != "$(<$npfile)" ]; then
@ -98,7 +97,7 @@ do
fi
# trim leading and split args on space
args=( $(printf "%s" "$args" | sed -E "s/^ //") )
args=( $(printf %s "$args" | sed -E "s/^ //") )
case "${args[0]}" in
subscribe)
@ -111,7 +110,7 @@ do
;;
unsubscribe)
sed -i "/$who/d" subscribers.txt
sed -i"" "/$who/d" subscribers.txt
msg "$from" "i'll stop sending you updates."
;;
@ -129,7 +128,7 @@ do
;;
email-unsubscribe)
sed -i "/$who/d" email-subscribers.txt
sed -i"" "/$who/d" email-subscribers.txt
msg "$from" "i'll stop sending you email updates."
;;