Changed over to privmsgs.CapabilityCheckingPrivmsg and finished relaydisconnect.

This commit is contained in:
Jeremy Fincher 2003-03-27 08:24:22 +00:00
parent d5c7789cbb
commit 32262af492

View File

@ -53,79 +53,62 @@ import privmsgs
import callbacks import callbacks
import asyncoreDrivers import asyncoreDrivers
class IdDict(dict): class Relay(privmsgs.CapabilityCheckingPrivmsg):
def __setitem__(self, key, value): capability = 'owner'
dict.__setitem__(self, id(key), value)
def __getitem__(self, key):
return dict.__getitem__(self, id(key))
def __contains__(self, key):
return dict.__contains__(self, id(key))
class Relay(callbacks.Privmsg):
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
self.ircs = [] self.ircs = {}
self.started = False self.started = False
self.abbreviations = {} #IdDict({}) self.abbreviations = {}
def startrelay(self, irc, msg, args): def startrelay(self, irc, msg, args):
"<network abbreviation for current server>" "<network abbreviation for current server>"
if ircdb.checkCapability(msg.prefix, 'owner'): realIrc = irc.getRealIrc()
realIrc = irc.getRealIrc() abbreviation = privmsgs.getArgs(args)
abbreviation = privmsgs.getArgs(args) self.ircs[abbreviation] = realIrc
self.ircs.append(realIrc) self.abbreviations[realIrc] = abbreviation
self.abbreviations[realIrc] = abbreviation self.started = True
self.started = True irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, conf.replyNoCapability % 'owner')
def relayconnect(self, irc, msg, args): def relayconnect(self, irc, msg, args):
"<network abbreviation> <domain:port> (port defaults to 6667)" "<network abbreviation> <domain:port> (port defaults to 6667)"
if ircdb.checkCapability(msg.prefix, 'owner'): abbreviation, server = privmsgs.getArgs(args, needed=2)
abbreviation, server = privmsgs.getArgs(args, needed=2) if ':' in server:
if ':' in server: (server, port) = server.split(':')
(server, port) = server.split(':') port = int(port)
port = int(port)
else:
port = 6667
newIrc = irclib.Irc(irc.nick, callbacks=irc.callbacks)
driver = asyncoreDrivers.AsyncoreDriver((server, port))
driver.irc = newIrc
newIrc.driver = driver
self.ircs.append(newIrc)
self.abbreviations[newIrc] = abbreviation
irc.reply(msg, conf.replySuccess)
else: else:
irc.reply(msg, conf.replyNoCapability % 'owner') port = 6667
newIrc = irclib.Irc(irc.nick, callbacks=irc.callbacks)
driver = asyncoreDrivers.AsyncoreDriver((server, port))
driver.irc = newIrc
newIrc.driver = driver
self.ircs[abbreviation] = newIrc
self.abbreviations[newIrc] = abbreviation
irc.reply(msg, conf.replySuccess)
def relaydisconnect(self, irc, msg, args): def relaydisconnect(self, irc, msg, args):
"<network>" "<network>"
pass network = privmsgs.getArgs(args)
otherIrc = self.ircs[network]
otherIrc.die()
otherIrc.driver.die()
irc.reply(conf.replySuccess)
def relayjoin(self, irc, msg, args): def relayjoin(self, irc, msg, args):
"<channel>" "<channel>"
if ircdb.checkCapability(msg.prefix, 'owner'): channel = privmsgs.getArgs(args)
channel = privmsgs.getArgs(args) for otherIrc in self.ircs.itervalues():
for otherIrc in self.ircs: if channel not in otherIrc.state.channels:
if channel not in otherIrc.state.channels: otherIrc.queueMsg(ircmsgs.join(channel))
otherIrc.queueMsg(ircmsgs.join(channel)) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.reply(msg, conf.replyNoCapability % 'owner')
def relaypart(self, irc, msg, args): def relaypart(self, irc, msg, args):
"<channel>" "<channel>"
if ircdb.checkCapability(msg.prefix, 'owner'): channel = privmsgs.getArgs(args)
channel = privmsgs.getArgs(args) for otherIrc in self.ircs.itervalues():
for otherIrc in self.ircs: if channel in otherIrc.state.channels:
if channel in otherIrc.state.channels: otherIrc.queueMsg(ircmsgs.part(channel))
otherIrc.queueMsg(ircmsgs.part(channel)) irc.reply(msg, conf.replySuccess)
irc.reply(msg, conf.replySuccess)
else:
irc.reply(msg, conf.replyNoCapability % 'owner')
def _formatPrivmsg(self, nick, abbreviation, msg): def _formatPrivmsg(self, nick, abbreviation, msg):
if ircmsgs.isAction(msg): if ircmsgs.isAction(msg):
@ -144,7 +127,7 @@ class Relay(callbacks.Privmsg):
#debug.printf('irc = %s' % irc) #debug.printf('irc = %s' % irc)
abbreviation = self.abbreviations[irc] abbreviation = self.abbreviations[irc]
s = self._formatPrivmsg(msg.nick, abbreviation, msg) s = self._formatPrivmsg(msg.nick, abbreviation, msg)
for otherIrc in self.ircs: for otherIrc in self.ircs.itervalues():
#debug.printf('otherIrc = %s' % otherIrc) #debug.printf('otherIrc = %s' % otherIrc)
if otherIrc != irc: if otherIrc != irc:
#debug.printf('otherIrc != irc') #debug.printf('otherIrc != irc')
@ -158,7 +141,7 @@ class Relay(callbacks.Privmsg):
channels = msg.args[0].split(',') channels = msg.args[0].split(',')
abbreviation = self.abbreviations[irc] abbreviation = self.abbreviations[irc]
s = '%s has joined on %s' % (msg.nick, abbreviation) s = '%s has joined on %s' % (msg.nick, abbreviation)
for otherIrc in self.ircs: for otherIrc in self.ircs.itervalues():
if otherIrc != irc: if otherIrc != irc:
for channel in channels: for channel in channels:
if channel in otherIrc.state.channels: if channel in otherIrc.state.channels:
@ -169,7 +152,7 @@ class Relay(callbacks.Privmsg):
channels = msg.args[0].split(',') channels = msg.args[0].split(',')
abbreviation = self.abbreviations[irc] abbreviation = self.abbreviations[irc]
s = '%s has left on %s' % (msg.nick, abbreviation) s = '%s has left on %s' % (msg.nick, abbreviation)
for otherIrc in self.ircs: for otherIrc in self.ircs.itervalues():
if otherIrc == irc: if otherIrc == irc:
continue continue
for channel in channels: for channel in channels:
@ -184,7 +167,7 @@ class Relay(callbacks.Privmsg):
channel = msg.args[0] channel = msg.args[0]
abbreviation = self.abbreviations[irc] abbreviation = self.abbreviations[irc]
s = self._formatPrivmsg(irc.nick, abbreviation, msg) s = self._formatPrivmsg(irc.nick, abbreviation, msg)
for otherIrc in self.ircs: for otherIrc in self.ircs.itervalues():
if otherIrc != irc: if otherIrc != irc:
if channel in otherIrc.state.channels: if channel in otherIrc.state.channels:
msg = ircmsgs.privmsg(channel, s) msg = ircmsgs.privmsg(channel, s)