Skip to content

Commit

Permalink
Allow network-specific nicks. Closes GH-134.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Oct 27, 2011
1 parent ceabe07 commit e253fe1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
16 changes: 10 additions & 6 deletions plugins/NickCapture/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ def __init__(self, irc):
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.
Expand All @@ -76,19 +80,19 @@ def _sendNick(self, irc, nick):
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)
Expand Down
26 changes: 15 additions & 11 deletions plugins/Services/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ def outFilter(self, irc, msg):
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.
Expand All @@ -100,7 +104,7 @@ def _doIdentify(self, irc, nick=None):
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')
Expand All @@ -122,7 +126,7 @@ def _doGhost(self, irc, nick=None):
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')
Expand Down Expand Up @@ -150,7 +154,7 @@ def __call__(self, irc, msg):
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')
Expand All @@ -172,7 +176,7 @@ def do001(self, irc, msg):
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')
Expand All @@ -196,7 +200,7 @@ def do376(self, irc, msg):
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:
Expand All @@ -210,15 +214,15 @@ def do515(self, irc, msg):
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)
elif ircutils.strEqual(msg.nick, nick):
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))

Expand Down Expand Up @@ -267,7 +271,7 @@ def doChanservNotice(self, irc, msg):
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)
Expand Down Expand Up @@ -509,7 +513,7 @@ def ghost(self, irc, msg, args, nick):
"""
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:
Expand Down
11 changes: 11 additions & 0 deletions src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def setValue(self, v):
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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/irclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ def reset(self):
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()[:]
Expand Down Expand Up @@ -914,10 +917,17 @@ def _getNextNick(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -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)'

0 comments on commit e253fe1

Please sign in to comment.