Implement facts api for remembering things
This commit is contained in:
parent
2d53264347
commit
c98f4fa3f1
1 changed files with 53 additions and 4 deletions
57
rowbot
57
rowbot
|
@ -92,6 +92,8 @@ nick=${opts[nick]:-rowbot-dev}
|
||||||
ident=${opts[ident]:-rowbot}
|
ident=${opts[ident]:-rowbot}
|
||||||
realname=${opts[realname]:-rowbot}
|
realname=${opts[realname]:-rowbot}
|
||||||
chan=${opts[chan]:-}
|
chan=${opts[chan]:-}
|
||||||
|
trigger=${opts[trigger]:-\`}
|
||||||
|
fact_root=${opts[fact-root]:-.}
|
||||||
|
|
||||||
###
|
###
|
||||||
# net code
|
# net code
|
||||||
|
@ -128,6 +130,10 @@ on_ERROR() {
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
on_JOIN() {
|
||||||
|
info "%s has joined %s" "$from" "${params[0]}"
|
||||||
|
}
|
||||||
|
|
||||||
on_MODE() {
|
on_MODE() {
|
||||||
if (( ${#params[@]} == 2 )); then
|
if (( ${#params[@]} == 2 )); then
|
||||||
info "%s sets mode(s) %s on %s" "$from" "${params[1]}" "${params[0]}"
|
info "%s sets mode(s) %s on %s" "$from" "${params[1]}" "${params[0]}"
|
||||||
|
@ -258,7 +264,7 @@ pong() {
|
||||||
}
|
}
|
||||||
|
|
||||||
privmsg() {
|
privmsg() {
|
||||||
send "PRIVMSG %s :%s" "$1" "$2"
|
send "PRIVMSG %s :\u200b%s" "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
user() {
|
user() {
|
||||||
|
@ -266,11 +272,54 @@ user() {
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
###
|
||||||
# utility hooks
|
# app hooks
|
||||||
##
|
##
|
||||||
|
|
||||||
hook_JOIN_greet() {
|
hook_PRIVMSG_factoids() {
|
||||||
privmsg "${params[0]}" "Hello, $from!"
|
if [[ ${params[0]:0:1} != \# ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ ${words[0]} = "$trigger"* ]]; then
|
||||||
|
case ${words[0]:${#trigger}} in
|
||||||
|
is)
|
||||||
|
if (( ${#words[@]} < 3 )); then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local key val
|
||||||
|
key=${params[1]#*"$trigger"is} key=${key# }
|
||||||
|
val=${key#* } key=${key%% *}
|
||||||
|
|
||||||
|
info "%s said in %s to remember %s as %s" "$from" "${params[0]}" "$key" "$val"
|
||||||
|
privmsg "${params[0]}" "I'm sure I'll remember that."
|
||||||
|
mkdir -p "$fact_root"/"${params[0]}"
|
||||||
|
printf %s "$val" > "$fact_root"/"${params[0]}"/"$key"
|
||||||
|
;;
|
||||||
|
isnt)
|
||||||
|
if (( ${#words[@]} < 2 )); then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local key
|
||||||
|
key=${params[1]#*"$trigger"isnt} key=${key# }
|
||||||
|
|
||||||
|
if [[ -f $fact_root/${params[0]}/$key ]]; then
|
||||||
|
info "%s said in %s to delete %s" "$from" "${params[0]}" "$key"
|
||||||
|
privmsg "${params[0]}" "I forgot what that was anyways."
|
||||||
|
rm -f "$fact_root"/"${params[0]}"/"$key"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
ls)
|
||||||
|
local facts=( "$fact_root"/"${params[0]}"/* )
|
||||||
|
privmsg "${params[0]}" "${facts[*]##*/}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
local key=${params[1]:1}
|
||||||
|
|
||||||
|
if [[ -f $fact_root/${params[0]}/$key ]]; then
|
||||||
|
privmsg "${params[0]}" "$from: $(<"$fact_root"/"${params[0]}"/"$key")"
|
||||||
|
fi
|
||||||
|
esac
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
Loading…
Reference in a new issue