From 3a824f6d44c0bd3c7bd902a88c4406c99f374ca2 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 12 Jul 2021 00:22:31 -0500 Subject: [PATCH] Add plugin support --- rowbot | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/rowbot b/rowbot index 879d856..b530574 100755 --- a/rowbot +++ b/rowbot @@ -614,6 +614,64 @@ irc_on_473() { log_error "%s: %s" "${msg_args[1]}" "${msg_args[2]}" } +### +# plugin api +### + +plugin_reg() { + declare -n plugins=irc_plugin_array_"$1" + local plugin + + if [[ -v plugins ]]; then + for plugin in "${plugins[@]}"; do + if [[ $plugin = "$2" ]]; then + return 1 + fi + done + else + plugins=( ) + fi + + plugins+=( "$2" ) +} + +plugin_run() { + # This is a false positive. + # shellcheck disable=SC2178 + declare -n plugins=irc_plugin_array_"$1" + shift + local plugin + + if [[ -v plugins ]]; then + for plugin in "${plugins[@]}"; do + "$plugin" "$@" + done + fi +} + +### +# plugins +### + +# lime-o-meter + +limeometer() { + # We don't care about failures here, for better or for worse. + # shellcheck disable=SC2155 + local limes=$(random 1 42) limeification + + if [[ ${msg[from]} = Time-Warp ]]; then + limes=42 + fi + + (( limeification = (limes * 100) / 42 )) + irc_privmsg "${msg[to]}" "$limes limes (limes to $limeification%)" +} + +on_init_limeometer() { + plugin_reg uplime limeometer +} + ### # irc send handlers ### @@ -806,5 +864,6 @@ while net_recv line; do # This variable will be used in later code. # shellcheck disable=SC2034 read -ra action_args <<< "$action_line" + plugin_run "$action" fi done