declare -A reminders
cleanup() {
- echo "QUIT :Going back to hell" >&4
+ send_line "QUIT :Going back to hell"
keeprunning=0
sleep 0.2
if [[ $irc_process -gt 0 ]]; then
list_reminders $channel
;;
*)
- send_line "PRIVMSG $channel :Sorry, don't know how to $bot_command."
+ send_action $channel "is sorry, they don't know how to $bot_command."
;;
esac
fi
sleep 0.1
}
+send_privmsg() {
+ channel="$1"
+ content="$2"
+
+ send_line "PRIVMSG $channel :$content"
+}
+
+send_action() {
+ channel="$1"
+ content="$2"
+ action_wrapper=$'\001'
+
+ content="${action_wrapper}ACTION ${content}${action_wrapper}"
+ send_privmsg "$channel" "$content"
+}
+
send_help_message() {
channel=$1
echo "Sending help!"
- send_line "PRIVMSG $channel :Help:"
- send_line "PRIVMSG $channel : An IRC bot written in bash!"
- send_line "PRIVMSG $channel : help - display this message"
- send_line "PRIVMSG $channel : version - display version number"
- send_line "PRIVMSG $channel : quit - make the bot quit IRC"
- send_line "PRIVMSG $channel : add YYYY-mm-dd HH:MM reminder text"
- send_line "PRIVMSG $channel : list - list reminders"
+ send_privmsg $channel "Help:"
+ send_privmsg $channel " An IRC bot written in bash!"
+ send_privmsg $channel " help - display this message"
+ send_privmsg $channel " version - display version number"
+ send_privmsg $channel " quit - make the bot quit IRC"
+ send_privmsg $channel " add YYYY-mm-dd HH:MM reminder text"
+ send_privmsg $channel " list - list reminders"
}
send_version() {
channel=$1
- send_line "PRIVMSG $channel :Version: $version"
+ send_privmsg $channel "Version: $version"
}
add_reminder() {
# YYYY-mm-dd HH:MM the text of the reminder
timestamp=$(date +"%s" --date="${dataparts[0]} ${dataparts[1]}")
if [[ $? -ne 0 ]]; then
- send_line "PRIVMSG $channel :Couldn't parse date/time ${dataparts[0]} ${dataparts[1]}"
+ send_privmsg $channel "Couldn't parse date/time ${dataparts[0]} ${dataparts[1]}"
else
- send_line "PRIVMSG $channel :Added reminder for ${dataparts[0]} ${dataparts[1]}: ${dataparts[@]:2}"
+ send_privmsg $channel "Added reminder for ${dataparts[0]} ${dataparts[1]}: ${dataparts[@]:2}"
reminders[$timestamp]="${dataparts[@]:2}"
fi
}
# loop through the reminders keys to see if it's past and alert if so
for ts in ${!reminders[@]}; do
if [[ $ts -le $current_timestamp ]]; then
- send_line "PRIVMSG $my_irc_channel :${reminders[$ts]}"
+ send_privmsg $my_irc_channel "${reminders[$ts]}"
# we need to remove this from the array now
unset "reminders[$ts]"
fi
channel=$1
for ts in ${!reminders[@]}; do
date_stamp="$(date --date="@$ts" +"%Y-%m-%d %H:%M")"
- send_line "PRIVMSG $channel :$date_stamp ${reminders[$ts]}"
+ send_privmsg $channel "$date_stamp ${reminders[$ts]}"
done
}