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.
This commit is contained in:
Brian S. Stephan 2010-10-09 18:52:51 -05:00
parent 599106e447
commit 52b740a52c
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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: