From 95d9c06b7b638c7651e0320f25b6561e4ef5b254 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 28 Jun 2021 15:49:44 -0500 Subject: [PATCH 1/2] Clean up some visual problems in the code --- rowbot | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rowbot b/rowbot index 83a8eb5..a72f4e2 100755 --- a/rowbot +++ b/rowbot @@ -59,10 +59,6 @@ error() { # utilities ### -parent() { - (( BASHPID == $$ )) -} - has() { hash "$1" 2>/dev/null } @@ -80,6 +76,14 @@ die() { exit "$status" } +is-parent() { + (( BASHPID == $$ )) +} + +is-channel() { + [[ ${1:0:1} = \# ]] +} + is-log-level() { local level @@ -94,7 +98,7 @@ is-log-level() { ### # argument parser for parsing arguments -## +### original_args=( "$@" ) declare -A opts @@ -128,7 +132,7 @@ prog_args=( "$@" ) ### # default config -## +### server=irc.libera.chat port=6667 tls=no client_cert= nick=rowbot-dev ident=rowbot realname=rowbot chan= @@ -286,7 +290,7 @@ cleanup() { fi } -if parent; then +if is-parent; then trap cleanup EXIT fi @@ -694,7 +698,7 @@ who() { ### # app hooks -## +### hook_pre_PRIVMSG_nolog() { local words From bfd13f8350277d529b3b75dfd44dbc13746f2e5e Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Tue, 29 Jun 2021 20:32:23 -0500 Subject: [PATCH 2/2] Apply bot scanning --- rowbot | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/rowbot b/rowbot index a72f4e2..5705af0 100755 --- a/rowbot +++ b/rowbot @@ -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_")