mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Make plugins global, not per IRC instance
This commit is contained in:
parent
3c2d0dbe3f
commit
45cef19eaa
51
main.py
51
main.py
@ -55,7 +55,6 @@ class Irc():
|
||||
self.socket.settimeout(180)
|
||||
self.socket.connect((ip, port))
|
||||
self.proto.connect(self)
|
||||
self.loaded = []
|
||||
reading_thread = threading.Thread(target = self.run)
|
||||
self.connected = True
|
||||
reading_thread.start()
|
||||
@ -90,33 +89,34 @@ class Irc():
|
||||
log.debug("(%s) -> %s", self.name, data.decode("utf-8").strip("\n"))
|
||||
self.socket.send(data)
|
||||
|
||||
def load_plugins(self):
|
||||
to_load = conf.conf['plugins']
|
||||
plugins_folder = [os.path.join(os.getcwd(), 'plugins')]
|
||||
# Here, we override the module lookup and import the plugins
|
||||
# dynamically depending on which were configured.
|
||||
for plugin in to_load:
|
||||
try:
|
||||
moduleinfo = imp.find_module(plugin, plugins_folder)
|
||||
pl = imp.load_source(plugin, moduleinfo[1])
|
||||
self.loaded.append(pl)
|
||||
except ImportError as e:
|
||||
if str(e).startswith('No module named'):
|
||||
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
||||
else:
|
||||
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
||||
else:
|
||||
if hasattr(pl, 'main'):
|
||||
log.debug('Calling main() function of plugin %r', pl)
|
||||
pl.main(irc)
|
||||
log.info("loaded plugins: %s", self.loaded)
|
||||
|
||||
if __name__ == '__main__':
|
||||
log.info('PyLink starting...')
|
||||
if conf.conf['login']['password'] == 'changeme':
|
||||
log.critical("You have not set the login details correctly! Exiting...")
|
||||
sys.exit(2)
|
||||
protocols_folder = [os.path.join(os.getcwd(), 'protocols')]
|
||||
|
||||
# Import plugins first globally, because they can listen for events
|
||||
# that happen before the connection phase.
|
||||
to_load = conf.conf['plugins']
|
||||
plugins_folder = [os.path.join(os.getcwd(), 'plugins')]
|
||||
# Here, we override the module lookup and import the plugins
|
||||
# dynamically depending on which were configured.
|
||||
for plugin in to_load:
|
||||
try:
|
||||
moduleinfo = imp.find_module(plugin, plugins_folder)
|
||||
pl = imp.load_source(plugin, moduleinfo[1])
|
||||
utils.plugins.append(pl)
|
||||
except ImportError as e:
|
||||
if str(e).startswith('No module named'):
|
||||
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
||||
else:
|
||||
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
||||
else:
|
||||
if hasattr(pl, 'main'):
|
||||
log.debug('Calling main() function of plugin %r', pl)
|
||||
pl.main()
|
||||
|
||||
for network in conf.conf['servers']:
|
||||
protoname = conf.conf['servers'][network]['protocol']
|
||||
try:
|
||||
@ -130,8 +130,5 @@ if __name__ == '__main__':
|
||||
sys.exit(2)
|
||||
else:
|
||||
utils.networkobjects[network] = Irc(network, proto, conf.conf)
|
||||
# This is a separate loop to make sure that ALL networks have their
|
||||
# Irc objects added into utils.networkobjects, before we load any plugins
|
||||
# that may require them.
|
||||
for irc in utils.networkobjects.values():
|
||||
irc.load_plugins()
|
||||
log.info("loaded plugins: %s", utils.plugins)
|
||||
|
||||
|
@ -54,6 +54,7 @@ def joinClient(irc, client, channel):
|
||||
channel = channel.lower()
|
||||
server = utils.isInternalClient(irc, client)
|
||||
if not server:
|
||||
log.error('(%s) Error trying to join client %r to %r (no such pseudoclient exists)', irc.name, client, channel)
|
||||
raise LookupError('No such PyLink PseudoClient exists.')
|
||||
# One channel per line here!
|
||||
_sendFromServer(irc, server, "FJOIN {channel} {ts} {modes} :,{uid}".format(
|
||||
@ -526,7 +527,7 @@ def handle_events(irc, data):
|
||||
# to plugins and the like. For example, the JOIN handler will return
|
||||
# something like: {'channel': '#whatever', 'users': ['UID1', 'UID2',
|
||||
# 'UID3']}, etc.
|
||||
if parsed_args:
|
||||
if parsed_args is not None:
|
||||
# Always make sure TS is sent.
|
||||
if 'ts' not in parsed_args:
|
||||
parsed_args['ts'] = int(time.time())
|
||||
@ -636,3 +637,6 @@ def handle_fhost(irc, numeric, command, args):
|
||||
def handle_fname(irc, numeric, command, args):
|
||||
irc.users[numeric].realname = newgecos = args[0]
|
||||
return {'target': numeric, 'newgecos': newgecos}
|
||||
|
||||
def handle_endburst(irc, numeric, command, args):
|
||||
return {}
|
||||
|
Loading…
Reference in New Issue
Block a user