diff --git a/rowbot b/rowbot index b67fba0..0136408 100755 --- a/rowbot +++ b/rowbot @@ -4,7 +4,7 @@ # feature switch toggling ### -shopt -s dotglob extglob lastpipe nullglob +shopt -s dotglob extglob nullglob ### # utility and helper functions @@ -31,7 +31,7 @@ die() { } get_option() { - if (( $# != 2 )); then + if (( ! $# )); then return 1 fi @@ -44,7 +44,7 @@ get_option() { config[$1]=${opts[$1]} elif [[ -v $var_name ]]; then config[$1]=${!var_name} - else + elif (( $# > 1 )); then config[$1]=$2 fi } @@ -65,6 +65,10 @@ is_reloaded() { [[ $RELOADED = yes ]] || (( LORE_LIVES > 1 )) } +is_running () { + kill -0 "$1" 2>/dev/null +} + random() { local min=$1 max=$2 (( (RANDOM % max) + min )) @@ -141,15 +145,6 @@ unset key file declare -A config -# irc registration settings - -get_option nick rowbot-dev -get_option ident rowbot -get_option realname rowbot -get_option chan "" - -# bot control settings - get_option owner "${USER:-uplime}" get_option trigger \` get_option dev yes @@ -160,12 +155,15 @@ get_option dev yes on_sys_first_001_bootup() { log_info "rowbot's pid is %d" "$$" + get_option nick rowbot-dev + get_option ident rowbot + get_option realname rowbot } on_sys_first_999_bootup() { log_debug "registering with the server" - nick "${config[nick]}" - user "${config[ident]}" "${config[realname]}" + irc_nick "${config[nick]}" + irc_user "${config[ident]}" "${config[realname]}" } on_sys_before_999_bootup() { @@ -351,7 +349,7 @@ on_sys_after_002_net() { unset IRC_SOCK else sock_dir=$SOCK_DIR tls_pid=$TLS_PID out_sock=$OUT_SOCK in_sock=$IN_SOCK - unset sock_dir tls_pid out_sock in_sock + unset SOCK_DIR TLS_PID OUT_SOCK IN_SOCK fi } @@ -370,15 +368,100 @@ on_sys_exit_998_net() { fi } +### +# irc magic +### + +magic_annoyatron900() { + irc_ping "row your bot gently down the stream" +} + +on_sys_init_999_magic() { + get_option chan "" +} + +on_sys_before_999_magic() { + if [[ -v alarm_pid ]]; then + export ALARM_PID=$alarm_pid + fi +} + +on_sys_after_999_magic() { + trap magic_annoyatron900 USR1 + + if [[ -v ALARM_PID ]]; then + alarm_pid=$ALARM_PID + fi +} + +on_sys_register_999_magic() { + if [[ ${config[chan]} ]]; then + irc_join "$chan" + fi + + while true; do + read -rt 10