From a0701541979747c61e706fa115f15d9a92dde8a0 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 19 Jul 2021 16:43:44 -0500 Subject: [PATCH] Add format specifiers to factoids --- rowbot | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/rowbot b/rowbot index 9f153a3..cc2da8b 100755 --- a/rowbot +++ b/rowbot @@ -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 }