Finally got the persistent configuration working with the Relay module (though don't try to reload it :)).

This commit is contained in:
Jeremy Fincher 2003-08-23 04:42:04 +00:00
parent 9d20105689
commit 147d5cf6da
4 changed files with 38 additions and 20 deletions

View File

@ -140,12 +140,13 @@ class Relay(callbacks.Privmsg):
that network to other networks.
"""
abbreviation, server = privmsgs.getArgs(args, needed=2)
realIrc = irc.getRealIrc()
if ':' in server:
(server, port) = server.split(':')
port = int(port)
else:
port = 6667
newIrc = irclib.Irc(irc.nick, callbacks=irc.callbacks)
newIrc = irclib.Irc(irc.nick, callbacks=realIrc.callbacks)
driver = drivers.newDriver((server, port), newIrc)
newIrc.driver = driver
self.ircs[abbreviation] = newIrc

View File

@ -58,15 +58,10 @@ class ConfigAfter376(irclib.IrcCallback):
self.commands = commands
def do376(self, irc, msg):
#debug.printf('Firing ConfigAfter376 messages')
for command in self.commands:
#debug.printf(irc.nick)
#debug.printf(command)
msg = ircmsgs.privmsg(irc.nick, command, prefix=irc.prefix)
irc.queueMsg(msg)
do377 = do376
def handleConfigFile():
nick = conf.config['nick']
user = conf.config['user']
@ -76,10 +71,7 @@ def handleConfigFile():
for Class in privmsgs.standardPrivmsgModules:
callback = Class()
if hasattr(callback, 'configure'):
fakeIrc = callback.configure()
# This is mostly a hack to make sure the load command works.
for cb in fakeIrc.callbacks: # Should most always be empty.
irc.addCallback(cb)
callback.configure(irc)
irc.addCallback(callback)
irc.addCallback(ConfigAfter376(conf.config['afterConnect']))
drivers.newDriver(conf.config['server'], irc)

View File

@ -100,6 +100,10 @@ def reply(msg, s):
m = reply(msg, 'My response would\'ve been too long.')
return m
def error(msg, s):
"""Makes an error reply to msg with the appropriate error payload."""
return reply(msg, 'Error: ' + s)
class RateLimiter:
lastRequest = {}
def __init__(self):
@ -298,7 +302,7 @@ class IrcObjectProxy:
self.reply(self.msg, debug.exnToString(e))
except Exception, e:
debug.recoverableException()
self.reply(self.msg, debug.exnToString(e))
self.error(self.msg, debug.exnToString(e))
def reply(self, msg, s):
if self.finalEvaled:
@ -358,6 +362,31 @@ class CommandThread(threading.Thread):
self.irc.error(self.msg, debug.exnToString(e))
class ConfigIrcProxy(object):
def __init__(self, irc):
self.__dict__['irc'] = irc
def reply(self, msg, s):
return None
def error(self, msg, s):
debug.msg('ConfigIrcProxy saw an error: %s' % s, 'normal')
findCallback = IrcObjectProxy.findCallback.im_func
def getRealIrc(self):
irc = self.__dict__['irc']
while(hasattr(irc, 'getRealIrc')):
irc = irc.getRealIrc()
return irc
def __getattr__(self, attr):
return getattr(self.getRealIrc(), attr)
def __setattr__(self, attr, value):
setattr(self.getRealIrc(), attr, value)
class Privmsg(irclib.IrcCallback):
"""Base class for all Privmsg handlers."""
threaded = False
@ -367,14 +396,11 @@ class Privmsg(irclib.IrcCallback):
self.rateLimiter = RateLimiter()
self.Proxy = IrcObjectProxy
def configure(self):
def configure(self, irc):
nick = conf.config['nick']
user = conf.config['user']
ident = conf.config['ident']
fakeIrc = irclib.Irc(nick, user, ident)
fakeIrc.error = lambda _, s: None #debug.printf(s)
fakeIrc.reply = lambda _, s: None #debug.printf(s)
fakeIrc.findCallback = lambda *args: None
fakeIrc = ConfigIrcProxy(irc)
for args in conf.config['onStart']:
args = args[:]
command = args.pop(0)
@ -388,7 +414,6 @@ class Privmsg(irclib.IrcCallback):
method(fakeIrc, msg, args)
finally:
world.startup = False
return fakeIrc
def __call__(self, irc, msg):
irclib.IrcCallback.__call__(self, irc, msg)

View File

@ -206,7 +206,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
i = 0
for driver in drivers._drivers.itervalues():
driver.die()
for irc in world.ircs:
for irc in world.ircs[:]:
irc.die()
debug.exit(i)
@ -267,7 +267,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
linecache.checkcache()
callback = module.Class()
if hasattr(callback, 'configure'):
callback.configure()
callback.configure(irc)
irc.addCallback(callback)
irc.reply(msg, conf.replySuccess)
@ -302,7 +302,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
linecache.checkcache()
callback = module.Class()
if hasattr(callback, 'configure'):
callback.configure()
callback.configure(irc)
irc.addCallback(callback)
irc.reply(msg, conf.replySuccess)
except ImportError: