Lay the groundwork for responding to IRC messages
This commit is contained in:
parent
99783ba792
commit
576738e85e
33
rowbot
33
rowbot
|
@ -57,6 +57,14 @@ has() {
|
|||
fi
|
||||
}
|
||||
|
||||
is_action() {
|
||||
[[ ${msg[cmd]} = PRIVMSG && ${msg_args[-1]:0:${#config[trigger]}} = "${config[trigger]}" ]]
|
||||
}
|
||||
|
||||
is_chan() {
|
||||
[[ ${msg_args[${1:-0}]} = \# ]]
|
||||
}
|
||||
|
||||
is_parent() {
|
||||
(( BASHPID == $$ ))
|
||||
}
|
||||
|
@ -79,11 +87,12 @@ run_callbacks() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
local filter=$1
|
||||
local status=0 filter=$1
|
||||
shift
|
||||
|
||||
while IFS= read -r; do
|
||||
"$REPLY" "$@"
|
||||
(( status |= $? ))
|
||||
done < <(compgen -A function "$filter")
|
||||
|
||||
return 0
|
||||
|
@ -614,6 +623,7 @@ while net_recv line; do
|
|||
# alphabet values
|
||||
|
||||
msg[cmd]=${line%% *} line=${line#"${msg[cmd]}"} line=${line# }
|
||||
msg[cmd]=${msg[cmd]^^}
|
||||
log_debug "parsing message command %s" "${msg[cmd]}"
|
||||
|
||||
# parse the remaining values into white-space separated arguments
|
||||
|
@ -633,7 +643,7 @@ while net_recv line; do
|
|||
fi
|
||||
done
|
||||
|
||||
if [[ ${msg[cmd]^^} = @(PRIVMSG|NOTICE) ]]; then
|
||||
if [[ ${msg[cmd]} = @(PRIVMSG|NOTICE) ]]; then
|
||||
case ${msg_args[-1]} in
|
||||
"["*"]")
|
||||
(( msg[score] += 20 ))
|
||||
|
@ -645,9 +655,24 @@ while net_recv line; do
|
|||
|
||||
log_debug "bot score is %d" "${msg[score]}"
|
||||
|
||||
if has irc_on_"${msg[cmd]^^}"; then
|
||||
irc_on_"${msg[cmd]^^}"
|
||||
if has irc_on_"${msg[cmd]}"; then
|
||||
if run_callbacks "on_msg_${msg[cmd]}_"; then
|
||||
log_debug "handler for %s was skipped" "${msg[cmd]}"
|
||||
else
|
||||
irc_on_"${msg[cmd]}"
|
||||
fi
|
||||
|
||||
run_callbacks "on_late_msg_${msg[cmd]}_"
|
||||
else
|
||||
log_warn "unhandled line: %s" "${msg[original]}"
|
||||
fi
|
||||
|
||||
if is_action; then
|
||||
action=${msg_args[-1]#"${config[trigger]}"} action=${action%% *}
|
||||
action_line=${msg_args[-1]#"$trigger$action"}
|
||||
read -r action_line <<< "$action_line"
|
||||
# This variable will be used in later code.
|
||||
# shellcheck disable=SC2034
|
||||
read -ra action_args <<< "$action_line"
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue