summaryrefslogtreecommitdiff
path: root/hack_of_all_hacks
diff options
context:
space:
mode:
authorJoe <joe@joelightning.com>2011-11-10 11:31:23 +0000
committerJoe <joe@joelightning.com>2011-11-10 11:31:23 +0000
commitc40170cb03e41bd1efe775bbd430a50da6cdeea4 (patch)
tree0cc4c0f5cc41c502a0dff8fdca124cab2bd0dab5 /hack_of_all_hacks
First commit, pbot-ng already works.
Diffstat (limited to 'hack_of_all_hacks')
-rw-r--r--hack_of_all_hacks165
1 files changed, 165 insertions, 0 deletions
diff --git a/hack_of_all_hacks b/hack_of_all_hacks
new file mode 100644
index 0000000..0c4e026
--- /dev/null
+++ b/hack_of_all_hacks
@@ -0,0 +1,165 @@
+#! /bin/bash
+
+# This function reads tags of xml in the same way read normally reads lines.
+function rdom
+{
+ local IFS=\>
+ read -d \< element content
+}
+
+
+function l33t_codes
+{
+ person="${sender%%!*}"
+
+ ##########################
+ # Shared libraries error #
+ ##########################
+
+ if [[ ${line} == *"error while loading shared libraries"* ]]
+ then
+ send_msg '#parabola' "${person}: please report a bug, specifying exact error message, package of the failing command and architecture"
+ fi
+
+ ##########
+ # Repeat #
+ ##########
+
+ # If two different people say the same thing in a row then say it again
+ # for fun.
+ if [[ ${line##*PRIVMSG} == ${lastline} ]] && [[ ${person} != ${lastsender} ]]
+ then
+ send_msg '#parabola' "${line##*PRIVMSG}"
+ fi
+
+ lastline="${line##*PRIVMSG}"
+ lastsender="${person}"
+
+ #################
+ # Announcements #
+ #################
+
+ # Remove any forward slashes.
+ personoslash="${person//\/}"
+
+ # Make this person a folder if they don't already have one.
+ if ! [[ -d "announcements/people/${personoslash}" ]]
+ then
+ mkdir -p "announcements/people/${personoslash}"
+ touch "announcements/people/${personoslash}/phrases"
+ cat << EOF > "announcements/people/${personoslash}/settings"
+enabled=yes
+locked=no
+EOF
+ fi
+
+ the_time_now=$(date +%s)
+
+ # 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 ]]
+ then
+ # Check if they were last present more than three hours ago.
+ if (( ( $( stat -c %Y announcements/people/${personoslash}/seen ) +
+ 10800 ) < the_time_now ))
+ then
+ send_msg '#parabola' \
+ "$( shuf "announcements/people/${personoslash}/phrases" | head -1 )"
+ fi
+
+ fi
+
+ # Record that the person has been seen, and when.
+ touch "announcements/people/${personoslash}/seen"
+
+ ########
+ # Seen #
+ ########
+
+ # This one depends on the previous to record the last time the person was
+ # seen and create the `the_time_now' var.
+ if [[ ${line} == *"pbots_friend: when did you last see"* ]]
+ then
+ subject="${line##*pbots_friend: 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 '#parabola' "I last saw ${subject} speak ${seconds_ago_seen} seconds ago."
+ elif (( minutes_ago_seen < 120 ))
+ then
+ send_msg '#parabola' "I last saw ${subject} speak ${minutes_ago_seen} minutes ago."
+ elif (( hours_ago_seen < 48 ))
+ then
+ send_msg '#parabola' "I last saw ${subject} speak ${hours_ago_seen} hours ago."
+ elif (( days_ago_seen < 60 ))
+ then
+ send_msg '#parabola' "I last saw ${subject} speak ${days_ago_seen} days ago."
+ elif (( months_ago_seen < 24 ))
+ then
+ send_msg '#parabola' "I last saw ${subject} speak ${months_ago_seen} months ago."
+ else
+ send_msg '#parabola' "I last saw ${subject} speak ${years_ago_seen} years ago."
+ fi
+ else
+ send_msg '#parabola' "I never saw ${subject} speak."
+ fi
+ fi
+
+ ######################
+ # Echo injected data #
+ ######################
+
+ # Should send a message like: echo 'This is the message' > /tmp/un-provoked-message-store
+
+ line_half_filtered="${line##*PRIVMSG}"
+ line_filtered=${line_half_filtered##* :}
+
+ if [[ ${personoslash} == tlCJ99mfZl ]]
+ then
+ send_msg '#parabola' "${line_filtered}"
+ fi
+
+ # TODO: add a birthday announcement feature, cointoss feature, timer
+ # feature.
+
+ #####################
+ # Page title getter #
+ #####################
+
+ if [[ ${line} =~ http://[^\ ]+ ]] || [[ ${line} =~ https://[^\ ]+ ]]
+ then
+ url_to_get="${BASH_REMATCH}"
+
+ the_title=$(
+ curl -L --compressed "${url_to_get}" 2> /dev/null |
+ while rdom
+ do
+ if [[ ${element} = title ]]
+ then
+ echo "${content}" | sed 's/&mdash;/—/g ; s/&lt;/</g ; s/&gt;/>/g ; s/&amp;/&/g ; s/&quot;/"/g'
+ fi
+ done
+ )
+
+ if ! [[ -z ${the_title} ]]
+ then
+ send_msg '#parabola' "The title of that page is: \`${the_title}'"
+ fi
+ fi
+
+ #########
+ # Tests #
+ #########
+
+ #echo "${line}"
+}