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