mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Minor code cleanup.
This commit is contained in:
parent
d9fcd25ac1
commit
eca71949b4
@ -133,8 +133,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
def __call__(self, irc, msg):
|
def __call__(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
try:
|
try:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
self.ircstates[irc].addMsg(irc, self.lastmsg[irc])
|
self.ircstates[irc].addMsg(irc, self.lastmsg[irc])
|
||||||
finally:
|
finally:
|
||||||
self.lastmsg[irc] = msg
|
self.lastmsg[irc] = msg
|
||||||
@ -143,16 +142,19 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
def die(self):
|
def die(self):
|
||||||
callbacks.Privmsg.die(self)
|
callbacks.Privmsg.die(self)
|
||||||
configurable.Mixin.die(self)
|
configurable.Mixin.die(self)
|
||||||
for irc in self.abbreviations:
|
# Let's not kill the ircs, so we can reload this plugin.
|
||||||
if irc != originalIrc:
|
|
||||||
irc.callbacks[:] = []
|
|
||||||
irc.die()
|
|
||||||
|
|
||||||
def do376(self, irc, msg):
|
def do376(self, irc, msg):
|
||||||
if self.channels:
|
if self.channels:
|
||||||
irc.queueMsg(ircmsgs.joins(self.channels))
|
irc.queueMsg(ircmsgs.joins(self.channels))
|
||||||
do377 = do422 = do376
|
do377 = do422 = do376
|
||||||
|
|
||||||
|
def _getRealIrc(self, irc):
|
||||||
|
if isinstance(irc, irclib.Irc):
|
||||||
|
return irc
|
||||||
|
else:
|
||||||
|
return irc.getRealIrc()
|
||||||
|
|
||||||
def start(self, irc, msg, args):
|
def start(self, irc, msg, args):
|
||||||
"""<network abbreviation for current server>
|
"""<network abbreviation for current server>
|
||||||
|
|
||||||
@ -164,10 +166,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
will show up as 'user@oftc'.
|
will show up as 'user@oftc'.
|
||||||
"""
|
"""
|
||||||
global originalIrc
|
global originalIrc
|
||||||
if isinstance(irc, irclib.Irc):
|
realIrc = self._getRealIrc(irc)
|
||||||
realIrc = irc
|
|
||||||
else:
|
|
||||||
realIrc = irc.getRealIrc()
|
|
||||||
originalIrc = realIrc
|
originalIrc = realIrc
|
||||||
abbreviation = privmsgs.getArgs(args)
|
abbreviation = privmsgs.getArgs(args)
|
||||||
self.ircs[abbreviation] = realIrc
|
self.ircs[abbreviation] = realIrc
|
||||||
@ -189,10 +188,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
irc.error(msg, 'You must use the start command first.')
|
irc.error(msg, 'You must use the start command first.')
|
||||||
return
|
return
|
||||||
abbreviation, server = privmsgs.getArgs(args, required=2)
|
abbreviation, server = privmsgs.getArgs(args, required=2)
|
||||||
if isinstance(irc, irclib.Irc):
|
realIrc = self._getRealIrc(irc)
|
||||||
realIrc = irc
|
|
||||||
else:
|
|
||||||
realIrc = irc.getRealIrc()
|
|
||||||
if ':' in server:
|
if ':' in server:
|
||||||
(server, port) = server.split(':')
|
(server, port) = server.split(':')
|
||||||
port = int(port)
|
port = int(port)
|
||||||
@ -326,10 +322,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
if not self.started:
|
if not self.started:
|
||||||
irc.error(msg, 'You must use the start command first.')
|
irc.error(msg, 'You must use the start command first.')
|
||||||
return
|
return
|
||||||
if isinstance(irc, irclib.Irc):
|
realIrc = self._getRealIrc(irc)
|
||||||
realIrc = irc
|
|
||||||
else:
|
|
||||||
realIrc = irc.getRealIrc()
|
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
irc.error(msg, 'I\'m not relaying %s.' % channel)
|
irc.error(msg, 'I\'m not relaying %s.' % channel)
|
||||||
@ -381,10 +374,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
irc.error(msg, 'You must use the start command first.')
|
irc.error(msg, 'You must use the start command first.')
|
||||||
return
|
return
|
||||||
nickAtNetwork = privmsgs.getArgs(args)
|
nickAtNetwork = privmsgs.getArgs(args)
|
||||||
if isinstance(irc, irclib.Irc):
|
realIrc = self._getRealIrc(irc)
|
||||||
realIrc = irc
|
|
||||||
else:
|
|
||||||
realIrc = irc.getRealIrc()
|
|
||||||
try:
|
try:
|
||||||
(nick, network) = nickAtNetwork.split('@', 1)
|
(nick, network) = nickAtNetwork.split('@', 1)
|
||||||
if not ircutils.isNick(nick):
|
if not ircutils.isNick(nick):
|
||||||
@ -409,8 +399,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
self._whois[(otherIrc, nick)] = (irc, msg, {})
|
self._whois[(otherIrc, nick)] = (irc, msg, {})
|
||||||
|
|
||||||
def do311(self, irc, msg):
|
def do311(self, irc, msg):
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
nick = ircutils.toLower(msg.args[1])
|
nick = ircutils.toLower(msg.args[1])
|
||||||
if (irc, nick) not in self._whois:
|
if (irc, nick) not in self._whois:
|
||||||
return
|
return
|
||||||
@ -424,8 +413,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
do320 = do311
|
do320 = do311
|
||||||
|
|
||||||
def do318(self, irc, msg):
|
def do318(self, irc, msg):
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
nick = ircutils.toLower(msg.args[1])
|
nick = ircutils.toLower(msg.args[1])
|
||||||
if (irc, nick) not in self._whois:
|
if (irc, nick) not in self._whois:
|
||||||
return
|
return
|
||||||
@ -490,8 +478,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
del self._whois[(irc, nick)]
|
del self._whois[(irc, nick)]
|
||||||
|
|
||||||
def do402(self, irc, msg):
|
def do402(self, irc, msg):
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
nick = ircutils.toLower(msg.args[1])
|
nick = ircutils.toLower(msg.args[1])
|
||||||
if (irc, nick) not in self._whois:
|
if (irc, nick) not in self._whois:
|
||||||
return
|
return
|
||||||
@ -531,9 +518,8 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
otherIrc.queueMsg(msg)
|
otherIrc.queueMsg(msg)
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
if not isinstance(irc, irclib.Irc):
|
|
||||||
irc = irc.getRealIrc()
|
|
||||||
if self.started and ircutils.isChannel(msg.args[0]):
|
if self.started and ircutils.isChannel(msg.args[0]):
|
||||||
|
irc = self._getRealIrc(irc)
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel not in self.channels or ircutils.isCtcp(msg):
|
if channel not in self.channels or ircutils.isCtcp(msg):
|
||||||
return
|
return
|
||||||
@ -544,8 +530,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doJoin(self, irc, msg):
|
def doJoin(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
return
|
return
|
||||||
@ -556,8 +541,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doPart(self, irc, msg):
|
def doPart(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
return
|
return
|
||||||
@ -568,8 +552,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doMode(self, irc, msg):
|
def doMode(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
return
|
return
|
||||||
@ -581,8 +564,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doKick(self, irc, msg):
|
def doKick(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel not in self.channels:
|
if channel not in self.channels:
|
||||||
return
|
return
|
||||||
@ -598,8 +580,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doNick(self, irc, msg):
|
def doNick(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
newNick = msg.args[0]
|
newNick = msg.args[0]
|
||||||
network = self.abbreviations[irc]
|
network = self.abbreviations[irc]
|
||||||
s = 'nick change by %s to %s on %s' % (msg.nick, newNick, network)
|
s = 'nick change by %s to %s on %s' % (msg.nick, newNick, network)
|
||||||
@ -610,8 +591,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doTopic(self, irc, msg):
|
def doTopic(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
if msg.nick == irc.nick:
|
if msg.nick == irc.nick:
|
||||||
return
|
return
|
||||||
(channel, newTopic) = msg.args
|
(channel, newTopic) = msg.args
|
||||||
@ -625,8 +605,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
|
|
||||||
def doQuit(self, irc, msg):
|
def doQuit(self, irc, msg):
|
||||||
if self.started:
|
if self.started:
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
network = self.abbreviations[irc]
|
network = self.abbreviations[irc]
|
||||||
if msg.args:
|
if msg.args:
|
||||||
s = '%s has quit %s (%s)' % (msg.nick, network, msg.args[0])
|
s = '%s has quit %s (%s)' % (msg.nick, network, msg.args[0])
|
||||||
@ -640,8 +619,7 @@ class Relay(callbacks.Privmsg, configurable.Mixin):
|
|||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
if not self.started:
|
if not self.started:
|
||||||
return msg
|
return msg
|
||||||
if not isinstance(irc, irclib.Irc):
|
irc = self._getRealIrc(irc)
|
||||||
irc = irc.getRealIrc()
|
|
||||||
if msg.command == 'PRIVMSG':
|
if msg.command == 'PRIVMSG':
|
||||||
abbreviations = self.abbreviations.values()
|
abbreviations = self.abbreviations.values()
|
||||||
rPrivmsg = re.compile(r'<[^@]+@(?:%s)>' % '|'.join(abbreviations))
|
rPrivmsg = re.compile(r'<[^@]+@(?:%s)>' % '|'.join(abbreviations))
|
||||||
|
Loading…
Reference in New Issue
Block a user