mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-24 03:29:28 +01:00
Finally got the persistent configuration working with the Relay module (though don't try to reload it :)).
This commit is contained in:
parent
9d20105689
commit
147d5cf6da
@ -140,12 +140,13 @@ class Relay(callbacks.Privmsg):
|
|||||||
that network to other networks.
|
that network to other networks.
|
||||||
"""
|
"""
|
||||||
abbreviation, server = privmsgs.getArgs(args, needed=2)
|
abbreviation, server = privmsgs.getArgs(args, needed=2)
|
||||||
|
realIrc = irc.getRealIrc()
|
||||||
if ':' in server:
|
if ':' in server:
|
||||||
(server, port) = server.split(':')
|
(server, port) = server.split(':')
|
||||||
port = int(port)
|
port = int(port)
|
||||||
else:
|
else:
|
||||||
port = 6667
|
port = 6667
|
||||||
newIrc = irclib.Irc(irc.nick, callbacks=irc.callbacks)
|
newIrc = irclib.Irc(irc.nick, callbacks=realIrc.callbacks)
|
||||||
driver = drivers.newDriver((server, port), newIrc)
|
driver = drivers.newDriver((server, port), newIrc)
|
||||||
newIrc.driver = driver
|
newIrc.driver = driver
|
||||||
self.ircs[abbreviation] = newIrc
|
self.ircs[abbreviation] = newIrc
|
||||||
|
10
src/bot.py
10
src/bot.py
@ -58,15 +58,10 @@ class ConfigAfter376(irclib.IrcCallback):
|
|||||||
self.commands = commands
|
self.commands = commands
|
||||||
|
|
||||||
def do376(self, irc, msg):
|
def do376(self, irc, msg):
|
||||||
#debug.printf('Firing ConfigAfter376 messages')
|
|
||||||
for command in self.commands:
|
for command in self.commands:
|
||||||
#debug.printf(irc.nick)
|
|
||||||
#debug.printf(command)
|
|
||||||
msg = ircmsgs.privmsg(irc.nick, command, prefix=irc.prefix)
|
msg = ircmsgs.privmsg(irc.nick, command, prefix=irc.prefix)
|
||||||
irc.queueMsg(msg)
|
irc.queueMsg(msg)
|
||||||
|
|
||||||
do377 = do376
|
|
||||||
|
|
||||||
def handleConfigFile():
|
def handleConfigFile():
|
||||||
nick = conf.config['nick']
|
nick = conf.config['nick']
|
||||||
user = conf.config['user']
|
user = conf.config['user']
|
||||||
@ -76,10 +71,7 @@ def handleConfigFile():
|
|||||||
for Class in privmsgs.standardPrivmsgModules:
|
for Class in privmsgs.standardPrivmsgModules:
|
||||||
callback = Class()
|
callback = Class()
|
||||||
if hasattr(callback, 'configure'):
|
if hasattr(callback, 'configure'):
|
||||||
fakeIrc = callback.configure()
|
callback.configure(irc)
|
||||||
# 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)
|
|
||||||
irc.addCallback(callback)
|
irc.addCallback(callback)
|
||||||
irc.addCallback(ConfigAfter376(conf.config['afterConnect']))
|
irc.addCallback(ConfigAfter376(conf.config['afterConnect']))
|
||||||
drivers.newDriver(conf.config['server'], irc)
|
drivers.newDriver(conf.config['server'], irc)
|
||||||
|
@ -100,6 +100,10 @@ def reply(msg, s):
|
|||||||
m = reply(msg, 'My response would\'ve been too long.')
|
m = reply(msg, 'My response would\'ve been too long.')
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
def error(msg, s):
|
||||||
|
"""Makes an error reply to msg with the appropriate error payload."""
|
||||||
|
return reply(msg, 'Error: ' + s)
|
||||||
|
|
||||||
class RateLimiter:
|
class RateLimiter:
|
||||||
lastRequest = {}
|
lastRequest = {}
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -298,7 +302,7 @@ class IrcObjectProxy:
|
|||||||
self.reply(self.msg, debug.exnToString(e))
|
self.reply(self.msg, debug.exnToString(e))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
debug.recoverableException()
|
debug.recoverableException()
|
||||||
self.reply(self.msg, debug.exnToString(e))
|
self.error(self.msg, debug.exnToString(e))
|
||||||
|
|
||||||
def reply(self, msg, s):
|
def reply(self, msg, s):
|
||||||
if self.finalEvaled:
|
if self.finalEvaled:
|
||||||
@ -358,6 +362,31 @@ class CommandThread(threading.Thread):
|
|||||||
self.irc.error(self.msg, debug.exnToString(e))
|
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):
|
class Privmsg(irclib.IrcCallback):
|
||||||
"""Base class for all Privmsg handlers."""
|
"""Base class for all Privmsg handlers."""
|
||||||
threaded = False
|
threaded = False
|
||||||
@ -367,14 +396,11 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
self.rateLimiter = RateLimiter()
|
self.rateLimiter = RateLimiter()
|
||||||
self.Proxy = IrcObjectProxy
|
self.Proxy = IrcObjectProxy
|
||||||
|
|
||||||
def configure(self):
|
def configure(self, irc):
|
||||||
nick = conf.config['nick']
|
nick = conf.config['nick']
|
||||||
user = conf.config['user']
|
user = conf.config['user']
|
||||||
ident = conf.config['ident']
|
ident = conf.config['ident']
|
||||||
fakeIrc = irclib.Irc(nick, user, ident)
|
fakeIrc = ConfigIrcProxy(irc)
|
||||||
fakeIrc.error = lambda _, s: None #debug.printf(s)
|
|
||||||
fakeIrc.reply = lambda _, s: None #debug.printf(s)
|
|
||||||
fakeIrc.findCallback = lambda *args: None
|
|
||||||
for args in conf.config['onStart']:
|
for args in conf.config['onStart']:
|
||||||
args = args[:]
|
args = args[:]
|
||||||
command = args.pop(0)
|
command = args.pop(0)
|
||||||
@ -388,7 +414,6 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
method(fakeIrc, msg, args)
|
method(fakeIrc, msg, args)
|
||||||
finally:
|
finally:
|
||||||
world.startup = False
|
world.startup = False
|
||||||
return fakeIrc
|
|
||||||
|
|
||||||
def __call__(self, irc, msg):
|
def __call__(self, irc, msg):
|
||||||
irclib.IrcCallback.__call__(self, irc, msg)
|
irclib.IrcCallback.__call__(self, irc, msg)
|
||||||
|
@ -206,7 +206,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
|
|||||||
i = 0
|
i = 0
|
||||||
for driver in drivers._drivers.itervalues():
|
for driver in drivers._drivers.itervalues():
|
||||||
driver.die()
|
driver.die()
|
||||||
for irc in world.ircs:
|
for irc in world.ircs[:]:
|
||||||
irc.die()
|
irc.die()
|
||||||
debug.exit(i)
|
debug.exit(i)
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
|
|||||||
linecache.checkcache()
|
linecache.checkcache()
|
||||||
callback = module.Class()
|
callback = module.Class()
|
||||||
if hasattr(callback, 'configure'):
|
if hasattr(callback, 'configure'):
|
||||||
callback.configure()
|
callback.configure(irc)
|
||||||
irc.addCallback(callback)
|
irc.addCallback(callback)
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ class OwnerCommands(CapabilityCheckingPrivmsg):
|
|||||||
linecache.checkcache()
|
linecache.checkcache()
|
||||||
callback = module.Class()
|
callback = module.Class()
|
||||||
if hasattr(callback, 'configure'):
|
if hasattr(callback, 'configure'):
|
||||||
callback.configure()
|
callback.configure(irc)
|
||||||
irc.addCallback(callback)
|
irc.addCallback(callback)
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
Loading…
Reference in New Issue
Block a user