summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2020-04-12 19:00:41 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2020-06-13 22:05:22 -0400
commit7a068b56884ff18cfb026b5cd47be7db099ea034 (patch)
treec88e7efd7e082fc3c0d5e5c299583e44efb95e4e
parent34c7bb23224670246f6845063d0aa64eafabd35b (diff)
throttle chat commands and triggers
-rw-r--r--TODO8
-rw-r--r--lib/commands.sh6
-rw-r--r--lib/main.sh30
3 files changed, 30 insertions, 14 deletions
diff --git a/TODO b/TODO
index 7602c02..916044b 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,5 @@
-Hi I'm not maintaining this file so I leave the rest verbatim. --xylon
+# TODO: * factor out accessors to announcements/people/* into lib/misc.sh (aka: 'person_dir')
+# e.g. PersonDir() , LastSeen() , IsNoob()
+# * write to ${person_dir}/seen after handling (not before) so that IsNoob() works
-TODO list
----------
-TODO list has been moved to our issue tracker at http://envbot.org/trac/query
+# TODO: * normalize whitespace FFS
diff --git a/lib/commands.sh b/lib/commands.sh
index b914a58..15ab489 100644
--- a/lib/commands.sh
+++ b/lib/commands.sh
@@ -257,9 +257,9 @@ commands_call_command() {
# So we got a command, now lets run it
# (strip leading white spaces) from parameters.
"$function" "$1" "$2" "${parameters## }"
- return 1
+ return 1 # handled
fi
- return 2
+ return 2 # unknown command
fi
- return 0
+ return 0 # not a command
}
diff --git a/lib/main.sh b/lib/main.sh
index 8a8bcee..9897485 100644
--- a/lib/main.sh
+++ b/lib/main.sh
@@ -441,11 +441,24 @@ while true; do
target="${BASH_REMATCH[2]}"
query="${BASH_REMATCH[3]}"
+ person="${sender%%!*}"
+ personoslash="${person//\/}"
+ declare -l personoslashlower="${personoslash}"
+ person_dir=announcements/people/${personoslashlower}
+ last_seen=$(stat -c %Y "${person_dir}/seen" 2> /dev/null)
+ should_handle=$(( ${last_seen} + 0 < $(date +%s) - 5 ))
+ if (( ! $should_handle ))
+ then
+ touch "${person_dir}/seen"
+ continue
+ fi
+
# Check if there is a command.
commands_call_command "$sender" "$target" "$query"
# Check return code
case $? in
1)
+ touch "${person_dir}/seen"
continue
;;
2)
@@ -454,23 +467,26 @@ while true; do
elif [[ $config_feedback_unknown_commands -eq 1 ]]; then
feedback_unknown_command "$sender" "$target" "$query"
fi
+ touch "${person_dir}/seen"
+ continue
;;
esac
- was_handled=0 # TODO: refactor 'process_event' triggers into modules
+ # run hook modules
+ was_handled=0 # TODO: refactor 'process_event' triggers into modules
for module in $modules_on_PRIVMSG; do
module_${module}_on_PRIVMSG "$sender" "$target" "$query"
if [[ $? -ne 0 ]]; then
- was_handled=1 # TODO: refactor 'process_event' triggers into modules
+ was_handled=1 # TODO: refactor 'process_event' triggers into modules
break
fi
done
- if ! (( ${was_handled} )) # TODO: refactor 'process_event' triggers into modules
- then
- (( $PROCESS_EVENT_SOURCED )) || source process_event
- process_event
- fi
+ if ! (( ${was_handled} )) # TODO: refactor 'process_event' triggers into modules
+ then
+ (( $PROCESS_EVENT_SOURCED )) || source process_event
+ process_event
+ fi
elif [[ "$line" =~ ^:([^ ]*)\ +NOTICE\ +([^:]+)\ +:(.*) ]]; then
sender="${BASH_REMATCH[1]}"