summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hack_of_all_hacks214
1 files changed, 106 insertions, 108 deletions
diff --git a/hack_of_all_hacks b/hack_of_all_hacks
index 2a31a4c..7b55b63 100644
--- a/hack_of_all_hacks
+++ b/hack_of_all_hacks
@@ -33,6 +33,35 @@ function tell_fact # thing channel
source common_codez
+function remember_fact
+{
+ if grep "^${is}$" "info/${thing}" &>/dev/null
+ then
+ send_msg "${channel_it_came_from}" "${personoslash}: I know."
+ else
+ echo "${is}" >> "info/${thing}"
+ send_msg "${channel_it_came_from}" "${personoslash}: Remembered."
+ fi
+}
+
+function forget_fact
+{
+ number_of_matching_lines=$(grep -c "^${isnt}" "info/${thing}")
+
+ case "${number_of_matching_lines}" in
+ 0 )
+ send_msg "${channel_it_came_from}" "${personoslash}: I know."
+ ;;
+ 1 )
+ grep -v "^${isnt}" "info/${thing}" | sponge "info/${thing}"
+ send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed."
+ ;;
+ * )
+ send_msg "${channel_it_came_from}" "${personoslash}: Ambiguos."
+ ;;
+ esac
+}
+
function l33t_codes
{
my_own_name='pbot'
@@ -63,7 +92,28 @@ function l33t_codes
send_msg "${channel_it_came_from}" "${line_filtered}"
injected_data=1
else
+ ###############################################################
+ # This is a message from a user. Make preperations to process #
+ ###############################################################
+
+ the_time_now=$(date +%s)
+
+ # Make this person a folder if they don't already have one.
+ if ! [[ -d "announcements/people/${personoslashlower}" ]]
+ then
+ mkdir -p "announcements/people/${personoslashlower}"
+ fi
+ # Record that the person has been seen, and when.
+ touch "announcements/people/${personoslashlower}/seen"
+
+ shopt -s extglob
+
+ # We want to get only the message part of the line
+ sentence="${line#* }"
+ sentence="${sentence#* }"
+ sentence="${sentence#* :}"
+
##########################
# Shared libraries error #
##########################
@@ -72,21 +122,25 @@ function l33t_codes
# If someone complains about error while loading shared libraries error
# then recomend them to the bug tracker.
- if [[ ${line} == *"error while loading shared libraries"* ]]
+ if [[ ${sentence} == *"error while loading shared libraries"* ]]
then
- yepyep=1
-
# Make sure they have not already been recommended to the bug
# tracker less than one day ago.
- if [[ -f announcements/people/${personoslashlower}/seen ]] && (( ( $( stat -c %Y announcements/people/${personoslashlower}/shared_libs ) + 86400 ) > the_time_now ))
+ sharlibsrecfile="announcements/people/${personoslashlower}/shared_libs"
+
+ # Have we recommended them to the bug tracker before?
+ if [[ -f ${sharlibsrecfile} ]]
then
- yepyep=0
+ # Was it less than a day ago?
+ (( ( $( stat -c %Y ${sharlibsrecfile} ) + 86400 ) > the_time_now )) && rec_recent=1 || rec_recent=0
+ else
+ rec_recent=0
fi
- if (( yepyep ))
+ if ! (( rec_recent ))
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/${personoslashlower}/shared_libs"
+ touch "${sharlibsrecfile}"
fi
fi
@@ -94,35 +148,24 @@ function l33t_codes
# Repeat #
##########
- stuff_said="$( echo ${line} | cut --complement -d ' ' -f 1,2,3 )"
- stuff_said="${stuff_said#:}"
-
- [[ ${stuff_said} != ${i_repeated} ]] && say_again=yesyes
+ [[ ${sentence} != ${i_repeated} ]] && say_again=yesyes
# If two different people say the same thing in a row then say it again
# for fun.
- if [[ ${stuff_said} == ${lastline} ]] && [[ ${person} != ${lastsender} ]] && [[ ${say_again} != nono ]] && [[ ${stuff_said} != "${my_own_name}: "* ]] # If two different people say the same thing to me in quick sucession I shouldn't repeat them.
+ if [[ ${sentence} == ${lastline} ]] && [[ ${person} != ${lastsender} ]] && [[ ${say_again} != nono ]] && [[ ${sentence} != "${my_own_name}: "* ]] # If two different people say the same thing to me in quick sucession I shouldn't repeat them.
then
- send_msg "${channel_it_came_from}" "${stuff_said}"
- i_repeated="${stuff_said}"
+ send_msg "${channel_it_came_from}" "${sentence}"
+ i_repeated="${sentence}"
say_again=nono
fi
- lastline="${stuff_said}"
+ lastline="${sentence}"
lastsender="${person}"
#################
# Announcements #
#################
- # Make this person a folder if they don't already have one.
- if ! [[ -d "announcements/people/${personoslashlower}" ]]
- then
- mkdir -p "announcements/people/${personoslashlower}"
- fi
-
- the_time_now=$(date +%s)
-
# If someone has sent this person a message then echo it to
# them.
if [[ -f "announcements/people/${personoslashlower}/messages" ]]
@@ -168,57 +211,38 @@ function l33t_codes
rm "announcements/people/${personoslashlower}/messages"
fi
- # Record that the person has been seen, and when.
- touch "announcements/people/${personoslashlower}/seen"
-
#####################
# Page title getter #
#####################
- # If pbot is present record it.
- #[[ ${sender%%!*} == pbot ]] && echo yes > pbot_present # commented out because pbot-ng now uses the pbot nickname
-
# We don't want to get the page title if it's injected data.
if [[ ${line} =~ http://[^\ ]+ ]] || [[ ${line} =~ https://[^\ ]+ ]] &&
(( ! injected_data ))
then
url_to_get="${BASH_REMATCH}"
- # If pbot is not present.
- if true #grep no pbot_present > /dev/null
- then
- the_title=$(
- curl -L --compressed "${url_to_get}" 2> /dev/null |
- while rdom
- do
- if [[ ${element} = title ]] || [[ ${element} = TITLE ]]
- then
- sed 's/ / /g' <<< "${content}" | replace_wierd_html_chars
- fi
- done
- )
+ the_title=$(
+ curl -L --compressed "${url_to_get}" 2> /dev/null |
+ while rdom
+ do
+ if [[ ${element} = title ]] || [[ ${element} = TITLE ]]
+ then
+ sed 's/ / /g' <<< "${content}" | replace_wierd_html_chars
+ fi
+ done
+ )
- if ! [[ -z ${the_title} ]]
- then
- send_msg "${channel_it_came_from}" "Page title: \`${the_title}'"
- fi
+ if ! [[ -z ${the_title} ]]
+ then
+ send_msg "${channel_it_came_from}" "Page title: \`${the_title}'"
fi
fi
- ########
- # Seen #
- ########
-
- shopt -s extglob
-
- # We want to get only the message part of the line
- sentence="${line#* }"
- sentence="${sentence#* }"
- sentence="${sentence#* :}"
-
- # This one depends on the previous to record the last time the person
- # was seen and create the `the_time_now' var.
case "${sentence}" in
+ ########
+ # Seen #
+ ########
+
"${my_own_name}: when did you last see"* )
subject="${sentence##${my_own_name}: when did you last see }"
subject="${subject##${my_own_name}: when did you last see: }" # If there's an `:', we can still handle it.
@@ -259,7 +283,11 @@ function l33t_codes
send_msg "${channel_it_came_from}" "I never saw ${subject} speak."
fi
;;
- "${my_own_name}: tell "+([![:space:]])": "+([![:space:]])* )
+ ########
+ # tell #
+ ########
+
+ "${my_own_name}: tell "+([![:space:]])": "+([![:space:]])* )
# The line will be something such as:
# pbot: tell fauno: you suck
process="${sentence##${my_own_name}: tell }"
@@ -289,81 +317,48 @@ function l33t_codes
fi
fi
;;
+ ############
+ # factoids #
+ ############
+
"${my_own_name}: "+([!/])" is "+([![:space:]])* )
declare -l thing="${sentence#${my_own_name}: }"
thing="${thing%% is *}"
is="${sentence#* is }"
- if grep "^${is}$" "info/${thing}" &>/dev/null
- then
- send_msg "${channel_it_came_from}" "${personoslash}: I know."
- else
- echo "${is}" >> "info/${thing}"
- send_msg "${channel_it_came_from}" "${personoslash}: Remembered."
- fi
+ remember_fact
;;
"${my_own_name}: "+([!/])" is: "+([![:space:]])* )
declare -l thing="${sentence#${my_own_name}: }"
thing="${thing%% is: *}"
is="${sentence#* is: }"
- if grep "^${is}$" "info/${thing}" &>/dev/null
- then
- send_msg "${channel_it_came_from}" "${personoslash}: I know."
- else
- echo "${is}" >> "info/${thing}"
- send_msg "${channel_it_came_from}" "${personoslash}: Remembered."
- fi
+ remember_fact
;;
"${my_own_name}: "+([![:space:]])" isn't "+([![:space:]])* )
declare -l thing="${sentence#${my_own_name}: }"
thing="${thing%% isn\'t *}"
isnt="${sentence#* isn\'t }"
- number_of_matching_lines=$(grep -c "^${isnt}" "info/${thing}")
-
- case "${number_of_matching_lines}" in
- 0 )
- send_msg "${channel_it_came_from}" "${personoslash}: I know."
- ;;
- 1 )
- grep -v "^${isnt}" "info/${thing}" | sponge "info/${thing}"
- send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed."
- ;;
- * )
- send_msg "${channel_it_came_from}" "${personoslash}: Ambiguos."
- ;;
- esac
+ forget_fact
;;
"${my_own_name}: "+([![:space:]])" isn't: "+([![:space:]])* )
declare -l thing="${sentence#${my_own_name}: }"
thing="${thing%% isn\'t: *}"
isnt="${sentence#* isn\'t: }"
- number_of_matching_lines=$(grep -c "^${isnt}" "info/${thing}")
-
- case "${number_of_matching_lines}" in
- 0 )
- send_msg "${channel_it_came_from}" "${personoslash}: I know."
- ;;
- 1 )
- grep -v "^${isnt}" "info/${thing}" | sponge "info/${thing}"
- send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed."
- ;;
- * )
- send_msg "${channel_it_came_from}" "${personoslash}: Ambiguos."
- ;;
- esac
+ forget_fact
;;
','+([!/]) )
thing="${sentence#,}"
tell_fact "${thing}" "${channel_it_came_from}"
;;
+ #############
+ # Footnotes #
+ #############
+
*\[[[:digit:]]\]* )
- #############
- # Footnotes #
- #############
declare -a fn
while read -d $'\0' file
@@ -390,7 +385,11 @@ function l33t_codes
send_msg "${channel_it_came_from}" "[${n}] ${str}"
done
;;
- ${my_own_name}:* | ','* )
+ ########################
+ # unrecognised command #
+ ########################
+
+ ${my_own_name}:* | ','* )
while read line
do
send_msg "${personoslash}" "${line}"
@@ -406,8 +405,7 @@ EOF
;;
esac
-# ' I put this comment here to fix a bug in emacs shell-script-mode that causes the display
-# to get messed up
+# ' this comment fixes a bug in emacs shell-script-mode that messes up the syntax highlighting
###########################
# answer nicks over query #