Improved API #9
1 changed files with 37 additions and 67 deletions
104
rowbot
104
rowbot
|
@ -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
|
is)
|
||||||
|
key=${action_line%% *}
|
||||||
|
|
||||||
|
if [[ $key = "$action_line" ]]; then
|
||||||
|
privmsg "$to" "$from: no fact provided"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case ${words[0]:${#trigger}} in
|
val=${action_line#"$key" }
|
||||||
is)
|
privmsg "$to" "I'm sure I'll remember that."
|
||||||
if (( ${#words[@]} < 3 )); then
|
mkdir -p "$fact_root"/"$to"
|
||||||
return 0
|
printf %s "$val" > "$fact_root"/"$to"/"$key"
|
||||||
|
;;
|
||||||
|
isnt)
|
||||||
|
if [[ -f $fact_root/$to/$action_line ]]; then
|
||||||
|
privmsg "$to" "I forgot what that was anyways."
|
||||||
|
rm -f "$fact_root"/"$to"/"$action_line"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
ls)
|
||||||
|
facts=( "$fact_root"/"$to"/* )
|
||||||
|
privmsg "$to" "${facts[*]##*/}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ -f $fact_root/$to/$action ]]; then
|
||||||
|
msg=$(<"$fact_root"/"$to"/"$action")
|
||||||
|
|
||||||
|
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
|
||||||
|
fi
|
||||||
local key val
|
esac
|
||||||
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."
|
|
||||||
mkdir -p "$fact_root"/"${args[0]}"
|
|
||||||
printf %s "$val" > "$fact_root"/"${args[0]}"/"$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"
|
|
||||||
privmsg "$to" "I forgot what that was anyways."
|
|
||||||
rm -f "$fact_root"/"${args[0]}"/"$key"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
ls)
|
|
||||||
local facts=( "$fact_root"/"${args[0]}"/* )
|
|
||||||
privmsg "$to" "${facts[*]##*/}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
local key=${words[0]:${#trigger}}
|
|
||||||
|
|
||||||
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"
|
|
||||||
else
|
|
||||||
privmsg "$to" "$from: $msg"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue