diff options
author | Joseph Graham <joseph@fibreglass.tunachunks> | 2013-07-28 10:40:48 +0100 |
---|---|---|
committer | Joseph Graham <joseph@fibreglass.tunachunks> | 2013-07-28 10:40:48 +0100 |
commit | 5a2a44f46844bda90ea2b57f025a4137fb45cf15 (patch) | |
tree | 35d1352f05575c52dac29e039f95824b94232b5f /hack_of_all_hacks | |
parent | ee12ef58ef2dbe3cb47c39f519e8f1708dcdf29e (diff) |
added a feature to send people messages
Diffstat (limited to 'hack_of_all_hacks')
-rw-r--r-- | hack_of_all_hacks | 106 |
1 files changed, 71 insertions, 35 deletions
diff --git a/hack_of_all_hacks b/hack_of_all_hacks index 3592e51..c7473ae 100644 --- a/hack_of_all_hacks +++ b/hack_of_all_hacks @@ -113,6 +113,17 @@ EOF fi fi + + # If someone has sent this person a message then echo it to them. + if [[ -f "announcements/people/${personoslash}/messages" ]] + then + uniq "announcements/people/${personoslash}/messages" | + while read line + do + send_msg "${channel_it_came_from}" "${personoslash}: ${line}" + done + rm "announcements/people/${personoslash}/messages" + fi # Record that the person has been seen, and when. touch "announcements/people/${personoslash}/seen" @@ -155,43 +166,68 @@ EOF # Seen # ######## + shopt -s extglob + # This one depends on the previous to record the last time the person # was seen and create the `the_time_now' var. - if [[ ${line} == *"pbot: when did you last see"* ]] - then - subject="${line##*pbot: when did you last see }" - subject="${subject%?}" - subject="${subject%% *}" - if [[ -f announcements/people/${subject}/seen ]] - then - seconds_ago_seen="$(( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ))" - minutes_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 60 ))" - hours_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 3600 ))" - days_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 86400 ))" - months_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 2592000 ))" - years_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 946080000 ))" - if (( seconds_ago_seen < 120 )) - then - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${seconds_ago_seen} seconds ago." - elif (( minutes_ago_seen < 120 )) - then - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${minutes_ago_seen} minutes ago." - elif (( hours_ago_seen < 48 )) - then - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${hours_ago_seen} hours ago." - elif (( days_ago_seen < 60 )) - then - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${days_ago_seen} days ago." - elif (( months_ago_seen < 24 )) - then - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${months_ago_seen} months ago." - else - send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${years_ago_seen} years ago." - fi - else - send_msg "${channel_it_came_from}" "I never saw ${subject} speak." - fi - fi + case "${line}" in + *"pbot: when did you last see"* ) + subject="${line##*pbot: when did you last see }" + subject="${subject##*pbot: when did you last see: }" # If there's an `:', we can still handle it. + subject="${subject%?}" + subject="${subject%% *}" + if [[ -f announcements/people/${subject}/seen ]] + then + seconds_ago_seen="$(( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ))" + minutes_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 60 ))" + hours_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 3600 ))" + days_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 86400 ))" + months_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 2592000 ))" + years_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subject}/seen ) ) / 946080000 ))" + if (( seconds_ago_seen < 120 )) + then + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${seconds_ago_seen} seconds ago." + elif (( minutes_ago_seen < 120 )) + then + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${minutes_ago_seen} minutes ago." + elif (( hours_ago_seen < 48 )) + then + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${hours_ago_seen} hours ago." + elif (( days_ago_seen < 60 )) + then + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${days_ago_seen} days ago." + elif (( months_ago_seen < 24 )) + then + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${months_ago_seen} months ago." + else + send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${years_ago_seen} years ago." + fi + else + send_msg "${channel_it_came_from}" "I never saw ${subject} speak." + fi + ;; + *"pbot: tell "+([[:alnum:]])":"* ) + # The line will be something such as: + # pbot: tell fauno: you suck + process="${line##*pbot: tell }" + subject="${process%%:*}" + message="${process#*:}" + message="${message# }" + + echo "${personoslash} told me to tell you: ${message}" >> "announcements/people/${subject}/messages" + send_msg "${channel_it_came_from}" "${personoslash}: certainly" + ;; + *pbot:* ) + while read line + do + send_msg "${channel_it_came_from}" "${line}" + done <<< cat << EOF +Command not recognised. Example commands: +pbot: tell fauno: you suck +pbot: when did you last see aurelien? +EOF + ;; + esac # TODO: add a birthday announcement feature, cointoss feature, timer # feature, tell so and so this feature, store phrase feature. |