mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-19 23:10:46 +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.settimeout(180)
|
||||||
self.socket.connect((ip, port))
|
self.socket.connect((ip, port))
|
||||||
self.proto.connect(self)
|
self.proto.connect(self)
|
||||||
self.loaded = []
|
|
||||||
reading_thread = threading.Thread(target = self.run)
|
reading_thread = threading.Thread(target = self.run)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
reading_thread.start()
|
reading_thread.start()
|
||||||
@ -90,33 +89,34 @@ class Irc():
|
|||||||
log.debug("(%s) -> %s", self.name, data.decode("utf-8").strip("\n"))
|
log.debug("(%s) -> %s", self.name, data.decode("utf-8").strip("\n"))
|
||||||
self.socket.send(data)
|
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__':
|
if __name__ == '__main__':
|
||||||
log.info('PyLink starting...')
|
log.info('PyLink starting...')
|
||||||
if conf.conf['login']['password'] == 'changeme':
|
if conf.conf['login']['password'] == 'changeme':
|
||||||
log.critical("You have not set the login details correctly! Exiting...")
|
log.critical("You have not set the login details correctly! Exiting...")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
protocols_folder = [os.path.join(os.getcwd(), 'protocols')]
|
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']:
|
for network in conf.conf['servers']:
|
||||||
protoname = conf.conf['servers'][network]['protocol']
|
protoname = conf.conf['servers'][network]['protocol']
|
||||||
try:
|
try:
|
||||||
@ -130,8 +130,5 @@ if __name__ == '__main__':
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
else:
|
else:
|
||||||
utils.networkobjects[network] = Irc(network, proto, conf.conf)
|
utils.networkobjects[network] = Irc(network, proto, conf.conf)
|
||||||
# This is a separate loop to make sure that ALL networks have their
|
log.info("loaded plugins: %s", utils.plugins)
|
||||||
# Irc objects added into utils.networkobjects, before we load any plugins
|
|
||||||
# that may require them.
|
|
||||||
for irc in utils.networkobjects.values():
|
|
||||||
irc.load_plugins()
|
|
||||||
|
@ -54,6 +54,7 @@ def joinClient(irc, client, channel):
|
|||||||
channel = channel.lower()
|
channel = channel.lower()
|
||||||
server = utils.isInternalClient(irc, client)
|
server = utils.isInternalClient(irc, client)
|
||||||
if not server:
|
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.')
|
raise LookupError('No such PyLink PseudoClient exists.')
|
||||||
# One channel per line here!
|
# One channel per line here!
|
||||||
_sendFromServer(irc, server, "FJOIN {channel} {ts} {modes} :,{uid}".format(
|
_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
|
# to plugins and the like. For example, the JOIN handler will return
|
||||||
# something like: {'channel': '#whatever', 'users': ['UID1', 'UID2',
|
# something like: {'channel': '#whatever', 'users': ['UID1', 'UID2',
|
||||||
# 'UID3']}, etc.
|
# 'UID3']}, etc.
|
||||||
if parsed_args:
|
if parsed_args is not None:
|
||||||
# Always make sure TS is sent.
|
# Always make sure TS is sent.
|
||||||
if 'ts' not in parsed_args:
|
if 'ts' not in parsed_args:
|
||||||
parsed_args['ts'] = int(time.time())
|
parsed_args['ts'] = int(time.time())
|
||||||
@ -636,3 +637,6 @@ def handle_fhost(irc, numeric, command, args):
|
|||||||
def handle_fname(irc, numeric, command, args):
|
def handle_fname(irc, numeric, command, args):
|
||||||
irc.users[numeric].realname = newgecos = args[0]
|
irc.users[numeric].realname = newgecos = args[0]
|
||||||
return {'target': numeric, 'newgecos': newgecos}
|
return {'target': numeric, 'newgecos': newgecos}
|
||||||
|
|
||||||
|
def handle_endburst(irc, numeric, command, args):
|
||||||
|
return {}
|
||||||
|
1
utils.py
1
utils.py
@ -10,6 +10,7 @@ bot_commands = {}
|
|||||||
command_hooks = defaultdict(list)
|
command_hooks = defaultdict(list)
|
||||||
networkobjects = {}
|
networkobjects = {}
|
||||||
schedulers = {}
|
schedulers = {}
|
||||||
|
plugins = []
|
||||||
|
|
||||||
class TS6UIDGenerator():
|
class TS6UIDGenerator():
|
||||||
"""TS6 UID Generator module, adapted from InspIRCd source
|
"""TS6 UID Generator module, adapted from InspIRCd source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user