Add a sysfacts trigger

This commit is contained in:
Nick Chambers 2021-06-19 21:47:57 -05:00
parent 2ace847c63
commit 78d5f9f492
1 changed files with 24 additions and 0 deletions

24
rowbot
View File

@ -97,6 +97,7 @@ trigger=${opts[trigger]:-\`}
fact_root=${opts[fact-root]:-.}
reload=${opts[reload]:-no}
dev=${opts[dev]:-no}
sysfacts_file=${opts[sysfacts]:-./sysfacts.txt}
if [[ -v USER ]]; then
owner=${opts[owner]:-"$USER"}
@ -712,6 +713,29 @@ hook_post_PRIVMSG_control_panel() {
fi
}
sysfacts=( )
if [[ -f $sysfacts_file ]]; then
mapfile -t sysfacts < "$sysfacts_file"
fi
hook_post_PRIVMSG_sysfacts() {
local to=${params[0]} idx
if [[ ${params[0]:0:1} != \# ]]; then
to=$from
fi
if [[ ${words[0]} = "$trigger"sysfact ]]; then
if (( ${#sysfacts[@]} == 0 )); then
privmsg "$to" "sysfacts are not loaded :("
else
(( idx = RANDOM % ${#sysfacts[@]} ))
privmsg "$to" "sysfact #$(( idx + 1 )): ${sysfacts[$idx]}"
fi
fi
}
hook_post_433_alternick() {
if [[ -z $desired_nick && $registered = no ]]; then
desired_nick=${params[1]}