Allow network-specific nicks. Closes GH-134.

This commit is contained in:
Valentin Lorentz 2011-10-27 12:31:37 +02:00
parent ceabe070a0
commit e253fe1543
5 changed files with 48 additions and 19 deletions

View File

@ -46,12 +46,16 @@ class NickCapture(callbacks.Plugin):
self.__parent.__init__(irc)
self.lastIson = 0
def _getNick(self):
return conf.supybot.nick()
def _getNick(self, network):
network_nick = conf.supybot.networks.get(network).nick()
if network_nick == '':
return conf.supybot.nick()
else:
return network_nick
def __call__(self, irc, msg):
if irc.afterConnect:
nick = self._getNick()
nick = self._getNick(irc.network)
if nick and not ircutils.strEqual(nick, irc.nick):
# We used to check this, but nicksToHostmasks is never cleared
# except on reconnects, which can cause trouble.
@ -76,19 +80,19 @@ class NickCapture(callbacks.Plugin):
irc.sendMsg(ircmsgs.nick(nick))
def doQuit(self, irc, msg):
nick = self._getNick()
nick = self._getNick(irc.network)
if ircutils.strEqual(msg.nick, nick):
self._sendNick(irc, nick)
def doNick(self, irc, msg):
nick = self._getNick()
nick = self._getNick(irc.network)
if ircutils.strEqual(msg.nick, nick):
self._sendNick(irc, nick)
def do303(self, irc, msg):
"""This is returned by the ISON command."""
if not msg.args[1]:
nick = self._getNick()
nick = self._getNick(irc.network)
if nick:
self._sendNick(irc, nick)
NickCapture = internationalizeDocstring(NickCapture)

View File

@ -83,8 +83,12 @@ class Services(callbacks.Plugin):
return None
return msg
def _getNick(self):
return conf.supybot.nick()
def _getNick(self, network):
network_nick = conf.supybot.networks.get(network).nick()
if network_nick == '':
return conf.supybot.nick()
else:
return network_nick
def _getNickServPassword(self, nick):
# This should later be nick-specific.
@ -100,7 +104,7 @@ class Services(callbacks.Plugin):
if self.disabled(irc):
return
if nick is None:
nick = self._getNick()
nick = self._getNick(irc.network)
if nick not in self.registryValue('nicks'):
return
nickserv = self.registryValue('NickServ')
@ -122,7 +126,7 @@ class Services(callbacks.Plugin):
if self.disabled(irc):
return
if nick is None:
nick = self._getNick()
nick = self._getNick(irc.network)
if nick not in self.registryValue('nicks'):
return
nickserv = self.registryValue('NickServ')
@ -150,7 +154,7 @@ class Services(callbacks.Plugin):
self.__parent.__call__(irc, msg)
if self.disabled(irc):
return
nick = self._getNick()
nick = self._getNick(irc.network)
if nick not in self.registryValue('nicks'):
return
nickserv = self.registryValue('NickServ')
@ -172,7 +176,7 @@ class Services(callbacks.Plugin):
def do376(self, irc, msg):
if self.disabled(irc):
return
nick = self._getNick()
nick = self._getNick(irc.network)
if nick not in self.registryValue('nicks'):
return
nickserv = self.registryValue('NickServ')
@ -196,7 +200,7 @@ class Services(callbacks.Plugin):
def do433(self, irc, msg):
if self.disabled(irc):
return
nick = self._getNick()
nick = self._getNick(irc.network)
if nick not in self.registryValue('nicks'):
return
if nick and irc.afterConnect:
@ -210,7 +214,7 @@ class Services(callbacks.Plugin):
self.channels.append(msg.args[1])
def doNick(self, irc, msg):
nick = self._getNick()
nick = self._getNick(irc.network)
if ircutils.strEqual(msg.args[0], irc.nick) and \
ircutils.strEqual(irc.nick, nick):
self._doIdentify(irc)
@ -218,7 +222,7 @@ class Services(callbacks.Plugin):
irc.sendMsg(ircmsgs.nick(nick))
def _ghosted(self, s):
nick = self._getNick()
nick = self._getNick(irc.network)
lowered = s.lower()
return bool('killed' in lowered and (nick in s or 'ghost' in lowered))
@ -267,7 +271,7 @@ class Services(callbacks.Plugin):
def doNickservNotice(self, irc, msg):
if self.disabled(irc):
return
nick = self._getNick()
nick = self._getNick(irc.network)
s = ircutils.stripFormatting(msg.args[1].lower())
on = 'on %s' % irc.network
networkGroup = conf.supybot.networks.get(irc.network)
@ -509,7 +513,7 @@ class Services(callbacks.Plugin):
"""
if self.registryValue('NickServ'):
if not nick:
nick = self._getNick()
nick = self._getNick(irc.network)
if ircutils.strEqual(nick, irc.nick):
irc.error(_('I cowardly refuse to ghost myself.'))
else:

View File

@ -139,6 +139,14 @@ class ValidNick(registry.String):
else:
registry.String.setValue(self, v)
class ValidNickOrEmpty(ValidNick):
"""Value must be a valid IRC nick or empty."""
def setValue(self, v):
if v != '' and not ircutils.isNick(v):
self.error()
else:
registry.String.setValue(self, v)
class ValidNicks(registry.SpaceSeparatedListOf):
Value = ValidNick
@ -277,6 +285,9 @@ def registerNetwork(name, password='', ssl=False, sasl_username=''):
registerChannelValue(network.channels, 'key', registry.String('',
_("""Determines what key (if any) will be used to join the
channel.""")))
registerGlobalValue(network, 'nick', ValidNickOrEmpty('', _("""Determines
what nick the bot will use on this network. If empty, defaults to
supybot.nick.""")))
sasl = registerGroup(network, 'sasl')
registerGlobalValue(sasl, 'username', registry.String(sasl_username,
_("""Determines what SASL username will be used on %s. This should

View File

@ -859,6 +859,9 @@ class Irc(IrcCommandDispatcher):
def _setNonResettingVariables(self):
# Configuration stuff.
self.nick = conf.supybot.nick()
network_nick = conf.supybot.networks.get(self.network).nick()
if network_nick != '':
self.nick = network_nick
self.user = conf.supybot.user()
self.ident = conf.supybot.ident()
self.alternateNicks = conf.supybot.nick.alternates()[:]
@ -914,10 +917,17 @@ class Irc(IrcCommandDispatcher):
if self.alternateNicks:
nick = self.alternateNicks.pop(0)
if '%s' in nick:
nick %= conf.supybot.nick()
network_nick = conf.supybot.networks.get(self.network).nick()
if network_nick == '':
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:

View File

@ -1,3 +1,3 @@
"""stick the various versioning attributes in here, so we only have to change
them once."""
version = '0.83.4.1+limnoria (2011-10-27T11:56:13+0200)'
version = '0.83.4.1+limnoria (2011-10-27T12:31:37+0200)'