Properly index the last element of the array

This commit is contained in:
Nick Chambers 2021-06-26 17:17:10 -05:00
parent 21c8d58459
commit 190c1534ed
1 changed files with 5 additions and 13 deletions

18
rowbot
View File

@ -412,7 +412,7 @@ on_JOIN() {
on_KICK() {
if (( ${#args[@]} == 3 )); then
info "%s has kicked %s from %s: %s" "$from" "${args[1]}" "${args[0]}" "${args[@]:(-1)}"
info "%s has kicked %s from %s: %s" "$from" "${args[1]}" "${args[0]}" "${args[-1]}"
else
info "%s has kicked %s from %s" "$from" "${args[1]}" "${args[0]}"
fi
@ -601,9 +601,7 @@ on_433() {
}
on_438() {
# The result will always be a string, since its the last index of the array.
# shellcheck disable=SC2145
error "${args[1]} couldn't change their nick to ${args[2]}: ${args[@]:(-1)}"
error "${args[1]} couldn't change their nick to ${args[2]}: ${args[-1]}"
}
on_473() {
@ -700,7 +698,7 @@ who() {
hook_pre_PRIVMSG_nolog() {
local words
read -ra words <<< "${args[@]:(-1)}"
read -ra words <<< "${args[-1]}"
if [[ ${words[0]} = "[nolog]" || ${words[0]} = nolog: ]]; then
info "this message was redacted"
@ -864,10 +862,7 @@ hook_cmd_factoids() {
msg=$(<"$fact_root"/"$to"/"$action")
if [[ ${action_args[0]} = \> ]] && (( ${#action_args[@]} > 1 )); then
# Since it is assigning the last index of the array, it will always be a
# single string.
# shellcheck disable=SC2145
privmsg "$to" "${action_args[@]:(-1)}: $msg"
privmsg "$to" "${action_args[-1]}: $msg"
else
privmsg "$to" "$from: $msg"
fi
@ -1055,10 +1050,7 @@ while recv line; do
is_action=no
if [[ ${cmd^^} = PRIVMSG ]]; then
# Since it is assigning the last index of the array, it will always be a
# single string.
# shellcheck disable=SC2124
to=${args[0]} last=${args[@]:(-1)}
to=${args[0]} last=${args[-1]}
if [[ ${to:0:1} != \# ]]; then
to=$from