From 18f291fe077e803f7ffc6481b8d9c84ce3b368ff Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 19 Jul 2021 22:09:11 -0500 Subject: [PATCH] Implement a fix for #16 --- rowbot | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/rowbot b/rowbot index aadb49e..cea7156 100755 --- a/rowbot +++ b/rowbot @@ -31,6 +31,17 @@ die() { exit "${STATUS:-42}" } +get_array() { + local entry idx_size + declare -n scalar=ARR_${1^^} + declare -n array=$1 + + while read -r entry; do + idx_size=${entry%%:*} entry=${entry#"$idx_size":} + array[${entry:0:idx_size}]=${entry:idx_size} + done <<< "$scalar" +} + get_option() { if (( ! $# )); then return 1 @@ -82,6 +93,21 @@ is_running () { kill -0 "$1" 2>/dev/null } +put_array() { + # The variable named array is a nameref to an array + # shellcheck disable=SC2178 + declare -n array=$1 + declare -n scalar=ARR_${1^^} + local key + + for key in "${!array[@]}"; do + scalar+=${#key}:$key${array[$key]}$'\n' + done + + scalar=${scalar%$'\n'} + export "ARR_${1^^}" +} + random() { local min=$1 max=$2 printf %d "$(( (RANDOM % max) + min ))" @@ -473,10 +499,10 @@ on_sys_first_003_welcome() { on_sys_init_999_welcome() { get_option chan "" + declare -gA isupport } on_msg_005_welcome() { - declare -gA isupport local param key value for param in "${msg_args[@]:1:${#msg_args[@]}-2}"; do @@ -491,6 +517,14 @@ on_msg_005_welcome() { done } +on_sys_before_001_welcome() { + put_array isupport +} + +on_sys_after_999_welcome() { + get_array isupport +} + on_sys_register_999_welcome() { if [[ ${config[chan]} ]]; then irc_join "${config[chan]}"