Update the control_panel hook to use the new api

This commit is contained in:
Nick Chambers 2021-06-20 00:56:52 -05:00 committed by Nick Chambers
parent 5787b3f04b
commit fa3b002b75
1 changed files with 79 additions and 80 deletions

73
rowbot
View File

@ -659,28 +659,23 @@ hook_post_PRIVMSG_factoids() {
fi fi
} }
hook_post_PRIVMSG_control_panel() { hook_cmd_control_panel() {
if [[ ${words[0]} = "$trigger"* ]]; then
if [[ $from != "$owner" && $dev != yes ]]; then if [[ $from != "$owner" && $dev != yes ]]; then
return 0 return 0
fi fi
local to=${args[0]} local channel env_var reload_vars recipient msg
if [[ ${args[0]:0:1} != \# ]]; then case $action in
to=$from
fi
case ${words[0]:${#trigger}} in
raw) raw)
local cmd info "%s is executing command: %s" "$from" "$action_line"
cmd=${args[1]#"$trigger"raw} cmd=${cmd# } send "$action_line"
info "%s is executing command: %s" "$from" "$cmd"
send "$cmd"
;; ;;
join) join)
join "${words[1]}" for channel in "${action_args[@]}"; do
privmsg "$to" "joined ${words[1]}" join "$channel"
privmsg "$to" "joined $channel"
done
;; ;;
reload) reload)
reload_vars=( reload_vars=(
@ -697,45 +692,41 @@ hook_post_PRIVMSG_control_panel() {
exec "$0" --reload "${original_args[@]}" exec "$0" --reload "${original_args[@]}"
;; ;;
level) level)
level=${words[1]} level=${action_args[0]}
privmsg "$to" "log level is now set to $level" privmsg "$to" "log level is now set to $level"
;; ;;
dev) dev)
if [[ $dev = yes ]]; then if [[ $dev = yes ]]; then
dev=no dev=no
privmsg "$to" "developer status disabled" privmsg "$to" "developer mode disabled"
else else
dev=yes dev=yes
privmsg "$to" "developer status enabled" privmsg "$to" "developer mode enabled"
fi fi
;; ;;
dev\?) dev\?)
if [[ $dev = yes ]]; then if [[ $dev = yes ]]; then
privmsg "$to" "developer status is enabled" privmsg "$to" "developer mode is enabled"
else else
privmsg "$to" "developer status is disabled" privmsg "$to" "developer mode is disabled"
fi fi
;; ;;
trigger) trigger)
if (( ${#words[@]} > 1 )); then trigger=${action_args[0]}
trigger=${words[1]} privmsg "$to" "trigger is now '$trigger'"
privmsg "$to" "trigger is now $trigger"
fi
;;
msg)
if (( ${words[@]} > 2 )); then
privmsg "${words[1]}" "${words[*]:2}"
privmsg "$to" "sent message to ${words[1]}"
fi
;; ;;
cycle) cycle)
if [[ ${to:0:1} = \# ]]; then
privmsg "$to" "cycling channel $to" privmsg "$to" "cycling channel $to"
part "$to" "be back soon!" part "$to" "be right back!"
join "$to" join "$to"
fi ;;
msg)
recipient=${action_line%% *}
msg=${action_line#"$recipient"* }
declare -p recipient msg action_line
privmsg "$recipient" "$msg"
privmsg "$to" "sent message to $recipient"
esac esac
fi
} }
hook_post_433_alternick() { hook_post_433_alternick() {
@ -817,20 +808,22 @@ while recv line; do
words=( ) words=( )
fi fi
is_action=no
if [[ ${cmd^^} = PRIVMSG ]]; then if [[ ${cmd^^} = PRIVMSG ]]; then
# Since it is assigning the last index of the array, it will always be a # Since it is assigning the last index of the array, it will always be a
# single string. # single string.
# shellcheck disable=SC2124 # shellcheck disable=SC2124
to=${args[0]} last=${args[@]:(-1)} to=${args[0]} last=${args[@]:(-1)}
if [[ ${to:0:1} = \# ]]; then if [[ ${to:0:1} != \# ]]; then
to=$from to=$from
fi fi
if [[ $last = "$trigger"* ]]; then if [[ $last = "$trigger"* ]]; then
action=${last#"$trigger"} action=${action## *} is_action=yes
action_line=${last#"$trigger$action"* } action=${last#"$trigger"} action=${action%% *}
# shellcheck disable=SC2034 action_line=${last#"$trigger$action" }
read -ra action_args <<< "$action_line" read -ra action_args <<< "$action_line"
fi fi
fi fi
@ -855,4 +848,10 @@ while recv line; do
while IFS= read -r hook; do while IFS= read -r hook; do
"$hook" "$hook"
done < <(compgen -A function "hook_post_${cmd^^}_") done < <(compgen -A function "hook_post_${cmd^^}_")
if [[ $is_action = yes ]]; then
while IFS= read -r hook; do
"$hook"
done < <(compgen -A function "hook_cmd_")
fi
done done