Apply bot scanning

This commit is contained in:
Nick Chambers 2021-06-29 20:32:23 -05:00
parent 95d9c06b7b
commit bfd13f8350
1 changed files with 27 additions and 3 deletions

30
rowbot
View File

@ -84,6 +84,30 @@ is-channel() {
[[ ${1:0:1} = \# ]]
}
is-bot() {
local score=0
if [[ ${args[-1]:0:3} = $'\xe2\x80\x8b' ]]; then
(( score += 100 ))
fi
if [[ $from = *-bot ]]; then
(( score += 30 ))
elif [[ $from = *bot ]]; then
(( score += 15 ))
fi
if [[ /$host/ = */bot/* ]]; then
(( score += 100 ))
fi
if [[ ${args[-1]} = '['*']' ]]; then
(( score += 20 ))
fi
printf %d "$score"
}
is-log-level() {
local level
@ -229,8 +253,6 @@ if [[ $markov_seed ]]; then
markov_chains[$key]+=" ${words[$idx + 2]}"
fi
done
debug "markov seeds: %s" "${!markov_chains[*]}"
else
die "seed file does not exist: %s" "$markov_seed"
fi
@ -1062,10 +1084,12 @@ while recv line; do
if [[ $last = "$trigger"* ]]; then
is_action=yes
bot_score=$(is-bot)
action=${last#"$trigger"} action=${action%% *}
action_line=${last#"$trigger$action" }
read -r action_line <<< "$action_line"
read -ra action_args <<< "$action_line"
debug "bot score: %d" "$bot_score"
fi
fi
@ -1090,7 +1114,7 @@ while recv line; do
"$hook"
done < <(compgen -A function "hook_post_${cmd^^}_")
if [[ $is_action = yes ]]; then
if [[ $is_action = yes ]] && (( bot_score < 40 )); then
while IFS= read -r hook; do
"$hook"
done < <(compgen -A function "hook_cmd_")