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:
parent
599106e447
commit
52b740a52c
@ -41,7 +41,6 @@ class Module(object):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.server = server
|
self.server = server
|
||||||
self.modlist = modlist
|
self.modlist = modlist
|
||||||
self.register_handlers(server)
|
|
||||||
|
|
||||||
# add self to the object list
|
# add self to the object list
|
||||||
modlist.append(self)
|
modlist.append(self)
|
||||||
@ -49,6 +48,10 @@ class Module(object):
|
|||||||
# print what was loaded, for debugging
|
# print what was loaded, for debugging
|
||||||
print("loaded " + self.__class__.__name__)
|
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):
|
def register_handlers(self, server):
|
||||||
"""
|
"""
|
||||||
Hook handler functions into the IRC library. This is called by __init__ and sets
|
Hook handler functions into the IRC library. This is called by __init__ and sets
|
||||||
|
@ -116,7 +116,8 @@ try:
|
|||||||
mods = cfgmodlist.split(',')
|
mods = cfgmodlist.split(',')
|
||||||
for mod in mods:
|
for mod in mods:
|
||||||
# try to load each module
|
# 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:
|
except NoSectionError as e:
|
||||||
print("You seem to be missing a modules config section, which you probably wanted.")
|
print("You seem to be missing a modules config section, which you probably wanted.")
|
||||||
except NoOptionError as e:
|
except NoOptionError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user