From 0afef8ef68f067d57b79ece1177019af47c50813 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 19 Jun 2021 01:35:33 -0500 Subject: [PATCH 1/3] Allow the bot to keep trying for the desired nick --- rowbot | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rowbot b/rowbot index ebda271..2cbba88 100755 --- a/rowbot +++ b/rowbot @@ -274,6 +274,7 @@ on_001() { ping_pid=$! nick=${params[0]} + registered=yes who "$nick" %%uht,42 } @@ -375,6 +376,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]}" } @@ -469,6 +478,11 @@ who() { ping-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 @@ -664,6 +678,20 @@ 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 ### @@ -673,6 +701,7 @@ trap ping-handler ALRM if [[ $reload = yes ]]; then privmsg "$RELOAD_TO" done. else + registered=no nick "$nick" user "$ident" "$realname" fi From 5094636435269111abdcc88440b5e12f358f3361 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 19 Jun 2021 01:39:27 -0500 Subject: [PATCH 2/3] Give ping-handler a more appropriate name --- rowbot | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rowbot b/rowbot index 2cbba88..6a88089 100755 --- a/rowbot +++ b/rowbot @@ -476,7 +476,7 @@ who() { # keepalive code ### -ping-handler() { +alarm-handler() { ping "row your bot gently down the stream" if [[ $keep_trying = yes ]]; then @@ -485,7 +485,7 @@ ping-handler() { fi } -trap ping-handler ALRM +trap alarm-handler ALRM ### # app hooks @@ -696,8 +696,6 @@ hook_post_NICK_alternick() { # driver ### -trap ping-handler ALRM - if [[ $reload = yes ]]; then privmsg "$RELOAD_TO" done. else From c570d399cbaec273867f9678d07279cc93f57587 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 19 Jun 2021 01:52:29 -0500 Subject: [PATCH 3/3] Make the nick retry logic reloadable --- rowbot | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rowbot b/rowbot index 6a88089..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 @@ -618,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