summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2018-08-01 19:22:54 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2018-08-11 17:03:42 -0400
commit40e4364d2ce81252774c3111f37c317053b43ded (patch)
treee149822300dd88012910e716b53799141657b556
parentff6119f99a9a4c804936a8e07f69a2d94795a77a (diff)
normalize whitespace
-rw-r--r--lib/channels.sh48
-rw-r--r--process_event729
2 files changed, 414 insertions, 363 deletions
diff --git a/lib/channels.sh b/lib/channels.sh
index df38c55..512cfcb 100644
--- a/lib/channels.sh
+++ b/lib/channels.sh
@@ -36,10 +36,10 @@ channels_current=""
## @param Is a channel key, if any.
#---------------------------------------------------------------------
channels_join() {
- local channel="$1"
- local key=""
- [[ -n "$2" ]] && key=" $2"
- send_raw "JOIN ${channel}${key}"
+ local channel="$1"
+ local key=""
+ [[ -n "$2" ]] && key=" $2"
+ send_raw "JOIN ${channel}${key}"
}
#---------------------------------------------------------------------
@@ -49,10 +49,10 @@ channels_join() {
## @param Is a reason.
#---------------------------------------------------------------------
channels_part() {
- local channel="$1"
- local reason=""
- [[ -n "$2" ]] && reason=" :$2"
- send_raw "PART ${channel}${reason}"
+ local channel="$1"
+ local reason=""
+ [[ -n "$2" ]] && reason=" :$2"
+ send_raw "PART ${channel}${reason}"
}
###########################################################################
@@ -67,7 +67,7 @@ channels_part() {
## @param The channel to add
#---------------------------------------------------------------------
channels_add() {
- channels_current+=" $1"
+ channels_current+=" $1"
}
#---------------------------------------------------------------------
@@ -77,7 +77,7 @@ channels_add() {
## @param The channel to remove
#---------------------------------------------------------------------
channels_remove() {
- list_remove channels_current "$1" channels_current
+ list_remove channels_current "$1" channels_current
}
#---------------------------------------------------------------------
@@ -88,11 +88,11 @@ channels_remove() {
## @param Reason (ignored).
#---------------------------------------------------------------------
channels_handle_part() {
- local whoparted=
- parse_hostmask_nick "$1" 'whoparted'
- if [[ $whoparted == $server_nick_current ]]; then
- channels_remove "$2"
- fi
+ local whoparted=
+ parse_hostmask_nick "$1" 'whoparted'
+ if [[ $whoparted == $server_nick_current ]]; then
+ channels_remove "$2"
+ fi
}
#---------------------------------------------------------------------
@@ -104,10 +104,10 @@ channels_handle_part() {
## @param Reason (ignored).
#---------------------------------------------------------------------
channels_handle_kick() {
- local whogotkicked="$3"
- if [[ $whogotkicked == $server_nick_current ]]; then
- channels_remove "$2"
- fi
+ local whogotkicked="$3"
+ if [[ $whogotkicked == $server_nick_current ]]; then
+ channels_remove "$2"
+ fi
}
#---------------------------------------------------------------------
@@ -117,9 +117,9 @@ channels_handle_kick() {
## @param Channel joined.
#---------------------------------------------------------------------
channels_handle_join() {
- local whojoined=
- parse_hostmask_nick "$1" 'whojoined'
- if [[ $whojoined == $server_nick_current ]]; then
- channels_add "$2"
- fi
+ local whojoined=
+ parse_hostmask_nick "$1" 'whojoined'
+ if [[ $whojoined == $server_nick_current ]]; then
+ channels_add "$2"
+ fi
}
diff --git a/process_event b/process_event
index 7d93ed5..23e73ea 100644
--- a/process_event
+++ b/process_event
@@ -77,373 +77,424 @@ function process_event
# If it's a private message
[[ "${channel_it_came_from}" == "${my_own_name}" ]] && channel_it_came_from="${personoslash}"
+
######################
# Echo injected data #
######################
# Should send a message like: echo 'This is the message' > /tmp/un-provoked-message-store
-
injected_data=0
-
line_filtered=${line##*PRIVMSG +([![:space:]]) :}
if [[ ${personoslash} == tlCJ99mfZl ]]
then
- 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 #
- ##########################
-
- the_time_now=$(date +%s)
-
- # If someone complains about error while loading shared libraries error
- # then recomend them to the bug tracker.
- if [[ ${sentence} == *"error while loading shared libraries"* ]]
- then
- # Make sure they have not already been recommended to the bug
- # tracker less than one day ago.
- sharlibsrecfile="announcements/people/${personoslashlower}/shared_libs"
-
- # Have we recommended them to the bug tracker before?
- if [[ -f ${sharlibsrecfile} ]]
- then
- # 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 ! (( 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 "${sharlibsrecfile}"
- fi
- fi
-
- ##########
- # Repeat #
- ##########
-
- [[ ${sentence} != ${i_repeated} ]] && say_again=yesyes
-
- # If two different people say the same thing in a row then say it again
- # for fun.
- 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}" "${sentence}"
- i_repeated="${sentence}"
- say_again=nono
- fi
-
- lastline="${sentence}"
- lastsender="${person}"
-
- #################
- # Announcements #
- #################
-
- # If someone has sent this person a message then echo it to
- # them.
- if [[ -f "announcements/people/${personoslashlower}/messages" ]]
+ send_msg "${channel_it_came_from}" "${line_filtered}"
+ injected_data=1
+ fi
+ # NOTE: this 'injected_data' clause is apparently the IPC mechanism
+ # used by the ./labs_change_detector script
+ # see ./labs_change_detector, transport/socat.sh, and transport/dev-tcp.sh
+ # the clause above was originally mutually exclusive
+ # with the remaining entirety of this function
+ # and it is the only place where 'injected_data' is set
+ # yet, 'injected_data' is tested below in the 'Page title getter' section
+ # so, presumably this 'injected_data' was intended to fall through?
+
+
+ ###############################################################
+ # 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 #
+ ##########################
+
+ # If someone complains about error while loading shared libraries error
+ # then recomend them to the bug tracker.
+ if [[ ${sentence} == *"error while loading shared libraries"* ]]
+ then
+ # Make sure they have not already been recommended to the bug
+ # tracker less than one day ago.
+ sharlibsrecfile="announcements/people/${personoslashlower}/shared_libs"
+
+ # Have we recommended them to the bug tracker before?
+ if [[ -f ${sharlibsrecfile} ]]
then
- uniq "announcements/people/${personoslashlower}/messages" |
- while read line
- do
- # 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
+ last_time=$( stat -c %Y ${sharlibsrecfile} )
+
+ (( last_time > the_time_now - 86400 )) && rec_recent=1 || rec_recent=0
+ else
+ rec_recent=0
+ fi
+
+ 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 "${sharlibsrecfile}"
+ fi
+ fi
+
+
+ ##########
+ # Repeat #
+ ##########
+
+ [[ ${sentence} != ${i_repeated} ]] && say_again=yesyes
+
+ # If two different people say the same thing in a row then say it again for fun;
+ # unless it was directed at me.
+ if [[ ${sentence} == ${lastline} ]] && [[ ${person} != ${lastsender} ]] && \
+ [[ ${say_again} != nono ]] && [[ ${sentence} != "${my_own_name}: "* ]]
+ then
+ send_msg "${channel_it_came_from}" "${sentence}"
+ i_repeated="${sentence}"
+ say_again=nono
+ fi
+
+ lastline="${sentence}"
+ lastsender="${person}"
+
+
+ #################
+ # Announcements #
+ #################
+
+ # If someone has sent this person a message then echo it to them.
+ if [[ -f "announcements/people/${personoslashlower}/messages" ]]
+ then
+ uniq "announcements/people/${personoslashlower}/messages" |
+ while read line
+ do
+ # 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/${personoslashlower}/messages"
+ fi
+
+
+ #####################
+ # Page title getter #
+ #####################
+
+ # We don't want to get the page title if it's injected data
+ # nor if it probably came from a spambot
+ if [[ ${line} =~ http://[^\ ]+ ]] || [[ ${line} =~ https://[^\ ]+ ]] && (( ! injected_data ))
+ then
+ url_to_get="${BASH_REMATCH}"
+ 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
- rm "announcements/people/${personoslashlower}/messages"
+ )
+
+ if ! [[ -z ${the_title} ]]
+ then
+ send_msg "${channel_it_came_from}" "Page title: \`${the_title}'"
fi
-
- #####################
- # Page title getter #
- #####################
-
- # 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}"
-
- 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
- fi
-
- 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.
- subject="${subject%\?}"
- subject="${subject%% *}"
- declare -l subjectlower="${subject}"
+ fi
+
+
+ ######################
+ # main chat triggers #
+ ######################
+
+ case "${sentence}" in
+
- if [[ "${subject}" == ${my_own_name} ]]
+ #########
+ # hello #
+ #########
+
+ hello|hi)
+ send_msg "${channel_it_came_from}" "hello ${person}, it works!!!"
+ ;;
+
+
+ ########
+ # 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.
+ 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/${subjectlower}/seen" ]]
+ then
+ 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."
+ 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 0 seconds ago."
- elif [[ -f "announcements/people/${subjectlower}/seen" ]]
- then
- 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."
- 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
- ;;
- ########
- # tell #
- ########
-
- "${my_own_name}: tell "+([![:space:]])":"+([[:space:]])+([![:space:]])* )
- # The line will be something such as:
- # pbot: tell fauno: you suck
- process="${sentence##${my_own_name}: tell }"
- subject="${process%%:*}"
- message="${process#*:}"
- message="${message# }"
-
- if [[ "${subject}" == "${my_own_name}" ]]
+ 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}" "${my_own_name}: ${personoslash} told me to tell you, (0 seconds ago): ${message}"
+ 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
- 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='certainly'
-
- 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
+ send_msg "${channel_it_came_from}" "I last saw ${subject} speak ${years_ago_seen} years ago."
fi
- ;;
- ############
- # factoids #
- ############
-
- "${my_own_name}: "+([!/])" is "+([![:space:]])* )
- declare -l thing="${sentence#${my_own_name}: }"
- thing="${thing%% is *}"
- is="${sentence#* is }"
-
- remember_fact
- ;;
- "${my_own_name}: "+([!/])" is: "+([![:space:]])* )
- declare -l thing="${sentence#${my_own_name}: }"
- thing="${thing%% is: *}"
- is="${sentence#* is: }"
-
- remember_fact
- ;;
- "${my_own_name}: "+([![:space:]])" isn't "+([![:space:]])* )
- declare -l thing="${sentence#${my_own_name}: }"
- thing="${thing%% isn\'t *}"
- isnt="${sentence#* isn\'t }"
-
- forget_fact
- ;;
- "${my_own_name}: "+([![:space:]])" isn't: "+([![:space:]])* )
- declare -l thing="${sentence#${my_own_name}: }"
- thing="${thing%% isn\'t: *}"
- isnt="${sentence#* isn\'t: }"
-
- forget_fact
- ;;
- ','+([!/]) )
- thing="${sentence#,}"
-
- tell_fact "${thing}" "${channel_it_came_from}"
- ;;
- #############
- # Footnotes #
- #############
-
- *\[[[:digit:]]\]* )
- declare -a fn
-
- while read -d $'\0' file
- do
- #if match = grep "${file##*/}[ ]\?\[[[:digit:]]\]" <<< "${sentence}"
- filename="${file##*/}"
-
- declare -l lowersentence="${sentence}"
-
- if [[ " ${lowersentence}" =~ [^[:alnum:]]${filename}[\ ]?\[[[:digit:]]\] ]]
- then
- index="${BASH_REMATCH: -2:1}"
-
- fn[${index}]=$(head -1 "${file}")
- fi
- done < <(find info -print0)
-
- for (( n=0 ; n<50 ; n++ ))
- do
- str="${fn[${n}]}"
-
- [[ -z "${str}" ]] && continue
-
- send_msg "${channel_it_came_from}" "[${n}] ${str}"
- done
- ;;
- ########################
- # unrecognised command #
- ########################
-
- ${my_own_name}:* | ','* )
- while read line
- do
- send_msg "${personoslash}" "${line}"
- done <<< cat << EOF
-Command not recognised. Example commands:
-${my_own_name}: tell Jack: hi Jack
-${my_own_name}: when did you last see Jill?
-${my_own_name}: lemon is yummy
-${my_own_name}: lemon isn't yummy
-,lemon
-EOF
- ;;
- esac
+ else
+ send_msg "${channel_it_came_from}" "I never saw ${subject} speak."
+ fi
+ ;;
-# ' this comment fixes a bug in emacs shell-script-mode that messes up the syntax highlighting
- # I'm dissabling this feature for now as it was being abused
- # and would need an overhaul to be abuse-proof + nobody uses it afaik
- # ##########################
- # # tell someone something #
- # ##########################
+ ########
+ # tell #
+ ########
- # # TODO: this should be in the case statement
+ "${my_own_name}: tell "+([![:space:]])":"+([[:space:]])+([![:space:]])* )
+ # The line will be something such as:
+ # pbot: tell fauno: you suck
+ process="${sentence##${my_own_name}: tell }"
+ subject="${process%%:*}"
+ message="${process#*:}"
+ message="${message# }"
- # if [[ "${sentence}" =~ ${my_own_name}: tell\ [^\ ]+\ about\ [^\ ]+ ]]
- # then
- # # TODO: There should be the following three constraints to
- # # prevent abuse.
- # # 1. People may only ask the bot to tell someone about
- # # something in the #parabola channel, not by query.
- # # 2. pbot will only tell someone something if they're a user
- # # he has seen in the past week
- # # 3. each person may use tell no more than 10 times in
- # # three hours.
+ if [[ "${subject}" == "${my_own_name}" ]]
+ then
+ send_msg "${channel_it_came_from}" "${my_own_name}: ${personoslash} told me to tell you, (0 seconds ago): ${message}"
+ else
+ declare -l subjectlower="${subject}"
- # gotit="${BASH_REMATCH}" # will be like: `,tell jack about blah'
+ [[ -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"
- # dudep1="${gotit#,tell }"
- # dude="${dudep1%% *}"
- # thing="${gotit##* }"
+ response='certainly'
- # if [[ -n "${dude}" ]] && [[ -n "${thing}" ]]
- # then
- # tell_fact "${thing}" "${dude}" || send_msg "${channel_it_came_from}" "${personoslash}: Error, failed to tell ${dude} about ${thing}"
- # fi
- # fi
+ send_msg "${channel_it_came_from}" "${personoslash}: ${response}"
- # TODO: add a birthday announcement feature, cointoss feature, timer
- # feature.
+ 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
+ ;;
- #########
- # Tests #
- #########
- #echo "${line}"
- fi
+ ############
+ # factoids #
+ ############
+
+ "${my_own_name}: "+([!/])" is "+([![:space:]])* )
+ declare -l thing="${sentence#${my_own_name}: }"
+ thing="${thing%% is *}"
+ is="${sentence#* is }"
+
+ remember_fact
+ ;;
+ "${my_own_name}: "+([!/])" is: "+([![:space:]])* )
+ declare -l thing="${sentence#${my_own_name}: }"
+ thing="${thing%% is: *}"
+ is="${sentence#* is: }"
+
+ remember_fact
+ ;;
+ "${my_own_name}: "+([![:space:]])" isn't "+([![:space:]])* )
+ declare -l thing="${sentence#${my_own_name}: }"
+ thing="${thing%% isn\'t *}"
+ isnt="${sentence#* isn\'t }"
+
+ forget_fact
+ ;;
+ "${my_own_name}: "+([![:space:]])" isn't: "+([![:space:]])* )
+ declare -l thing="${sentence#${my_own_name}: }"
+ thing="${thing%% isn\'t: *}"
+ isnt="${sentence#* isn\'t: }"
+
+ forget_fact
+ ;;
+ ','+([!/]) )
+ thing="${sentence#,}"
+
+ tell_fact "${thing}" "${channel_it_came_from}"
+ ;;
+
+
+ #############
+ # Footnotes #
+ #############
+
+ *\[[[:digit:]]\]* )
+ declare -a fn
+
+ while read -d $'\0' file
+ do
+ #if match = grep "${file##*/}[ ]\?\[[[:digit:]]\]" <<< "${sentence}"
+ filename="${file##*/}"
+
+ declare -l lowersentence="${sentence}"
+
+ if [[ " ${lowersentence}" =~ [^[:alnum:]]${filename}[\ ]?\[[[:digit:]]\] ]]
+ then
+ index="${BASH_REMATCH: -2:1}"
+
+ fn[${index}]=$(head -1 "${file}")
+ fi
+ done < <(find info -print0)
+
+ for (( n=0 ; n<50 ; n++ ))
+ do
+ str="${fn[${n}]}"
+
+ [[ -z "${str}" ]] && continue
+
+ send_msg "${channel_it_came_from}" "[${n}] ${str}"
+ done
+ ;;
+
+
+ #############
+ # translate #
+ #############
+
+ "${my_own_name}: translate "+([![:space:]])* )
+ local message="${sentence#* translate }"
+ local nick="$(echo "${message%% *}" | tr -d '/')"
+
+ if [[ -n "${nick}" ]] && [[ ${nick} != ${my_own_name} ]]
+ then if [[ -d announcements/people/${nick} ]]
+ then translate_user
+ else translate_message
+ fi
+ fi
+ ;;
+
+
+ ########################
+ # unrecognised command #
+ ########################
+
+ ${my_own_name}:* | ','* )
+ while read line
+ do
+ send_msg "${personoslash}" "${line}"
+ done <<< cat << EOF
+Command not recognised. Example commands:
+${my_own_name}: tell Jack: hi Jack
+${my_own_name}: when did you last see Jill?
+${my_own_name}: lemon is yummy
+${my_own_name}: lemon isn't yummy
+,lemon
+EOF
+ ;;
+ esac
+
+# ' this comment fixes a bug in emacs shell-script-mode that messes up the syntax highlighting
+
+ # I'm dissabling this feature for now as it was being abused
+ # and would need an overhaul to be abuse-proof + nobody uses it afaik
+ # ##########################
+ # # tell someone something #
+ # ##########################
+
+ # # TODO: this should be in the case statement
+
+ # if [[ "${sentence}" =~ ${my_own_name}: tell\ [^\ ]+\ about\ [^\ ]+ ]]
+ # then
+ # # TODO: There should be the following three constraints to
+ # # prevent abuse.
+ # # 1. People may only ask the bot to tell someone about
+ # # something in the #parabola channel, not by query.
+ # # 2. pbot will only tell someone something if they're a user
+ # # he has seen in the past week
+ # # 3. each person may use tell no more than 10 times in
+ # # three hours.
+
+ # gotit="${BASH_REMATCH}" # will be like: `,tell jack about blah'
+
+ # dudep1="${gotit#,tell }"
+ # dude="${dudep1%% *}"
+ # thing="${gotit##* }"
+
+ # if [[ -n "${dude}" ]] && [[ -n "${thing}" ]]
+ # then
+ # tell_fact "${thing}" "${dude}" || send_msg "${channel_it_came_from}" "${personoslash}: Error, failed to tell ${dude} about ${thing}"
+ # fi
+ # fi
+
+ # TODO: add a birthday announcement feature, cointoss feature, timer
+ # feature.
+
+ #########
+ # Tests #
+ #########
+
+ #echo "${line}"
}