Break infinite regain/release loops redux
This commit is contained in:
parent
11d626ab25
commit
1f7b5ee6a3
@ -48,6 +48,9 @@ def unhandled(cli, prefix, cmd, *args):
|
||||
fn.caller(cli, prefix, *args)
|
||||
|
||||
def connect_callback(cli):
|
||||
regaincount = 0
|
||||
releasecount = 0
|
||||
|
||||
@hook("endofmotd", hookid=294)
|
||||
@hook("nomotd", hookid=294)
|
||||
def prepare_stuff(cli, prefix, *args):
|
||||
@ -82,28 +85,27 @@ def connect_callback(cli):
|
||||
users.Bot.change_nick(botconfig.NICK)
|
||||
|
||||
def mustregain(cli, server, bot_nick, nick, msg):
|
||||
if not botconfig.PASS or bot_nick == nick:
|
||||
if not botconfig.PASS or bot_nick == nick or regaincount > 3:
|
||||
return
|
||||
if var.NICKSERV_REGAIN_COMMAND:
|
||||
cli.ns_regain(nick=botconfig.NICK, password=botconfig.PASS, nickserv=var.NICKSERV, command=var.NICKSERV_REGAIN_COMMAND)
|
||||
else:
|
||||
cli.ns_ghost(nick=botconfig.NICK, password=botconfig.PASS, nickserv=var.NICKSERV, command=var.NICKSERV_GHOST_COMMAND)
|
||||
# infinite loops are bad
|
||||
hook.unhook(241)
|
||||
# it is possible (though unlikely) that regaining the nick fails for some reason and we would loop infinitely
|
||||
# as such, keep track of a count of how many times we regain, and after 3 times we no longer attempt to regain nicks
|
||||
# Since we'd only be regaining on initial connect, this should be safe. The same trick is used below for release as well
|
||||
regaincount += 1
|
||||
users.Bot.change_nick(botconfig.NICK)
|
||||
hook("nicknameinuse", hookid=241)(mustregain)
|
||||
|
||||
def mustrelease(cli, server, bot_nick, nick, msg):
|
||||
if not botconfig.PASS or bot_nick == nick:
|
||||
if not botconfig.PASS or bot_nick == nick or releasecount > 3:
|
||||
return # prevents the bot from trying to release without a password
|
||||
if var.NICKSERV_RELEASE_COMMAND:
|
||||
cli.ns_release(nick=botconfig.NICK, password=botconfig.PASS, nickserv=var.NICKSERV, command=var.NICKSERV_GHOST_COMMAND)
|
||||
else:
|
||||
cli.ns_ghost(nick=botconfig.NICK, password=botconfig.PASS, nickserv=var.NICKSERV, command=var.NICKSERV_GHOST_COMMAND)
|
||||
# if releasing doesn't work, don't go into infinite loop, just run with our _ showing
|
||||
hook.unhook(240)
|
||||
releasecount += 1
|
||||
users.Bot.change_nick(botconfig.NICK)
|
||||
hook("unavailresource", hookid=240)(mustrelease)
|
||||
|
||||
@hook("unavailresource", hookid=239)
|
||||
@hook("nicknameinuse", hookid=239)
|
||||
|
Loading…
Reference in New Issue
Block a user