2003-03-12 07:26:59 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
|
|
|
# Copyright (c) 2002, Jeremiah Fincher
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
2003-03-26 09:39:50 +01:00
|
|
|
"""
|
|
|
|
Handles relaying between networks.
|
|
|
|
"""
|
|
|
|
|
2003-03-12 07:26:59 +01:00
|
|
|
from baseplugin import *
|
|
|
|
|
2003-03-27 09:17:51 +01:00
|
|
|
import re
|
2003-06-22 18:17:33 +02:00
|
|
|
import time
|
2003-03-27 09:17:51 +01:00
|
|
|
|
2003-04-20 01:51:11 +02:00
|
|
|
import conf
|
2003-06-22 18:17:33 +02:00
|
|
|
import utils
|
2003-03-26 09:39:50 +01:00
|
|
|
import ircdb
|
|
|
|
import irclib
|
2003-04-20 02:10:53 +02:00
|
|
|
import drivers
|
2003-03-26 09:39:50 +01:00
|
|
|
import ircmsgs
|
|
|
|
import ircutils
|
2003-03-12 07:26:59 +01:00
|
|
|
import privmsgs
|
|
|
|
import callbacks
|
2003-03-26 09:39:50 +01:00
|
|
|
|
2003-04-08 09:15:45 +02:00
|
|
|
def configure(onStart, afterConnect, advanced):
|
|
|
|
import socket
|
|
|
|
from questions import expect, anything, something, yn
|
|
|
|
onStart.append('load Relay')
|
|
|
|
startNetwork = anything('What is the name of the network you\'re ' \
|
|
|
|
'connecting to first?')
|
|
|
|
onStart.append('startrelay %s' % startNetwork)
|
|
|
|
while yn('Do you want to connect to another network for relaying?') == 'y':
|
|
|
|
network = anything('What is the name of the network you want to ' \
|
|
|
|
'connect to?')
|
|
|
|
server = ''
|
|
|
|
while not server:
|
|
|
|
server = anything('What server does that network use?')
|
|
|
|
try:
|
|
|
|
print 'Looking up %s' % server
|
|
|
|
ip = socket.gethostbyname(server)
|
|
|
|
print 'Found %s (%s)' % (server, ip)
|
|
|
|
except socket.error:
|
|
|
|
print 'Sorry, but I couldn\'t find that server.'
|
|
|
|
server = ''
|
|
|
|
if yn('Does that server require you to connect on a port other than '
|
|
|
|
'the default port for IRC (6667)?') == 'y':
|
|
|
|
port = ''
|
|
|
|
while not port:
|
|
|
|
port = anything('What port is that?')
|
|
|
|
try:
|
|
|
|
int(port)
|
|
|
|
except ValueError:
|
|
|
|
print 'Sorry, but that isn\'t a valid port.'
|
|
|
|
port = ''
|
|
|
|
server = ':'.join((server, port))
|
|
|
|
onStart.append('relayconnect %s %s' % (network, server))
|
|
|
|
channel = anything('What channel would you like to relay between?')
|
|
|
|
afterConnect.append('relayjoin %s' % channel)
|
|
|
|
while yn('Would like to relay between any more channels?') == 'y':
|
|
|
|
channel = anything('What channel?')
|
|
|
|
afterConnect.append('relayjoin %s' % channel)
|
|
|
|
|
|
|
|
|
2003-03-28 02:26:37 +01:00
|
|
|
class Relay(callbacks.Privmsg):
|
2003-03-26 09:39:50 +01:00
|
|
|
def __init__(self):
|
|
|
|
callbacks.Privmsg.__init__(self)
|
2003-03-27 09:24:22 +01:00
|
|
|
self.ircs = {}
|
2003-06-22 18:17:33 +02:00
|
|
|
self.whois = {}
|
2003-03-26 09:39:50 +01:00
|
|
|
self.started = False
|
2003-04-09 19:49:55 +02:00
|
|
|
self.ircstates = {}
|
2003-04-09 21:11:00 +02:00
|
|
|
self.lastmsg = ircmsgs.ping('this is just a fake message')
|
|
|
|
self.channels = set()
|
2003-03-27 09:24:22 +01:00
|
|
|
self.abbreviations = {}
|
2003-03-26 09:39:50 +01:00
|
|
|
|
2003-04-09 19:49:55 +02:00
|
|
|
def inFilter(self, irc, msg):
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
2003-04-09 20:12:38 +02:00
|
|
|
try:
|
2003-04-09 21:11:00 +02:00
|
|
|
self.ircstates[irc].addMsg(irc, self.lastmsg)
|
2003-04-09 20:12:38 +02:00
|
|
|
except KeyError:
|
2003-04-09 21:11:00 +02:00
|
|
|
self.ircstates[irc] = irclib.IrcState()
|
|
|
|
self.ircstates[irc].addMsg(irc, self.lastmsg)
|
|
|
|
self.lastmsg = msg
|
2003-04-09 19:49:55 +02:00
|
|
|
return msg
|
|
|
|
|
2003-03-26 09:39:50 +01:00
|
|
|
def startrelay(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""<network abbreviation for current server>
|
|
|
|
|
|
|
|
This command is necessary to start the Relay plugin; the
|
|
|
|
<network abbreviation> is the abbreviation that the network the
|
|
|
|
bot is currently connected to should be shown as to other networks.
|
|
|
|
For instance, if the network abbreviation is 'oftc', then when
|
|
|
|
relaying messages from that network to other networks, the users
|
|
|
|
will show up as 'user@oftc'.
|
|
|
|
"""
|
2003-03-27 09:24:22 +01:00
|
|
|
realIrc = irc.getRealIrc()
|
|
|
|
abbreviation = privmsgs.getArgs(args)
|
|
|
|
self.ircs[abbreviation] = realIrc
|
|
|
|
self.abbreviations[realIrc] = abbreviation
|
|
|
|
self.started = True
|
|
|
|
irc.reply(msg, conf.replySuccess)
|
2003-03-28 02:26:37 +01:00
|
|
|
startrelay = privmsgs.checkCapability(startrelay, 'owner')
|
2003-03-26 09:39:50 +01:00
|
|
|
|
2003-03-12 07:26:59 +01:00
|
|
|
def relayconnect(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""<network abbreviation> <domain:port> (port defaults to 6667)
|
|
|
|
|
|
|
|
Connects to another network at <domain:port>. The network
|
|
|
|
abbreviation <network abbreviation> is used when relaying messages from
|
|
|
|
that network to other networks.
|
|
|
|
"""
|
2003-03-27 09:24:22 +01:00
|
|
|
abbreviation, server = privmsgs.getArgs(args, needed=2)
|
|
|
|
if ':' in server:
|
|
|
|
(server, port) = server.split(':')
|
|
|
|
port = int(port)
|
2003-03-26 09:39:50 +01:00
|
|
|
else:
|
2003-03-27 09:24:22 +01:00
|
|
|
port = 6667
|
|
|
|
newIrc = irclib.Irc(irc.nick, callbacks=irc.callbacks)
|
2003-04-20 01:51:11 +02:00
|
|
|
driver = drivers.newDriver((server, port), newIrc)
|
2003-04-20 02:00:37 +02:00
|
|
|
newIrc.driver = driver
|
2003-03-27 09:24:22 +01:00
|
|
|
self.ircs[abbreviation] = newIrc
|
|
|
|
self.abbreviations[newIrc] = abbreviation
|
|
|
|
irc.reply(msg, conf.replySuccess)
|
2003-03-28 02:26:37 +01:00
|
|
|
relayconnect = privmsgs.checkCapability(relayconnect, 'owner')
|
2003-03-26 09:39:50 +01:00
|
|
|
|
|
|
|
def relaydisconnect(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""<network>
|
|
|
|
|
|
|
|
Disconnects and ceases to relay to and from the network represented by
|
|
|
|
the network abbreviation <network>.
|
|
|
|
"""
|
2003-03-27 09:24:22 +01:00
|
|
|
network = privmsgs.getArgs(args)
|
|
|
|
otherIrc = self.ircs[network]
|
2003-04-03 10:52:41 +02:00
|
|
|
otherIrc.driver.die()
|
2003-03-28 02:36:00 +01:00
|
|
|
del self.ircs[network]
|
|
|
|
world.ircs.remove(otherIrc)
|
2003-03-31 11:22:48 +02:00
|
|
|
del self.abbreviations[otherIrc]
|
2003-03-28 02:26:37 +01:00
|
|
|
irc.reply(msg, conf.replySuccess)
|
|
|
|
relaydisconnect = privmsgs.checkCapability(relaydisconnect, 'owner')
|
2003-03-26 09:39:50 +01:00
|
|
|
|
|
|
|
def relayjoin(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""<channel>
|
|
|
|
|
|
|
|
Starts relaying between the channel <channel> on all networks. If on a
|
|
|
|
network the bot isn't in <channel>, he'll join. This commands is
|
|
|
|
required even if the bot is in the channel on both networks; he won't
|
|
|
|
relay between those channels unless he's told to relayjoin both
|
|
|
|
channels.
|
|
|
|
"""
|
2003-03-27 09:24:22 +01:00
|
|
|
channel = privmsgs.getArgs(args)
|
2003-04-11 22:42:21 +02:00
|
|
|
self.channels.add(ircutils.toLower(channel))
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
|
|
|
if channel not in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.join(channel))
|
|
|
|
irc.reply(msg, conf.replySuccess)
|
2003-03-28 02:26:37 +01:00
|
|
|
relayjoin = privmsgs.checkCapability(relayjoin, 'owner')
|
2003-03-26 09:39:50 +01:00
|
|
|
|
|
|
|
def relaypart(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""<channel>
|
|
|
|
|
|
|
|
Ceases relaying between the channel <channel> on all networks. The bot
|
|
|
|
will part from the channel on all networks in which it is on the
|
|
|
|
channel.
|
|
|
|
"""
|
2003-03-27 09:24:22 +01:00
|
|
|
channel = privmsgs.getArgs(args)
|
2003-04-11 22:42:21 +02:00
|
|
|
self.channels.remove(ircutils.toLower(channel))
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
|
|
|
if channel in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.part(channel))
|
|
|
|
irc.reply(msg, conf.replySuccess)
|
2003-03-28 02:26:37 +01:00
|
|
|
relaypart = privmsgs.checkCapability(relaypart, 'owner')
|
2003-03-26 09:39:50 +01:00
|
|
|
|
2003-03-27 22:14:28 +01:00
|
|
|
def relaynames(self, irc, msg, args):
|
2003-04-06 11:17:38 +02:00
|
|
|
"""[<channel>] (only if not sent in the channel itself.)
|
|
|
|
|
|
|
|
The <channel> argument is only necessary if the message isn't sent on
|
|
|
|
the channel itself. Returns the nicks of the people in the channel on
|
|
|
|
the various networks the bot is connected to.
|
|
|
|
"""
|
2003-03-27 22:21:20 +01:00
|
|
|
if not isinstance(irc, irclib.Irc):
|
2003-03-27 22:28:15 +01:00
|
|
|
realIrc = irc.getRealIrc()
|
2003-03-27 22:14:28 +01:00
|
|
|
channel = privmsgs.getChannel(msg, args)
|
|
|
|
if channel not in self.channels:
|
2003-04-02 12:07:06 +02:00
|
|
|
irc.error(msg, 'I\'m not relaying %s.' % channel)
|
2003-03-27 22:14:28 +01:00
|
|
|
return
|
|
|
|
users = []
|
|
|
|
for (abbreviation, otherIrc) in self.ircs.iteritems():
|
2003-03-27 22:28:15 +01:00
|
|
|
if abbreviation != self.abbreviations[realIrc]:
|
2003-03-27 22:18:49 +01:00
|
|
|
Channel = otherIrc.state.channels[channel]
|
2003-03-27 22:21:20 +01:00
|
|
|
usersS = ', '.join([s for s in Channel.users if s.strip()!=''])
|
2003-07-23 07:29:16 +02:00
|
|
|
users.append('%s: %s' % (ircutils.bold(abbreviation), usersS))
|
2003-03-27 22:14:28 +01:00
|
|
|
irc.reply(msg, '; '.join(users))
|
2003-06-22 18:17:33 +02:00
|
|
|
|
|
|
|
def relaywhois(self, irc, msg, args):
|
|
|
|
"""<nick>@<network>
|
|
|
|
|
|
|
|
Returns the WHOIS response <network> gives for <nick>.
|
|
|
|
"""
|
|
|
|
nickAtNetwork = privmsgs.getArgs(args)
|
|
|
|
(nick, network) = nickAtNetwork.split('@', 1)
|
|
|
|
if network not in self.ircs:
|
|
|
|
irc.error(msg, 'I\'m not on that network.')
|
|
|
|
return
|
|
|
|
otherIrc = self.ircs[network]
|
|
|
|
otherIrc.queueMsg(ircmsgs.whois(nick))
|
|
|
|
self.whois[(otherIrc, nick)] = (irc, msg, {})
|
|
|
|
|
|
|
|
def do311(self, irc, msg):
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
realIrc = irc.getRealIrc()
|
|
|
|
nick = msg.args[1]
|
|
|
|
if (realIrc, nick) not in self.whois:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.whois[(realIrc, nick)][-1][msg.command] = msg
|
|
|
|
|
|
|
|
do312 = do311
|
|
|
|
do317 = do311
|
|
|
|
do319 = do311
|
|
|
|
|
|
|
|
def do318(self, irc, msg):
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
2003-07-23 03:45:48 +02:00
|
|
|
irc = irc.getRealIrc()
|
2003-06-22 18:17:33 +02:00
|
|
|
nick = msg.args[1]
|
2003-07-23 03:45:48 +02:00
|
|
|
if (irc, nick) not in self.whois:
|
2003-06-22 18:17:33 +02:00
|
|
|
return
|
2003-07-23 03:45:48 +02:00
|
|
|
(replyIrc, replyMsg, d) = self.whois[(irc, nick)]
|
2003-06-22 18:17:33 +02:00
|
|
|
hostmask = '@'.join(d['311'].args[2:])
|
|
|
|
channels = d['319'].args[-1].split()
|
|
|
|
channels = ', and '.join([', '.join(channels[:-1]), channels[-1]])
|
|
|
|
idle = utils.timeElapsed(d['317'].args[2])
|
|
|
|
signon = time.ctime(d['317'][3])
|
|
|
|
s = '%s (%s) has been online since %s (idle for %s) and is on %s' % \
|
|
|
|
(nick, hostmask, signon, idle, channels)
|
|
|
|
replyIrc.reply(replyMsg, s)
|
|
|
|
|
2003-03-27 09:17:51 +01:00
|
|
|
def _formatPrivmsg(self, nick, abbreviation, msg):
|
2003-07-23 07:29:16 +02:00
|
|
|
# colorize nicks
|
2003-07-23 17:24:05 +02:00
|
|
|
colorNumber = (hash(nick) % 14) + 2
|
2003-03-27 09:17:51 +01:00
|
|
|
if ircmsgs.isAction(msg):
|
2003-07-23 07:29:16 +02:00
|
|
|
return '* %s@%s %s' % \
|
2003-07-23 17:24:05 +02:00
|
|
|
(ircutils.mircColor(nick, colorNumber), abbreviation,
|
2003-07-23 07:29:16 +02:00
|
|
|
ircmsgs.unAction(msg))
|
2003-03-27 09:17:51 +01:00
|
|
|
else:
|
2003-07-23 07:29:16 +02:00
|
|
|
return '<%s@%s> %s' % \
|
2003-07-23 17:24:05 +02:00
|
|
|
(ircutils.mircColor(nick, colorNumber),
|
|
|
|
abbreviation, msg.args[1])
|
2003-03-27 09:17:51 +01:00
|
|
|
|
2003-03-26 09:39:50 +01:00
|
|
|
def doPrivmsg(self, irc, msg):
|
|
|
|
callbacks.Privmsg.doPrivmsg(self, irc, msg)
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
|
|
|
if self.started and ircutils.isChannel(msg.args[0]):
|
|
|
|
channel = msg.args[0]
|
2003-03-27 21:10:10 +01:00
|
|
|
if channel not in self.channels:
|
|
|
|
return
|
2003-03-26 09:39:50 +01:00
|
|
|
abbreviation = self.abbreviations[irc]
|
2003-03-27 09:17:51 +01:00
|
|
|
s = self._formatPrivmsg(msg.nick, abbreviation, msg)
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
2003-03-26 09:39:50 +01:00
|
|
|
if otherIrc != irc:
|
2003-04-20 02:00:37 +02:00
|
|
|
if channel in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-03-26 09:39:50 +01:00
|
|
|
|
|
|
|
def doJoin(self, irc, msg):
|
|
|
|
if self.started:
|
2003-03-27 10:14:00 +01:00
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
2003-03-27 21:32:49 +01:00
|
|
|
channel = msg.args[0]
|
|
|
|
if channel not in self.channels:
|
|
|
|
return
|
2003-03-26 09:39:50 +01:00
|
|
|
abbreviation = self.abbreviations[irc]
|
2003-04-30 16:49:09 +02:00
|
|
|
s = '%s (%s) has joined on %s' % (msg.nick,msg.prefix,abbreviation)
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
2003-03-26 09:39:50 +01:00
|
|
|
if otherIrc != irc:
|
2003-03-27 21:32:49 +01:00
|
|
|
if channel in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-03-26 09:39:50 +01:00
|
|
|
|
|
|
|
def doPart(self, irc, msg):
|
|
|
|
if self.started:
|
2003-03-27 10:14:00 +01:00
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
2003-03-27 21:32:49 +01:00
|
|
|
channel = msg.args[0]
|
|
|
|
if channel not in self.channels:
|
|
|
|
return
|
2003-03-26 09:39:50 +01:00
|
|
|
abbreviation = self.abbreviations[irc]
|
2003-04-30 16:49:09 +02:00
|
|
|
s = '%s (%s) has left on %s' % (msg.nick, msg.prefix, abbreviation)
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
2003-03-27 10:15:38 +01:00
|
|
|
if otherIrc != irc:
|
2003-03-27 21:32:49 +01:00
|
|
|
if channel in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-03-26 09:39:50 +01:00
|
|
|
|
2003-03-31 09:04:23 +02:00
|
|
|
def doMode(self, irc, msg):
|
|
|
|
if self.started:
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
|
|
|
channel = msg.args[0]
|
|
|
|
if channel in self.channels:
|
|
|
|
abbreviation = self.abbreviations[irc]
|
2003-04-30 16:49:09 +02:00
|
|
|
s = 'mode change by %s on %s: %s' % \
|
|
|
|
(msg.nick, abbreviation, ' '.join(msg.args[1:]))
|
2003-03-31 09:04:23 +02:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
2003-03-31 11:22:48 +02:00
|
|
|
if otherIrc != irc:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-03-31 09:04:23 +02:00
|
|
|
|
|
|
|
def doNick(self, irc, msg):
|
|
|
|
if self.started:
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
2003-03-31 11:22:48 +02:00
|
|
|
newNick = msg.args[0]
|
|
|
|
s = 'nick change by %s to %s' % (msg.nick, newNick)
|
|
|
|
for channel in self.channels:
|
|
|
|
if newNick in irc.state.channels[channel].users:
|
|
|
|
for otherIrc in self.ircs.itervalues():
|
|
|
|
if otherIrc != irc:
|
2003-03-31 09:04:23 +02:00
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-04-01 09:09:36 +02:00
|
|
|
|
|
|
|
def doQuit(self, irc, msg):
|
|
|
|
if self.started:
|
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
|
|
|
network = self.abbreviations[irc]
|
2003-06-22 18:17:33 +02:00
|
|
|
if msg.args:
|
2003-04-30 16:49:09 +02:00
|
|
|
s = '%s has quit %s (%s)' % (msg.nick, network, msg.args[0])
|
2003-04-01 09:09:36 +02:00
|
|
|
else:
|
2003-04-30 16:49:09 +02:00
|
|
|
s = '%s has quit %s.' % (msg.nick, network)
|
2003-04-01 09:09:36 +02:00
|
|
|
for channel in self.channels:
|
2003-04-09 21:11:00 +02:00
|
|
|
if msg.nick in self.ircstates[irc].channels[channel].users:
|
2003-04-01 09:09:36 +02:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
|
|
|
if otherIrc != irc:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
2003-03-31 09:04:23 +02:00
|
|
|
|
2003-03-27 09:17:51 +01:00
|
|
|
def outFilter(self, irc, msg):
|
2003-03-31 11:22:48 +02:00
|
|
|
if not self.started:
|
|
|
|
return msg
|
2003-03-27 10:14:00 +01:00
|
|
|
if not isinstance(irc, irclib.Irc):
|
|
|
|
irc = irc.getRealIrc()
|
2003-03-27 09:17:51 +01:00
|
|
|
if msg.command == 'PRIVMSG':
|
|
|
|
abbreviations = self.abbreviations.values()
|
2003-03-27 09:56:34 +01:00
|
|
|
rPrivmsg = re.compile(r'<[^@]+@(?:%s)>' % '|'.join(abbreviations))
|
2003-06-05 23:03:22 +02:00
|
|
|
rAction = re.compile(r'\* [^/]+@(?:%s) ' % '|'.join(abbreviations))
|
2003-03-27 21:32:49 +01:00
|
|
|
if not (rPrivmsg.match(msg.args[1]) or \
|
|
|
|
rAction.match(msg.args[1]) or \
|
|
|
|
msg.args[1].find('has left on ') != -1 or \
|
2003-03-31 11:22:48 +02:00
|
|
|
msg.args[1].find('has joined on ') != -1 or \
|
2003-04-09 20:46:41 +02:00
|
|
|
msg.args[1].find('has quit') != -1 or \
|
2003-03-31 11:22:48 +02:00
|
|
|
msg.args[1].startswith('mode change') or \
|
|
|
|
msg.args[1].startswith('nick change')):
|
2003-03-27 09:17:51 +01:00
|
|
|
channel = msg.args[0]
|
2003-03-28 06:36:59 +01:00
|
|
|
if channel in self.channels:
|
|
|
|
abbreviation = self.abbreviations[irc]
|
|
|
|
s = self._formatPrivmsg(irc.nick, abbreviation, msg)
|
|
|
|
for otherIrc in self.ircs.itervalues():
|
|
|
|
if otherIrc != irc:
|
|
|
|
if channel in otherIrc.state.channels:
|
|
|
|
otherIrc.queueMsg(ircmsgs.privmsg(channel, s))
|
|
|
|
elif msg.command == 'TOPIC':
|
|
|
|
(channel, topic) = msg.args
|
|
|
|
if channel in self.channels:
|
2003-03-27 09:24:22 +01:00
|
|
|
for otherIrc in self.ircs.itervalues():
|
2003-03-27 09:17:51 +01:00
|
|
|
if otherIrc != irc:
|
2003-03-28 08:10:23 +01:00
|
|
|
if otherIrc.state.getTopic(channel) != topic:
|
|
|
|
otherIrc.queueMsg(ircmsgs.topic(channel, topic))
|
2003-03-28 06:36:59 +01:00
|
|
|
|
2003-03-27 09:26:36 +01:00
|
|
|
return msg
|
2003-03-27 09:17:51 +01:00
|
|
|
|
2003-03-26 09:39:50 +01:00
|
|
|
Class = Relay
|
|
|
|
|
2003-03-24 09:41:19 +01:00
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|