Add helpful variables for user messages
This commit is contained in:
parent
41a4842920
commit
e976de6b63
48
rowbot
48
rowbot
|
@ -765,8 +765,26 @@ else
|
||||||
user "$ident" "$realname"
|
user "$ident" "$realname"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Always available:
|
||||||
|
# - from: name of the entity sending the message
|
||||||
|
# - ident: username of the entity sending the message
|
||||||
|
# - host: host of the entity sending the message
|
||||||
|
# - cmd: IRC command or numeric
|
||||||
|
# - args: array of arguments to the command
|
||||||
|
|
||||||
|
# Available if the last parameter starts with ":"
|
||||||
|
# - words: array of words, split by whitespace, of the last parameter
|
||||||
|
|
||||||
|
# Available if `cmd` is set to "privmsg":
|
||||||
|
# - to: location to send the message back to
|
||||||
|
|
||||||
|
# Additionally, if args[-1] starts with the trigger:
|
||||||
|
# - action: directive specified by the sender
|
||||||
|
# - action_line: data sent by the sender without the trigger or action
|
||||||
|
# - action_args: words sent by the sender without the trigger or action
|
||||||
|
|
||||||
while recv line; do
|
while recv line; do
|
||||||
params=( )
|
args=( )
|
||||||
has_words=no
|
has_words=no
|
||||||
orig_line=$line
|
orig_line=$line
|
||||||
|
|
||||||
|
@ -783,22 +801,36 @@ while recv line; do
|
||||||
|
|
||||||
while [[ $line ]]; do
|
while [[ $line ]]; do
|
||||||
if [[ ${line:0:1} = : ]]; then
|
if [[ ${line:0:1} = : ]]; then
|
||||||
params+=("${line:1}")
|
args+=( "${line:1}" )
|
||||||
line=""
|
line=""
|
||||||
has_words=yes
|
has_words=yes
|
||||||
else
|
else
|
||||||
param=${line%% *}
|
arg=${line%% *}
|
||||||
params+=("$param")
|
args+=( "$arg" )
|
||||||
line=${line#"$param"} line=${line# }
|
line=${line#"$arg"} line=${line# }
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $has_words = yes ]]; then
|
if [[ $has_words = yes ]]; then
|
||||||
read -ra words <<< "${params[@]:(-1)}"
|
read -ra words <<< "${args[@]:(-1)}"
|
||||||
else
|
else
|
||||||
words=( )
|
words=( )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ${cmd^^} = PRIVMSG ]]; then
|
||||||
|
to=${args[0]} last=${args[@]:(-1)}
|
||||||
|
|
||||||
|
if [[ ${to:0:1} = \# ]]; then
|
||||||
|
to=$from
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $last = "$trigger"* ]]; then
|
||||||
|
action=${last#"$trigger"} action=${action## *}
|
||||||
|
action_line=${last#"$trigger$action" }
|
||||||
|
read -ra action_args <<< "$action_line"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
skip_handler=0
|
skip_handler=0
|
||||||
|
|
||||||
while IFS= read -r hook; do
|
while IFS= read -r hook; do
|
||||||
|
@ -806,14 +838,14 @@ while recv line; do
|
||||||
(( skip_handler |= $? ))
|
(( skip_handler |= $? ))
|
||||||
done < <(compgen -A function "hook_pre_${cmd^^}_")
|
done < <(compgen -A function "hook_pre_${cmd^^}_")
|
||||||
|
|
||||||
if hash "on_${cmd^^}" 2>/dev/null; then
|
if has "on_${cmd^^}"; then
|
||||||
if (( ! skip_handler )); then
|
if (( ! skip_handler )); then
|
||||||
"on_${cmd^^}"
|
"on_${cmd^^}"
|
||||||
else
|
else
|
||||||
debug "handler for %s was skipped" "${cmd^^}"
|
debug "handler for %s was skipped" "${cmd^^}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
warn "unhandled line: %s" "$orig_line"
|
warn "unhandled line: %s" "$orig_line"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r hook; do
|
while IFS= read -r hook; do
|
||||||
|
|
Loading…
Reference in New Issue