Пример #1
0
def do_reload(bot, target, cmdargs, server_send=None):
    """The reloading magic.

    | First, reload handler.py.
    | Then make copies of all the handler data we want to keep.
    | Create a new handler and restore all the data.
    """
    def send(msg):
        if server_send is not None:
            server_send(msg)
        else:
            do_log(bot.connection, target, msg)

    if cmdargs == 'pull':
        srcdir = path.dirname(path.abspath(__file__))
        send(misc.do_pull(srcdir, bot.connection.real_nickname))
    # Reimport helpers
    errored_helpers = modutils.scan_and_reimport('helpers', 'helpers')
    if errored_helpers:
        send("Failed to load some helpers.")
        for error in errored_helpers:
            send("%s: %s" % error)
        return False
    if not load_modules(bot.config, send):
        return False

    bot.config = configparser.ConfigParser(
        interpolation=configparser.ExtendedInterpolation())
    config_file = path.join(path.dirname(__file__), '../config.cfg')
    with open(config_file) as f:
        bot.config.read_file(f)
    # preserve data
    data = bot.handler.get_data()
    bot.shutdown_mp()
    bot.handler = handler.BotHandler(bot.config, bot.connection, bot.channels)
    bot.handler.set_data(data)
    bot.handler.connection = bot.connection
    bot.handler.channels = bot.channels
    return True
Пример #2
0
def do_reload(bot, target, cmdargs, server_send=None):
    """The reloading magic.

    | First, reload handler.py.
    | Then make copies of all the handler data we want to keep.
    | Create a new handler and restore all the data.
    """
    def send(msg):
        if server_send is not None:
            server_send(msg)
        else:
            do_log(bot.connection, target, msg)

    if cmdargs == 'pull':
        srcdir = path.dirname(path.abspath(__file__))
        send(misc.do_pull(srcdir, bot.connection.real_nickname))
    # Reimport helpers
    errored_helpers = modutils.scan_and_reimport('helpers', 'helpers')
    if errored_helpers:
        send("Failed to load some helpers.")
        for error in errored_helpers:
            send("%s: %s" % error)
        return False
    if not load_modules(bot.config, send):
        return False

    bot.config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
    config_file = path.join(path.dirname(__file__), '../config.cfg')
    with open(config_file) as f:
        bot.config.read_file(f)
    # preserve data
    data = bot.handler.get_data()
    bot.shutdown_mp()
    bot.handler = handler.BotHandler(bot.config, bot.connection, bot.channels)
    bot.handler.set_data(data)
    bot.handler.connection = bot.connection
    bot.handler.channels = bot.channels
    return True
Пример #3
0
def scan_for_commands(folder):
    """ Scans folder for commands """
    global _known_commands
    _known_commands = {}
    scan_and_reimport(folder, "commands")
    return _known_commands
Пример #4
0
def scan_for_hooks(folder):
    """ Scans folder for hooks """
    global _known_hooks
    _known_hooks = []
    scan_and_reimport(folder, "hooks")
    return _known_hooks