# last character of the last element is going to be a \r so remove it
parts[-1]=${parts[-1]%$'\r'}
+ if [[ ${#parts[@]} -lt 4 ]]; then
+ return
+ fi
+
if [[ "${parts[1]}" == "PRIVMSG" ]]; then
sender=${parts[0]}
channel=${parts[2]}
$my_irc_channel)
if [[ ${parts[3]} =~ [:]*$my_irc_nick[:]*$ ]]; then
do_command=1
+ else
+ return
fi
bot_command=${parts[4]}
options="${parts[@]:5}"
add)
add_reminder $channel "$options"
;;
+ del)
+ del_reminder $channel "$options"
+ ;;
list)
list_reminders $channel
;;
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 " del md5sum"
send_privmsg $channel " list - list reminders"
}
send_privmsg $channel "Couldn't parse date/time ${dataparts[0]} ${dataparts[1]}"
else
text="${dataparts[@]:2}"
- send_privmsg $channel "Added reminder for ${dataparts[0]} ${dataparts[1]}: $text"
- reminders[$timestamp]="$text"
+ md5sum=$(echo -n "$timestamp $text" | md5sum | sed -e 's#[ ][ ]*-##;')
+ send_privmsg $channel "Added reminder for [$md5sum] ${dataparts[0]} ${dataparts[1]}: $text"
+ reminders[$timestamp-$md5sum]="$text"
fi
}
check_reminders() {
current_timestamp="$(date +"%s")"
# loop through the reminders keys to see if it's past and alert if so
- for ts in ${!reminders[@]}; do
+ for tsmd5 in ${!reminders[@]}; do
+ ts=${tsmd5%-*}
if [[ $ts -le $current_timestamp ]]; then
- send_privmsg $my_irc_channel "${reminders[$ts]}"
+ send_privmsg $my_irc_channel "${reminders[$tsmd5]}"
# we need to remove this from the array now
- unset "reminders[$ts]"
+ unset "reminders[$tsmd5]"
fi
done
}
list_reminders() {
channel=$1
- for ts in ${!reminders[@]}; do
- date_stamp="$(date --date="@$ts" +"%Y-%m-%d %H:%M")"
- send_privmsg $channel "$date_stamp ${reminders[$ts]}"
+ count=0
+ for tsmd5 in ${!reminders[@]}; do
+ ts=${tsmd5%-*}
+ md5sum=${tsmd5#*-}
+ date_stamp="$(date --date="@$ts" +"%Y-%m-%d %H:%M %Z")"
+ send_privmsg $channel "[$md5sum] $date_stamp ${reminders[$tsmd5]}"
+ count=$((count+1))
done
+
+ if [[ $count -eq 0 ]]; then
+ send_privmsg $channel "There are currently no reminders set, use add to add one."
+ fi
+}
+
+del_reminder() {
+ channel="$1"
+ md5todelete="$2"
+ found=0
+ for tsmd5 in ${!reminders[@]}; do
+ md5sum=${tsmd5#*-}
+ if [[ "$md5sum" == "$md5todelete" ]]; then
+ ts=${tsmd5%-*}
+ date_stamp="$(date --date="@$ts" +"%Y-%m-%d %H:%M %Z")"
+ send_privmsg $channel "Removed reminder [$md5sum] $date_stamp ${reminders[$tsmd5]}"
+ unset "reminders[$tsmd5]"
+ found=1
+ fi
+ done
+ if [[ $found -eq 0 ]]; then
+ send_privmsg $channel "Couldn't find reminder $md5todelete"
+ fi
}
connect_to_server