Merge branch 'is-bot' of uplime/rowbot into master
This commit is contained in:
commit
0a83bcda03
50
rowbot
50
rowbot
|
@ -59,10 +59,6 @@ error() {
|
||||||
# utilities
|
# utilities
|
||||||
###
|
###
|
||||||
|
|
||||||
parent() {
|
|
||||||
(( BASHPID == $$ ))
|
|
||||||
}
|
|
||||||
|
|
||||||
has() {
|
has() {
|
||||||
hash "$1" 2>/dev/null
|
hash "$1" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
@ -80,6 +76,38 @@ die() {
|
||||||
exit "$status"
|
exit "$status"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is-parent() {
|
||||||
|
(( BASHPID == $$ ))
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
is-log-level() {
|
||||||
local level
|
local level
|
||||||
|
|
||||||
|
@ -94,7 +122,7 @@ is-log-level() {
|
||||||
|
|
||||||
###
|
###
|
||||||
# argument parser for parsing arguments
|
# argument parser for parsing arguments
|
||||||
##
|
###
|
||||||
|
|
||||||
original_args=( "$@" )
|
original_args=( "$@" )
|
||||||
declare -A opts
|
declare -A opts
|
||||||
|
@ -128,7 +156,7 @@ prog_args=( "$@" )
|
||||||
|
|
||||||
###
|
###
|
||||||
# default config
|
# default config
|
||||||
##
|
###
|
||||||
|
|
||||||
server=irc.libera.chat port=6667 tls=no client_cert=
|
server=irc.libera.chat port=6667 tls=no client_cert=
|
||||||
nick=rowbot-dev ident=rowbot realname=rowbot chan=
|
nick=rowbot-dev ident=rowbot realname=rowbot chan=
|
||||||
|
@ -225,8 +253,6 @@ if [[ $markov_seed ]]; then
|
||||||
markov_chains[$key]+=" ${words[$idx + 2]}"
|
markov_chains[$key]+=" ${words[$idx + 2]}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
debug "markov seeds: %s" "${!markov_chains[*]}"
|
|
||||||
else
|
else
|
||||||
die "seed file does not exist: %s" "$markov_seed"
|
die "seed file does not exist: %s" "$markov_seed"
|
||||||
fi
|
fi
|
||||||
|
@ -286,7 +312,7 @@ cleanup() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if parent; then
|
if is-parent; then
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -694,7 +720,7 @@ who() {
|
||||||
|
|
||||||
###
|
###
|
||||||
# app hooks
|
# app hooks
|
||||||
##
|
###
|
||||||
|
|
||||||
hook_pre_PRIVMSG_nolog() {
|
hook_pre_PRIVMSG_nolog() {
|
||||||
local words
|
local words
|
||||||
|
@ -1058,10 +1084,12 @@ while recv line; do
|
||||||
|
|
||||||
if [[ $last = "$trigger"* ]]; then
|
if [[ $last = "$trigger"* ]]; then
|
||||||
is_action=yes
|
is_action=yes
|
||||||
|
bot_score=$(is-bot)
|
||||||
action=${last#"$trigger"} action=${action%% *}
|
action=${last#"$trigger"} action=${action%% *}
|
||||||
action_line=${last#"$trigger$action" }
|
action_line=${last#"$trigger$action" }
|
||||||
read -r action_line <<< "$action_line"
|
read -r action_line <<< "$action_line"
|
||||||
read -ra action_args <<< "$action_line"
|
read -ra action_args <<< "$action_line"
|
||||||
|
debug "bot score: %d" "$bot_score"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1086,7 +1114,7 @@ while recv line; do
|
||||||
"$hook"
|
"$hook"
|
||||||
done < <(compgen -A function "hook_post_${cmd^^}_")
|
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
|
while IFS= read -r hook; do
|
||||||
"$hook"
|
"$hook"
|
||||||
done < <(compgen -A function "hook_cmd_")
|
done < <(compgen -A function "hook_cmd_")
|
||||||
|
|
Loading…
Reference in New Issue