Add format specifiers to factoids

This commit is contained in:
Nick Chambers 2021-07-19 16:43:44 -05:00
parent 553d7faecf
commit a070154197
1 changed files with 27 additions and 2 deletions

29
rowbot
View File

@ -962,12 +962,37 @@ plugin_not_found_factoids() {
# The exit status isn't important here.
# shellcheck disable=SC2155
local fact=$(<"${config[fact-root]}"/"${msg[to]}"/"$action")
local target idx fmt_fact
if [[ ${action_args[0]} = \> ]] && (( ${#action_args[@]} > 1 )); then
irc_privmsg "${msg[to]}" "${action_args[-1]}: $fact"
target=${action_args[-1]}
else
irc_privmsg "${msg[to]}" "${msg[from]}: $fact"
target=${msg[from]}
fi
for (( idx = 0; idx < ${#fact}; idx += 1 )); do
if [[ ${fact:idx:1} = % ]] && (( idx + 1 < ${#fact} )); then
(( idx += 1 ))
case ${fact:idx:1} in
t)
fmt_fact+=$target
;;
c)
fmt_fact+=${msg[from]}
;;
r)
fmt_fact+=$(random 0 100)
;;
*)
fmt_fact+=${fact:idx:1}
esac
else
fmt_fact+=${fact:idx:1}
fi
done
irc_privmsg "${msg[to]}" "$target: $fmt_fact"
fi
}