update the factoids hook to use the new api

This commit is contained in:
Nick Chambers 2021-06-20 01:17:06 -05:00
parent e92623874c
commit 3f6e6c60ed
1 changed files with 37 additions and 67 deletions

70
rowbot
View File

@ -597,66 +597,47 @@ hook_pre_PRIVMSG_CTCP() {
return 1 return 1
} }
hook_post_PRIVMSG_factoids() { hook_cmd_factoids() {
if [[ ${args[0]:0:1} != \# && $from != shikhin ]]; then local key val facts msg
return 0
elif [[ ${words[0]} = "$trigger"* ]]; then
local to=${args[0]}
if [[ ${args[0]:0:1} != \# ]]; then case $action in
to=$from
fi
case ${words[0]:${#trigger}} in
is) is)
if (( ${#words[@]} < 3 )); then key=${action_line%% *}
if [[ $key = "$action_line" ]]; then
privmsg "$to" "$from: no fact provided"
return 0 return 0
fi fi
local key val val=${action_line#"$key" }
key=${args[1]#*"$trigger"is} key=${key# }
val=${key#* } key=${key%% *}
info "%s said in %s to remember %s as %s" "$from" "${args[0]}" "$key" "$val"
privmsg "$to" "I'm sure I'll remember that." privmsg "$to" "I'm sure I'll remember that."
mkdir -p "$fact_root"/"${args[0]}" mkdir -p "$fact_root"/"$to"
printf %s "$val" > "$fact_root"/"${args[0]}"/"$key" printf %s "$val" > "$fact_root"/"$to"/"$key"
;; ;;
isnt) isnt)
if (( ${#words[@]} < 2 )); then if [[ -f $fact_root/$to/$action_line ]]; then
return 0
fi
local key
key=${args[1]#*"$trigger"isnt} key=${key# }
if [[ -f $fact_root/${args[0]}/$key ]]; then
info "%s said in %s to delete %s" "$from" "${args[0]}" "$key"
privmsg "$to" "I forgot what that was anyways." privmsg "$to" "I forgot what that was anyways."
rm -f "$fact_root"/"${args[0]}"/"$key" rm -f "$fact_root"/"$to"/"$action_line"
fi fi
;; ;;
ls) ls)
local facts=( "$fact_root"/"${args[0]}"/* ) facts=( "$fact_root"/"$to"/* )
privmsg "$to" "${facts[*]##*/}" privmsg "$to" "${facts[*]##*/}"
;; ;;
*) *)
local key=${words[0]:${#trigger}} if [[ -f $fact_root/$to/$action ]]; then
msg=$(<"$fact_root"/"$to"/"$action")
if [[ -f $fact_root/${args[0]}/$key ]]; then if [[ ${action_args[0]} = \> ]] && (( ${#action_args[@]} > 1 )); then
local msg # Since it is assigning the last index of the array, it will always be a
msg=$(<"$fact_root"/"${args[0]}"/"$key") # single string.
# shellcheck disable=SC2145
if (( ${#words[@]} > 1 )) && [[ ${words[1]} = \> ]]; then privmsg "$to" "${action_args[@]:(-1)}: $msg"
local target
target=${args[1]#*\>} target=${target# } target=${target% }
privmsg "$to" "$target: $msg"
else else
privmsg "$to" "$from: $msg" privmsg "$to" "$from: $msg"
fi fi
fi fi
esac esac
fi
} }
hook_cmd_control_panel() { hook_cmd_control_panel() {
@ -763,9 +744,6 @@ fi
# - cmd: IRC command or numeric # - cmd: IRC command or numeric
# - args: array of arguments to the command # - args: array of arguments to the command
# Available if the last argument starts with ":"
# - words: array of words, split by whitespace, of the last argument
# Available if `cmd` is set to "privmsg": # Available if `cmd` is set to "privmsg":
# - to: location to send the message back to # - to: location to send the message back to
@ -776,7 +754,6 @@ fi
while recv line; do while recv line; do
args=( ) args=( )
has_words=no
orig_line=$line orig_line=$line
if [[ ${line:0:1} = : ]]; then if [[ ${line:0:1} = : ]]; then
@ -794,7 +771,6 @@ while recv line; do
if [[ ${line:0:1} = : ]]; then if [[ ${line:0:1} = : ]]; then
args+=( "${line:1}" ) args+=( "${line:1}" )
line="" line=""
has_words=yes
else else
arg=${line%% *} arg=${line%% *}
args+=( "$arg" ) args+=( "$arg" )
@ -802,12 +778,6 @@ while recv line; do
fi fi
done done
if [[ $has_words = yes ]]; then
read -ra words <<< "${args[@]:(-1)}"
else
words=( )
fi
is_action=no is_action=no
if [[ ${cmd^^} = PRIVMSG ]]; then if [[ ${cmd^^} = PRIVMSG ]]; then