Remove most read/write entries to config
This commit is contained in:
parent
71efc80fe8
commit
1b86e46aea
99
rowbot
99
rowbot
|
@ -104,7 +104,10 @@ is_reloaded() {
|
|||
# message classification
|
||||
|
||||
is_action() {
|
||||
[[ ${msg[cmd]} = PRIVMSG && ${msg_args[-1]:0:${#config[trigger]}} = "${config[trigger]}" ]]
|
||||
# The only possible fail conditions are already checked for.
|
||||
# shellcheck disable=SC2155
|
||||
local trigger=$(state_get trigger)
|
||||
[[ ${msg[cmd]} = PRIVMSG && ${msg_args[-1]:0:${#trigger}} = "$trigger" ]]
|
||||
}
|
||||
|
||||
is_chan() {
|
||||
|
@ -220,13 +223,16 @@ seconds() {
|
|||
}
|
||||
|
||||
url() {
|
||||
if [[ ${config[tls]} = no ]]; then
|
||||
printf irc://
|
||||
else
|
||||
if NS=net state_get tls; then
|
||||
printf ircs://
|
||||
else
|
||||
printf irc://
|
||||
fi
|
||||
|
||||
prints %s:%s "${config[server]}" "${config[port]}"
|
||||
# The only possible fail conditions are already checked for.
|
||||
# shellcheck disable=SC2155
|
||||
local server=$(NS=net state_get server) port=$(NS=net state_get port)
|
||||
prints %s:%s "$server" "$port"
|
||||
}
|
||||
|
||||
###
|
||||
|
@ -328,10 +334,10 @@ state_resolve() {
|
|||
fi
|
||||
fi
|
||||
|
||||
if [[ -v config[$1] ]]; then
|
||||
ns_config[$1]=${config[$1]}
|
||||
if [[ -v config["$1"] ]]; then
|
||||
ns_config["$1"]=${config["$1"]}
|
||||
elif [[ -v DEFAULT ]]; then
|
||||
ns_config[$1]=$DEFAULT
|
||||
ns_config["$1"]=$DEFAULT
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
@ -342,7 +348,7 @@ state_put() {
|
|||
# The `ns_config` variable is a reference to an array
|
||||
# shellcheck disable=SC2178
|
||||
declare -n ns_config=__rowbot_state_store_"$ns"
|
||||
ns_config[$1]=$2
|
||||
ns_config["$1"]=$2
|
||||
}
|
||||
|
||||
state_get() {
|
||||
|
@ -351,10 +357,10 @@ state_get() {
|
|||
# shellcheck disable=SC2178
|
||||
declare -n ns_config=__rowbot_state_store_"$ns"
|
||||
|
||||
if [[ -v ns_config[$1] ]]; then
|
||||
printf %s "${ns_config[$1]}"
|
||||
if [[ -v ns_config["$1"] ]]; then
|
||||
printf %s "${ns_config["$1"]}"
|
||||
|
||||
if [[ ${ns_config[$1]} = no ]]; then
|
||||
if [[ ${ns_config["$1"]} = no ]]; then
|
||||
return 1
|
||||
fi
|
||||
elif [[ -v DEFAULT ]]; then
|
||||
|
@ -370,9 +376,11 @@ state_get() {
|
|||
|
||||
state_has() {
|
||||
local ns=${NS-global} found=1 managed
|
||||
# The `ns_config` variable is a reference to an array
|
||||
# shellcheck disable=SC2178
|
||||
declare -n ns_config=__rowbot_state_store_"$ns"
|
||||
|
||||
for managed in "${ns_config[@]}"; do
|
||||
for managed in "${!ns_config[@]}"; do
|
||||
if [[ $managed = "$1" ]]; then
|
||||
found=0
|
||||
break
|
||||
|
@ -456,18 +464,23 @@ log_has_level() {
|
|||
on_sys_init_005_log() {
|
||||
declare -gA log_levels=( [trace]=1 [debug]=2 [info]=3 [warn]=4 [error]=5 )
|
||||
NS=log DEFAULT=info state_resolve level
|
||||
NS=log state_resolve log
|
||||
NS=log DEFAULT=no state_resolve overwrite
|
||||
local log_fd=1
|
||||
|
||||
if ! log_has_level "$(NS=log state_get level)"; then
|
||||
die "%s is not a valid logging level" "$(NS=log state_get level)"
|
||||
fi
|
||||
|
||||
local log_fd=1
|
||||
if NS=log state_has log; then
|
||||
# The only possible fail conditions are already checked for.
|
||||
# shellcheck disable=SC2155
|
||||
local log_file=$(NS=log state_get log)
|
||||
|
||||
if [[ -v ${config[log]} ]]; then
|
||||
if [[ ${config[overwrite]} = yes ]]; then
|
||||
exec {log_fd}>"${config[log]}"
|
||||
if NS=log state_get overwrite; then
|
||||
exec {log_fd}>"$log_file"
|
||||
else
|
||||
exec {log_fd}>>"${config[log]}"
|
||||
exec {log_fd}>>"$log_file"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -557,7 +570,7 @@ on_sys_init_015_net() {
|
|||
NS=net DEFAULT=irc.libera.chat state_resolve server
|
||||
NS=net DEFAULT=no state_resolve tls
|
||||
|
||||
if NS=net state_get tls; then
|
||||
if ! NS=net state_get tls; then
|
||||
NS=net DEFAULT=6667 state_resolve port
|
||||
else
|
||||
NS=net DEFAULT=6697 state_resolve port
|
||||
|
@ -678,18 +691,17 @@ on_sys_exit_997_annoyatron900() {
|
|||
# register with the server
|
||||
###
|
||||
|
||||
on_sys_first_003_welcome() {
|
||||
#get_option nick rowbot-dev
|
||||
#get_option ident rowbot
|
||||
#get_option realname rowbot
|
||||
log_debug "registering with the server"
|
||||
irc_nick "${config[nick]}"
|
||||
irc_user "${config[ident]}" "${config[realname]}"
|
||||
on_sys_init_020_welcome() {
|
||||
NS=irc state_resolve chans
|
||||
}
|
||||
|
||||
on_sys_init_999_welcome() {
|
||||
# get_option chan ""
|
||||
declare -gA isupport
|
||||
on_sys_first_020_welcome() {
|
||||
NS=irc DEFAULT=rowbot-dev state_resolve nick
|
||||
NS=irc DEFAULT=rowbot state_resolve ident
|
||||
NS=irc DEFAULT=rowbot state_resolve realname
|
||||
log_debug "registering with the server"
|
||||
irc_nick "$(NS=irc state_get nick)"
|
||||
irc_user "$(NS=irc state_get ident)" "$(NS=irc state_get realname)"
|
||||
}
|
||||
|
||||
on_msg_005_welcome() {
|
||||
|
@ -699,25 +711,14 @@ on_msg_005_welcome() {
|
|||
# This is a valid assignment, not a comparison.
|
||||
# shellcheck disable=SC1097
|
||||
IFS== read -r key value <<< "$param"
|
||||
# While isupport is unused, it's still there in case later code wants to
|
||||
# use it.
|
||||
# shellcheck disable=SC2034
|
||||
isupport[$key]=$value
|
||||
NS=isupport state_put "$key" "$value"
|
||||
log_trace "isupport: %s = %s" "$key" "$value"
|
||||
done
|
||||
}
|
||||
|
||||
on_sys_before_001_welcome() {
|
||||
put_assoc_array isupport
|
||||
}
|
||||
|
||||
on_sys_after_999_welcome() {
|
||||
get_assoc_array isupport
|
||||
}
|
||||
|
||||
on_sys_register_999_welcome() {
|
||||
if [[ ${config[chan]} ]]; then
|
||||
irc_join "${config[chan]}"
|
||||
on_sys_register_welcome() {
|
||||
if NS=irc state_has chans; then
|
||||
irc_join "$(NS=irc state_get chans)"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -725,21 +726,21 @@ on_sys_register_999_welcome() {
|
|||
# magic required to make privmsg work
|
||||
###
|
||||
|
||||
on_sys_register_001_privmagic() {
|
||||
config[nick]=${msg_args[0]}
|
||||
irc_who "${config[nick]}" %%uht,42
|
||||
on_sys_register_privmagic() {
|
||||
NS=irc state_put nick "${msg_args[0]}"
|
||||
}
|
||||
|
||||
on_msg_354_privmagic() {
|
||||
if (( msg_args[1] == 42 )); then
|
||||
log_debug "received the identifying who"
|
||||
config[ident]=${msg_args[2]} config[host]=${msg_args[3]}
|
||||
NS=irc state_put ident "${msg_args[2]}"
|
||||
NS=irc state_put host "${msg_args[3]}"
|
||||
fi
|
||||
}
|
||||
|
||||
on_msg_396_privmagic() {
|
||||
config[host]=${msg_args[1]}
|
||||
log_debug "config host has been changed to %s" "${msg_args[1]}"
|
||||
NS=irc state_put host "${msg_args[1]}"
|
||||
}
|
||||
|
||||
###
|
||||
|
|
Loading…
Reference in New Issue