From 624553c069b58eb4555467814acc3be1127195a2 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 27 Jan 2019 09:10:06 +0100 Subject: [PATCH] irclib: Don't return the same nick twice when duplicates in supybot.nick.alternates + supybot.nick. It migt crash on: 'assert newNick != self.nick' --- src/irclib.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/irclib.py b/src/irclib.py index 078176e14..23d473152 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -978,6 +978,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled): self.user = ircutils.standardSubstitute(self, None, get_value('user')) self.ident = get_value('ident') self.alternateNicks = conf.supybot.nick.alternates()[:] + self.triedNicks = ircutils.IrcSet() self.password = network_config.password() self.prefix = '%s!%s@%s' % (self.nick, self.ident, 'unset.domain') # The rest. @@ -1370,20 +1371,23 @@ class Irc(IrcCommandDispatcher, log.Firewalled): nick %= conf.supybot.nick() else: nick %= network_nick - return nick - else: - nick = conf.supybot.nick() - network_nick = conf.supybot.networks.get(self.network).nick() - if network_nick != '': - nick = network_nick - ret = nick - L = list(nick) - while len(L) <= 3: - L.append('`') - while ircutils.strEqual(ret, nick): - L[random.randrange(len(L))] = utils.iter.choice('0123456789') - ret = ''.join(L) - return ret + if nick not in self.triedNicks: + self.triedNicks.add(nick) + return nick + + nick = conf.supybot.nick() + network_nick = conf.supybot.networks.get(self.network).nick() + if network_nick != '': + nick = network_nick + ret = nick + L = list(nick) + while len(L) <= 3: + L.append('`') + while ret in self.triedNicks: + L[random.randrange(len(L))] = utils.iter.choice('0123456789') + ret = ''.join(L) + self.triedNicks.add(ret) + return ret def do002(self, msg): """Logs the ircd version."""