diff --git a/rowbot b/rowbot index ebda271..0f2c43f 100755 --- a/rowbot +++ b/rowbot @@ -140,9 +140,14 @@ trap cleanup EXIT if [[ $reload = yes ]]; then in_sock=$IN_SOCK out_sock=$OUT_SOCK trigger=$TRIGGER dev=$DEV level=$LOG_LEVEL + registered=$REGISTERED debug "doing a reload. pid is %d" "$$" + if [[ -v KEEP_TRYING ]]; then + keep_trying=$KEEP_TRYING desired_nick=$DESIRED + fi + if [[ $tls = yes ]]; then sock_dir=$SOCK_DIR tls_pid=$tls_pid @@ -274,6 +279,7 @@ on_001() { ping_pid=$! nick=${params[0]} + registered=yes who "$nick" %%uht,42 } @@ -375,6 +381,14 @@ on_376() { debug %s "${params[1]}" } +on_433() { + info "somebody is already using %s" "${params[1]}" + + if [[ $registered = no ]]; then + nick "${nick}_" + fi +} + on_473() { error "%s: %s" "${params[1]}" "${params[2]}" } @@ -467,11 +481,16 @@ who() { # keepalive code ### -ping-handler() { +alarm-handler() { ping "row your bot gently down the stream" + + if [[ $keep_trying = yes ]]; then + info "trying for %s again" "$desired_nick" + nick "$desired_nick" + fi } -trap ping-handler ALRM +trap alarm-handler ALRM ### # app hooks @@ -604,7 +623,11 @@ hook_post_PRIVMSG_control_panel() { reload) export IN_SOCK=$in_sock OUT_SOCK=$out_sock LOG_FD=$log DEV=$dev export RELOAD_TO=$to TRIGGER=$trigger LOG_LEVEL=$level - export NICK=$nick IDENT=$ident + export NICK=$nick IDENT=$ident REGISTERED=$registered + + if [[ $keep_trying = yes ]]; then + export KEEP_TRYING=yes DESIRED=$desired_nick + fi if [[ -v host ]]; then export HOST=$host @@ -664,15 +687,28 @@ hook_post_PRIVMSG_control_panel() { fi } +hook_post_433_alternick() { + if [[ -z $desired_nick && $registered = no ]]; then + desired_nick=${params[1]} + keep_trying=yes + fi +} + +hook_post_NICK_alternick() { + if [[ ${params[0]} = $desired_nick ]]; then + keep_trying=no + info "obtained nick %s" "$desired_nick" + fi +} + ### # driver ### -trap ping-handler ALRM - if [[ $reload = yes ]]; then privmsg "$RELOAD_TO" done. else + registered=no nick "$nick" user "$ident" "$realname" fi