irclib: Don't return the same nick twice when duplicates in supybot.nick.alternates + supybot.nick.

It migt crash on: 'assert newNick != self.nick'
This commit is contained in:
Valentin Lorentz 2019-01-27 09:10:06 +01:00
parent d20e418fd0
commit 624553c069

View File

@ -978,6 +978,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
self.user = ircutils.standardSubstitute(self, None, get_value('user')) self.user = ircutils.standardSubstitute(self, None, get_value('user'))
self.ident = get_value('ident') self.ident = get_value('ident')
self.alternateNicks = conf.supybot.nick.alternates()[:] self.alternateNicks = conf.supybot.nick.alternates()[:]
self.triedNicks = ircutils.IrcSet()
self.password = network_config.password() self.password = network_config.password()
self.prefix = '%s!%s@%s' % (self.nick, self.ident, 'unset.domain') self.prefix = '%s!%s@%s' % (self.nick, self.ident, 'unset.domain')
# The rest. # The rest.
@ -1370,8 +1371,10 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
nick %= conf.supybot.nick() nick %= conf.supybot.nick()
else: else:
nick %= network_nick nick %= network_nick
if nick not in self.triedNicks:
self.triedNicks.add(nick)
return nick return nick
else:
nick = conf.supybot.nick() nick = conf.supybot.nick()
network_nick = conf.supybot.networks.get(self.network).nick() network_nick = conf.supybot.networks.get(self.network).nick()
if network_nick != '': if network_nick != '':
@ -1380,9 +1383,10 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
L = list(nick) L = list(nick)
while len(L) <= 3: while len(L) <= 3:
L.append('`') L.append('`')
while ircutils.strEqual(ret, nick): while ret in self.triedNicks:
L[random.randrange(len(L))] = utils.iter.choice('0123456789') L[random.randrange(len(L))] = utils.iter.choice('0123456789')
ret = ''.join(L) ret = ''.join(L)
self.triedNicks.add(ret)
return ret return ret
def do002(self, msg): def do002(self, msg):