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,20 +1371,23 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
nick %= conf.supybot.nick() nick %= conf.supybot.nick()
else: else:
nick %= network_nick nick %= network_nick
return nick if nick not in self.triedNicks:
else: self.triedNicks.add(nick)
nick = conf.supybot.nick() return nick
network_nick = conf.supybot.networks.get(self.network).nick()
if network_nick != '': nick = conf.supybot.nick()
nick = network_nick network_nick = conf.supybot.networks.get(self.network).nick()
ret = nick if network_nick != '':
L = list(nick) nick = network_nick
while len(L) <= 3: ret = nick
L.append('`') L = list(nick)
while ircutils.strEqual(ret, nick): while len(L) <= 3:
L[random.randrange(len(L))] = utils.iter.choice('0123456789') L.append('`')
ret = ''.join(L) while ret in self.triedNicks:
return ret L[random.randrange(len(L))] = utils.iter.choice('0123456789')
ret = ''.join(L)
self.triedNicks.add(ret)
return ret
def do002(self, msg): def do002(self, msg):
"""Logs the ircd version.""" """Logs the ircd version."""