Update the control_panel hook to use the new api
This commit is contained in:
parent
5787b3f04b
commit
fa3b002b75
1 changed files with 79 additions and 80 deletions
159
rowbot
159
rowbot
|
@ -659,83 +659,74 @@ hook_post_PRIVMSG_factoids() {
|
|||
fi
|
||||
}
|
||||
|
||||
hook_post_PRIVMSG_control_panel() {
|
||||
if [[ ${words[0]} = "$trigger"* ]]; then
|
||||
if [[ $from != "$owner" && $dev != yes ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local to=${args[0]}
|
||||
|
||||
if [[ ${args[0]:0:1} != \# ]]; then
|
||||
to=$from
|
||||
fi
|
||||
|
||||
case ${words[0]:${#trigger}} in
|
||||
raw)
|
||||
local cmd
|
||||
cmd=${args[1]#"$trigger"raw} cmd=${cmd# }
|
||||
info "%s is executing command: %s" "$from" "$cmd"
|
||||
send "$cmd"
|
||||
;;
|
||||
join)
|
||||
join "${words[1]}"
|
||||
privmsg "$to" "joined ${words[1]}"
|
||||
;;
|
||||
reload)
|
||||
reload_vars=(
|
||||
nick ident host level log log_fd alarm_pid tls_pid in_sock
|
||||
out_sock sock_dir sys_root fact_root dev trigger registered
|
||||
keep_trying desired_nick to
|
||||
)
|
||||
|
||||
for env_var in "${reload_vars[@]}"; do
|
||||
export "${env_var^^}"="${!env_var}"
|
||||
done
|
||||
|
||||
privmsg "$to" "reloading..."
|
||||
exec "$0" --reload "${original_args[@]}"
|
||||
;;
|
||||
level)
|
||||
level=${words[1]}
|
||||
privmsg "$to" "log level is now set to $level"
|
||||
;;
|
||||
dev)
|
||||
if [[ $dev = yes ]]; then
|
||||
dev=no
|
||||
privmsg "$to" "developer status disabled"
|
||||
else
|
||||
dev=yes
|
||||
privmsg "$to" "developer status enabled"
|
||||
fi
|
||||
;;
|
||||
dev\?)
|
||||
if [[ $dev = yes ]]; then
|
||||
privmsg "$to" "developer status is enabled"
|
||||
else
|
||||
privmsg "$to" "developer status is disabled"
|
||||
fi
|
||||
;;
|
||||
trigger)
|
||||
if (( ${#words[@]} > 1 )); then
|
||||
trigger=${words[1]}
|
||||
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)
|
||||
if [[ ${to:0:1} = \# ]]; then
|
||||
privmsg "$to" "cycling channel $to"
|
||||
part "$to" "be back soon!"
|
||||
join "$to"
|
||||
fi
|
||||
esac
|
||||
hook_cmd_control_panel() {
|
||||
if [[ $from != "$owner" && $dev != yes ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local channel env_var reload_vars recipient msg
|
||||
|
||||
case $action in
|
||||
raw)
|
||||
info "%s is executing command: %s" "$from" "$action_line"
|
||||
send "$action_line"
|
||||
;;
|
||||
join)
|
||||
for channel in "${action_args[@]}"; do
|
||||
join "$channel"
|
||||
privmsg "$to" "joined $channel"
|
||||
done
|
||||
;;
|
||||
reload)
|
||||
reload_vars=(
|
||||
nick ident host level log log_fd alarm_pid tls_pid in_sock
|
||||
out_sock sock_dir sys_root fact_root dev trigger registered
|
||||
keep_trying desired_nick to
|
||||
)
|
||||
|
||||
for env_var in "${reload_vars[@]}"; do
|
||||
export "${env_var^^}"="${!env_var}"
|
||||
done
|
||||
|
||||
privmsg "$to" "reloading..."
|
||||
exec "$0" --reload "${original_args[@]}"
|
||||
;;
|
||||
level)
|
||||
level=${action_args[0]}
|
||||
privmsg "$to" "log level is now set to $level"
|
||||
;;
|
||||
dev)
|
||||
if [[ $dev = yes ]]; then
|
||||
dev=no
|
||||
privmsg "$to" "developer mode disabled"
|
||||
else
|
||||
dev=yes
|
||||
privmsg "$to" "developer mode enabled"
|
||||
fi
|
||||
;;
|
||||
dev\?)
|
||||
if [[ $dev = yes ]]; then
|
||||
privmsg "$to" "developer mode is enabled"
|
||||
else
|
||||
privmsg "$to" "developer mode is disabled"
|
||||
fi
|
||||
;;
|
||||
trigger)
|
||||
trigger=${action_args[0]}
|
||||
privmsg "$to" "trigger is now '$trigger'"
|
||||
;;
|
||||
cycle)
|
||||
privmsg "$to" "cycling channel $to"
|
||||
part "$to" "be right back!"
|
||||
join "$to"
|
||||
;;
|
||||
msg)
|
||||
recipient=${action_line%% *}
|
||||
msg=${action_line#"$recipient"* }
|
||||
declare -p recipient msg action_line
|
||||
privmsg "$recipient" "$msg"
|
||||
privmsg "$to" "sent message to $recipient"
|
||||
esac
|
||||
}
|
||||
|
||||
hook_post_433_alternick() {
|
||||
|
@ -817,20 +808,22 @@ while recv line; do
|
|||
words=( )
|
||||
fi
|
||||
|
||||
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)}
|
||||
|
||||
if [[ ${to:0:1} = \# ]]; then
|
||||
if [[ ${to:0:1} != \# ]]; then
|
||||
to=$from
|
||||
fi
|
||||
|
||||
if [[ $last = "$trigger"* ]]; then
|
||||
action=${last#"$trigger"} action=${action## *}
|
||||
action_line=${last#"$trigger$action"* }
|
||||
# shellcheck disable=SC2034
|
||||
is_action=yes
|
||||
action=${last#"$trigger"} action=${action%% *}
|
||||
action_line=${last#"$trigger$action" }
|
||||
read -ra action_args <<< "$action_line"
|
||||
fi
|
||||
fi
|
||||
|
@ -855,4 +848,10 @@ while recv line; do
|
|||
while IFS= read -r hook; do
|
||||
"$hook"
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue