From 190c1534ed810035dd89169cdd54539ac5dbf8c2 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 26 Jun 2021 17:17:10 -0500 Subject: [PATCH] Properly index the last element of the array --- rowbot | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/rowbot b/rowbot index 962cc27..83a8eb5 100755 --- a/rowbot +++ b/rowbot @@ -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