From 52b740a52cd3f0f6fc76359fdafffb8766d849f9 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 9 Oct 2010 18:52:51 -0500 Subject: [PATCH] split the register_handlers into a method other than the object constructor the reasoning behind this is that we may want to load one object but have it connect to multiple servers. this allows that. --- Module.py | 5 ++++- dr.botzo.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Module.py b/Module.py index bf33ec2..3636b46 100644 --- a/Module.py +++ b/Module.py @@ -41,7 +41,6 @@ class Module(object): self.config = config self.server = server self.modlist = modlist - self.register_handlers(server) # add self to the object list modlist.append(self) @@ -49,6 +48,10 @@ class Module(object): # print what was loaded, for debugging print("loaded " + self.__class__.__name__) + def attach_to_server(self, server): + """Call register_handlers against the given server.""" + self.register_handlers(server) + def register_handlers(self, server): """ Hook handler functions into the IRC library. This is called by __init__ and sets diff --git a/dr.botzo.py b/dr.botzo.py index 77fec59..b436cab 100644 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -116,7 +116,8 @@ try: mods = cfgmodlist.split(',') for mod in mods: # try to load each module - eval(mod + '.' + mod + '(config, server, modlist)') + module = eval(mod + '.' + mod + '(config, server, modlist)') + module.attach_to_server(server) except NoSectionError as e: print("You seem to be missing a modules config section, which you probably wanted.") except NoOptionError as e: