forked from tilderadio/radiobot
just print to stdout
This commit is contained in:
parent
7d449deb38
commit
b257f25f9d
|
@ -7,4 +7,3 @@ link="https://tilderadio.org/listen"
|
||||||
schedule="https://tilderadio.org/schedule/"
|
schedule="https://tilderadio.org/schedule/"
|
||||||
source="https://tildegit.org/ben/radiobot"
|
source="https://tildegit.org/ben/radiobot"
|
||||||
nick="radiobot"
|
nick="radiobot"
|
||||||
log="log.txt"
|
|
||||||
|
|
29
bot.sh
29
bot.sh
|
@ -1,18 +1,13 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# read configs
|
# read configs
|
||||||
. bot.properties
|
. bot.properties
|
||||||
input=".bot.cfg"
|
|
||||||
|
|
||||||
# save current dj info on startup
|
printf "starting %s: %s\n" "$nick" "$(date "+[%y:%m:%d %T]")"
|
||||||
now_playing=$(<$npfile)
|
|
||||||
dj=$(parse_dj)
|
|
||||||
|
|
||||||
printf "Starting session: %s\n" "$(date "+[%y:%m:%d %T]")" > $log
|
|
||||||
|
|
||||||
function send {
|
function send {
|
||||||
printf "> %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$1" >> $log
|
printf "> %s: %s\n" "$(date "+[%y:%m:%d %T]")" "$1"
|
||||||
printf "%s\r\n" "$1" >> $input
|
printf "%s\r\n" "$1" >> input.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
function msg {
|
function msg {
|
||||||
|
@ -23,18 +18,22 @@ function parse_dj {
|
||||||
grep -Eo '^\([^)]*\)' $npfile | sed 's/[()]//g' | xargs
|
grep -Eo '^\([^)]*\)' $npfile | sed 's/[()]//g' | xargs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# save current dj info on startup
|
||||||
|
now_playing=$(<$npfile)
|
||||||
|
dj=$(parse_dj)
|
||||||
|
|
||||||
# connect and register
|
# connect and register
|
||||||
send "NICK $nick"
|
send "NICK $nick"
|
||||||
send "USER $nick 0 * :$nick"
|
send "USER $nick 0 * :$nick"
|
||||||
send "MODE $nick +B"
|
send "MODE $nick +B"
|
||||||
|
|
||||||
# main loop
|
# main loop
|
||||||
tail -f $input | telnet $server $port | while read -r buf
|
tail -f input.txt | telnet $server $port | while read -r buf
|
||||||
do
|
do
|
||||||
# trim \r's
|
# trim \r's
|
||||||
line=$(printf "%b" "$buf" | tr -d $'\r')
|
line=$(printf %b "$buf" | tr -d $'\r')
|
||||||
# log the received line
|
# 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
|
# now playing
|
||||||
if [ "$now_playing" != "$(<$npfile)" ]; then
|
if [ "$now_playing" != "$(<$npfile)" ]; then
|
||||||
|
@ -98,7 +97,7 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# trim leading and split args on space
|
# 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
|
case "${args[0]}" in
|
||||||
subscribe)
|
subscribe)
|
||||||
|
@ -111,7 +110,7 @@ do
|
||||||
;;
|
;;
|
||||||
|
|
||||||
unsubscribe)
|
unsubscribe)
|
||||||
sed -i "/$who/d" subscribers.txt
|
sed -i"" "/$who/d" subscribers.txt
|
||||||
msg "$from" "i'll stop sending you updates."
|
msg "$from" "i'll stop sending you updates."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -129,7 +128,7 @@ do
|
||||||
;;
|
;;
|
||||||
|
|
||||||
email-unsubscribe)
|
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."
|
msg "$from" "i'll stop sending you email updates."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue