mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-04 00:47:21 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python3
 | 
						|
 | 
						|
import imp
 | 
						|
import os
 | 
						|
import sys
 | 
						|
 | 
						|
# cd into the PyLink root directory first...
 | 
						|
os.chdir(os.path.dirname(__file__))
 | 
						|
 | 
						|
import world
 | 
						|
 | 
						|
# This must be set before conf imports, so we get the real conf instead of testing one.
 | 
						|
world.testing = False
 | 
						|
 | 
						|
import conf
 | 
						|
from log import log
 | 
						|
import classes
 | 
						|
import coreplugin
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    log.info('PyLink %s starting...', world.version)
 | 
						|
    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')
 | 
						|
 | 
						|
    # Write a PID file.
 | 
						|
    with open('%s.pid' % conf.confname, 'w') as f:
 | 
						|
        f.write(str(os.getpid()))
 | 
						|
 | 
						|
    # 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')
 | 
						|
    sys.path.extend([plugins_folder, protocols_folder])
 | 
						|
    for plugin in to_load:
 | 
						|
        try:
 | 
						|
            world.plugins[plugin] = pl = __import__(plugin)
 | 
						|
        except ImportError as e:
 | 
						|
            if str(e) == ('No module named %r' % plugin):
 | 
						|
                log.error('Failed to load plugin %r: The plugin could not be found.', plugin)
 | 
						|
            else:
 | 
						|
                log.error('Failed to load plugin %r: ImportError: %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:
 | 
						|
            proto = __import__(protoname)
 | 
						|
        except ImportError as e:
 | 
						|
            if str(e) == ('No module named %r' % protoname):
 | 
						|
                log.critical('Failed to load protocol module %r: The file could not be found.', protoname)
 | 
						|
            else:
 | 
						|
                log.critical('Failed to load protocol module: ImportError: %s', protoname, str(e))
 | 
						|
            sys.exit(2)
 | 
						|
        else:
 | 
						|
            world.networkobjects[network] = irc = classes.Irc(network, proto)
 | 
						|
            irc.plugins_folder = plugins_folder
 | 
						|
    world.started.set()
 | 
						|
    log.info("loaded plugins: %s", world.plugins)
 |