summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Graham <joseph@fibreglass.tunachunks>2014-07-02 08:42:30 +0100
committerJoseph Graham <joseph@fibreglass.tunachunks>2014-07-02 08:42:30 +0100
commit1aee8e7fa935eef50101d2280a96425a9d179eeb (patch)
tree34012d8cb4673e30b7e7ce7bff8e42d44fc177fb
parentf8fb6cc2fd8f046652978dc0748f567be7dcd5fe (diff)
Improved the messages system.
Made him tell how long ago the message was sent. Made him handle nicks case-insensitively. Made him give a warning if someone tries to send a message to someone who's not present.
-rw-r--r--hack_of_all_hacks100
1 files changed, 74 insertions, 26 deletions
diff --git a/hack_of_all_hacks b/hack_of_all_hacks
index e5039e2..989593f 100644
--- a/hack_of_all_hacks
+++ b/hack_of_all_hacks
@@ -41,6 +41,7 @@ function l33t_codes
# Remove any forward slashes.
personoslash="${person//\/}"
+ declare -l personoslashlower="${personoslash}"
channel_it_came_from="$( echo ${line} | cut -d ' ' -f 3 )"
@@ -77,7 +78,7 @@ function l33t_codes
# Make sure they have not already been recommended to the bug
# tracker less than one day ago.
- if [[ -f announcements/people/${personoslash}/seen ]] && (( ( $( stat -c %Y announcements/people/${personoslash}/shared_libs ) + 86400 ) > the_time_now ))
+ if [[ -f announcements/people/${personoslashlower}/seen ]] && (( ( $( stat -c %Y announcements/people/${personoslashlower}/shared_libs ) + 86400 ) > the_time_now ))
then
yepyep=0
fi
@@ -85,7 +86,7 @@ function l33t_codes
if (( yepyep ))
then
send_msg "${channel_it_came_from}" "${person}: please report a bug, specifying the exact error message, package of the failing command and architecture: http://labs.parabola.nu"
- touch "announcements/people/${personoslash}/shared_libs"
+ touch "announcements/people/${personoslashlower}/shared_libs"
fi
fi
@@ -115,11 +116,11 @@ function l33t_codes
#################
# Make this person a folder if they don't already have one.
- if ! [[ -d "announcements/people/${personoslash}" ]]
+ if ! [[ -d "announcements/people/${personoslashlower}" ]]
then
- mkdir -p "announcements/people/${personoslash}"
- touch "announcements/people/${personoslash}/phrases"
- cat << EOF > "announcements/people/${personoslash}/settings"
+ mkdir -p "announcements/people/${personoslashlower}"
+ touch "announcements/people/${personoslashlower}/phrases"
+ cat << EOF > "announcements/people/${personoslashlower}/settings"
enabled=yes
locked=no
EOF
@@ -129,32 +130,66 @@ EOF
# If this person has announcements enabled and there is at least one
# phrase in their file and their seen log exists.
- if grep 'enabled=yes' "announcements/people/${personoslash}/settings" > \
- /dev/null && (( $( wc -l "announcements/people/${personoslash}/phrases" | cut -d ' ' -f 1 ) )) && [[ -f announcements/people/${personoslash}/seen ]]
+ if grep 'enabled=yes' "announcements/people/${personoslashlower}/settings" > \
+ /dev/null && (( $( wc -l "announcements/people/${personoslashlower}/phrases" | cut -d ' ' -f 1 ) )) && [[ -f "announcements/people/${personoslashlower}/seen" ]]
then
# Check if they were last present more than three hours ago.
- if (( ( $( stat -c %Y announcements/people/${personoslash}/seen ) +
+ if (( ( $( stat -c %Y "announcements/people/${personoslashlower}/seen" ) +
10800 ) < the_time_now ))
then
send_msg "${channel_it_came_from}" \
- "$( shuf "announcements/people/${personoslash}/phrases" | head -1 )"
+ "$( shuf "announcements/people/${personoslashlower}/phrases" | head -1 )"
fi
fi
- # If someone has sent this person a message then echo it to them.
- if [[ -f "announcements/people/${personoslash}/messages" ]]
+ # If someone has sent this person a message then echo it to
+ # them.
+ if [[ -f "announcements/people/${personoslashlower}/messages" ]]
then
- uniq "announcements/people/${personoslash}/messages" |
+ uniq "announcements/people/${personoslashlower}/messages" |
while read line
do
- send_msg "${channel_it_came_from}" "${personoslash}: ${line}"
+ # The first field is the time, in *nix seconds, that
+ # the message was sent. The second is the name of the
+ # sender. And the rest is the message.
+ intermediate="${line#* }"
+ sender_u="${intermediate%% *}"
+ message_u="${intermediate#* }"
+ time_sent="${line%% *}"
+
+ seconds_ago_seen="$(( the_time_now - time_sent ))"
+ minutes_ago_seen="$(( ( the_time_now - time_sent ) / 60 ))"
+ hours_ago_seen="$(( ( the_time_now - time_sent ) / 3600 ))"
+ days_ago_seen="$(( ( the_time_now - time_sent ) / 86400 ))"
+ months_ago_seen="$(( ( the_time_now - time_sent ) / 2592000 ))"
+ years_ago_seen="$(( ( the_time_now - time_sent ) / 31104000 ))"
+ if (( seconds_ago_seen < 120 ))
+ then
+ units="${seconds_ago_seen} seconds"
+ elif (( minutes_ago_seen < 120 ))
+ then
+ units="${minutes_ago_seen} minutes"
+ elif (( hours_ago_seen < 48 ))
+ then
+ units="${hours_ago_seen} hours"
+ elif (( days_ago_seen < 60 ))
+ then
+ units="${days_ago_seen} days"
+ elif (( months_ago_seen < 24 ))
+ then
+ units="${months_ago_seen} months"
+ else
+ units="${years_ago_seen} years"
+ fi
+
+ send_msg "${channel_it_came_from}" "${personoslash}: ${sender_u} told me to tell you, (${units} ago): ${message_u}"
done
- rm "announcements/people/${personoslash}/messages"
+ rm "announcements/people/${personoslashlower}/messages"
fi
# Record that the person has been seen, and when.
- touch "announcements/people/${personoslash}/seen"
+ touch "announcements/people/${personoslashlower}/seen"
#####################
# Page title getter #
@@ -209,17 +244,19 @@ EOF
subject="${subject##${my_own_name}: when did you last see: }" # If there's an `:', we can still handle it.
subject="${subject%\?}"
subject="${subject%% *}"
+ declare -l subjectlower="${subject}"
+
if [[ "${subject}" == ${my_own_name} ]]
then
send_msg "${channel_it_came_from}" "I last saw ${subject} speak 0 seconds ago."
- elif [[ -f announcements/people/${subject}/seen ]]
+ elif [[ -f "announcements/people/${subjectlower}/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 ) ) / 31104000 ))"
+ seconds_ago_seen="$(( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ))"
+ minutes_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ) / 60 ))"
+ hours_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ) / 3600 ))"
+ days_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ) / 86400 ))"
+ months_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ) / 2592000 ))"
+ years_ago_seen="$(( ( the_time_now - $( stat -c %Y announcements/people/${subjectlower}/seen ) ) / 31104000 ))"
if (( seconds_ago_seen < 120 ))
then
send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${seconds_ago_seen} seconds ago."
@@ -252,13 +289,24 @@ EOF
if [[ "${subject}" == "${my_own_name}" ]]
then
- send_msg "${channel_it_came_from}" "${my_own_name}: ${personoslash} told me to tell you: ${message}"
+ send_msg "${channel_it_came_from}" "${my_own_name}: ${personoslash} told me to tell you, (0 seconds ago): ${message}"
else
- [[ -d "announcements/people/${subject}" ]] || mkdir -p "announcements/people/${subject}"
- echo "${personoslash} told me to tell you: ${message}" >> "announcements/people/${subject}/messages"
+ declare -l subjectlower="${subject}"
+
+ [[ -d "announcements/people/${subjectlower}" ]] || mkdir -p "announcements/people/${subjectlower}"
+ # The time in *nix seconds is saved there so that
+ # pbot can say how long ago the massage was sent
+ # when he gives it to it's recipient.
+ echo "$(date +%s) ${personoslash} ${message}" >> "announcements/people/${subjectlower}/messages"
response=$(shuf -e 'certainly' 'I will do' 'OK' | head -1)
+
send_msg "${channel_it_came_from}" "${personoslash}: ${response}"
+
+ if ! [[ -f "announcements/people/${subjectlower}/seen" ]]
+ then
+ send_msg "${channel_it_came_from}" "${personoslash}: WARNING: I HAVE NEVER SEEN \"${subject}\" HERE BEFORE. CHECK YOUR SPELLING."
+ fi
fi
;;
"${my_own_name}: "+([!/])" is "+([![:space:]])* )