示例#1
0
文件: bot.py 项目: sckasturi/saltlake
    def do_reload(self, c, target, cmdargs, msgtype):
        """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.
        """
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for x in modutils.get_enabled(dirname(__file__) + '/helpers'):
            name = 'helpers.%s' % x
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        self.config.read_file(open(configfile))
        # preserve data
        data = self.handler.get_data()
        self.do_shutdown(True)
        self.handler = handler.BotHandler(self.config)
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        self.handler.workers = workers.Workers(self.handler)
        if output:
            return output
示例#2
0
    def do_reload(self, c, target, cmdargs):
        """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.
        """
        self.reload_event.clear()
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for name in modutils.get_enabled('helpers', 'helpers')[0]:
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        with open(configfile) as cfgfile:
            self.config.read_file(cfgfile)
        # preserve data
        data = self.handler.get_data()
        self.shutdown_server()
        self.shutdown_workers()
        self.handler = handler.BotHandler(self.config)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.reload_event.set()
        if output:
            return output
示例#3
0
    def do_reload(self, c, target, cmdargs, msgtype):
        """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.
        """
        output = None
        if cmdargs == 'pull':
            output = misc.do_pull(dirname(__file__), c.real_nickname)
            c.privmsg(target, output)
        for x in modutils.get_enabled(dirname(__file__) + '/helpers'):
            name = 'helpers.%s' % x
            if name in sys.modules:
                importlib.reload(sys.modules[name])
        importlib.reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        self.config.read_file(open(configfile))
        # preserve data
        data = self.handler.get_data()
        self.do_shutdown(True)
        self.handler = handler.BotHandler(self.config)
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        self.handler.workers = workers.Workers(self.handler)
        if output:
            return output
示例#4
0
文件: bot.py 项目: Polarcraft/cslbot
    def __init__(self, botconfig):
        """Setup everything."""
        if botconfig.getboolean('core', 'ssl'):
            factory = connection.Factory(wrapper=ssl.wrap_socket, ipv6=botconfig.getboolean('core', 'ipv6'))
        else:
            factory = connection.Factory(ipv6=botconfig.getboolean('core', 'ipv6'))
        passwd = None if botconfig.getboolean('core', 'sasl') else botconfig['auth']['serverpass']
        serverinfo = bot.ServerSpec(botconfig['core']['host'], botconfig.getint('core', 'ircport'), passwd)
        nick = botconfig['core']['nick']
        super().__init__([serverinfo], nick, nick, connect_factory=factory, reconnection_interval=5)
        # This does the magic when everything else is dead
        self.connection.add_global_handler("pubmsg", self.reload_handler, -30)
        self.connection.add_global_handler("all_events", self.handle_event, 10)
        # We need to get the channels that a nick is currently in before the regular quit event is processed.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        if passwd is None:
            # FIXME: make this less hacky
            self.reactor._on_connect = self.do_sasl
        self.config = botconfig
        self.handler = handler.BotHandler(botconfig, self.connection, self.channels)
        if not reloader.load_modules(botconfig):
            # The initial load of commands/hooks failed, so bail out.
            self.shutdown_mp(False)
            sys.exit(1)
        self.event_queue = queue.Queue()
        # Are we running in bare-bones, reload-only mode?
        self.reload_event = threading.Event()

        if botconfig['feature'].getboolean('server'):
            self.server = server.init_server(self)
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'
示例#5
0
文件: bot.py 项目: bobtwinkles/cslbot
    def __init__(self, botconfig):
        """Setup everything.

        | Setup the handler.
        | Setup the server.
        | Connect to the server.
        """
        if botconfig.getboolean('core', 'ssl'):
            factory = Factory(wrapper=ssl.wrap_socket, ipv6=botconfig.getboolean('core', 'ipv6'))
        else:
            factory = Factory(ipv6=botconfig.getboolean('core', 'ipv6'))
        passwd = None if botconfig.getboolean('core', 'sasl') else botconfig['auth']['serverpass']
        serverinfo = ServerSpec(botconfig['core']['host'], botconfig.getint('core', 'ircport'), passwd)
        nick = botconfig['core']['nick']
        super().__init__([serverinfo], nick, nick, connect_factory=factory)
        if passwd is None:
            # FIXME: make this less hacky
            self.reactor._on_connect = self.do_sasl
        self.reload_event = threading.Event()
        self.reload_event.set()
        self.config = botconfig
        self.handler = handler.BotHandler(botconfig)
        if botconfig['feature'].getboolean('server'):
            self.server = server.init_server(self)
        # properly log quits.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'
示例#6
0
    def __init__(self, botconfig):
        """Setup everything."""
        if botconfig.getboolean('core', 'ssl'):
            factory = connection.Factory(wrapper=ssl.wrap_socket, ipv6=botconfig.getboolean('core', 'ipv6'))
        else:
            factory = connection.Factory(ipv6=botconfig.getboolean('core', 'ipv6'))
        passwd = None if botconfig.getboolean('core', 'sasl') else botconfig['auth']['serverpass']
        serverinfo = bot.ServerSpec(botconfig['core']['host'], botconfig.getint('core', 'ircport'), passwd)
        nick = botconfig['core']['nick']
        super().__init__([serverinfo], nick, nick, connect_factory=factory, reconnection_interval=5)
        # This does the magic when everything else is dead
        self.connection.add_global_handler("pubmsg", self.reload_handler, -30)
        self.connection.add_global_handler("all_events", self.handle_event, 10)
        # We need to get the channels that a nick is currently in before the regular quit event is processed.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        if passwd is None:
            # FIXME: make this less hacky
            self.reactor._on_connect = self.do_sasl
        self.config = botconfig
        self.handler = handler.BotHandler(botconfig, self.connection, self.channels)
        if not reloader.load_modules(botconfig):
            # The initial load of commands/hooks failed, so bail out.
            self.shutdown_mp(False)
            sys.exit(1)
        self.event_queue = queue.Queue()
        # Are we running in bare-bones, reload-only mode?
        self.reload_event = threading.Event()

        if botconfig['feature'].getboolean('server'):
            self.server = server.init_server(self)
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'
示例#7
0
文件: bot.py 项目: Polarcraft/cslbot
 def reload_handler(self, c, e):
     """This handles reloads."""
     if e.type not in ['pubmsg', 'privmsg']:
         return
     cmd = self.is_reload(e)
     cmdchar = self.config['core']['cmdchar']
     if cmd is not None:
         admins = [x.strip() for x in self.config['auth']['admins'].split(',')]
         if e.source.nick not in admins:
             c.privmsg(self.get_target(e), "Nope, not gonna do it.")
             return
         importlib.reload(reloader)
         self.reload_event.set()
         cmdargs = cmd[len('%sreload' % cmdchar) + 1:]
         if reloader.do_reload(self, self.get_target(e), cmdargs):
             if self.config['feature'].getboolean('server'):
                 self.server = server.init_server(self)
             self.reload_event.clear()
示例#8
0
 def reload_handler(self, c, e):
     """This handles reloads."""
     if e.type not in ['pubmsg', 'privmsg']:
         return
     cmd = self.is_reload(e)
     cmdchar = self.config['core']['cmdchar']
     if cmd is not None:
         admins = [x.strip() for x in self.config['auth']['admins'].split(',')]
         if e.source.nick not in admins:
             c.privmsg(self.get_target(e), "Nope, not gonna do it.")
             return
         importlib.reload(reloader)
         self.reload_event.set()
         cmdargs = cmd[len('%sreload' % cmdchar) + 1:]
         if reloader.do_reload(self, self.get_target(e), cmdargs):
             if self.config['feature'].getboolean('server'):
                 self.server = server.init_server(self)
             self.reload_event.clear()
示例#9
0
文件: bot.py 项目: bobtwinkles/cslbot
    def do_reload(self, c, target, cmdargs):
        """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.
        """
        self.reload_event.clear()
        output = None
        if cmdargs == 'pull':
            srcdir = dirname(abspath(__file__))
            output = misc.do_pull(srcdir, c.real_nickname)
            c.privmsg(target, output)
        reload_ok = True
        failed_modules = []
        for name in modutils.get_enabled('helpers', 'helpers')[0]:
            if name in sys.modules:
                mod_reload_ok = modutils.safe_reload(sys.modules[name])
                if not mod_reload_ok:
                    failed_modules.append(name)
                    reload_ok = False
        if not reload_ok:
            controlchan = self.config['core']['ctrlchan']
            self.connection.privmsg(controlchan,
                                    "Failed to reload some helper modules. Some commands may not work as expected, see the console for details")
            self.connection.privmsg(controlchan, "Failures: " + ", ".join(failed_modules))
        modutils.safe_reload(handler)
        self.config = ConfigParser()
        configfile = join(dirname(__file__), 'config.cfg')
        with open(configfile) as cfgfile:
            self.config.read_file(cfgfile)
        # preserve data
        data = self.handler.get_data()
        self.shutdown_mp()
        self.handler = handler.BotHandler(self.config)
        self.handler.set_data(data)
        self.handler.connection = c
        self.handler.channels = self.channels
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
        self.reload_event.set()
        if output:
            return output
示例#10
0
文件: bot.py 项目: nwatson/cslbot
def main(args):
    """The bot's main entry point.

    | Setup logging.
    | When troubleshooting startup, it may help to change the INFO to DEBUG.
    | Initialize the bot and start processing messages.
    """
    loglevel = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=loglevel)
    botconfig = ConfigParser()
    configfile = join(dirname(__file__), 'config.cfg')
    if not exists(configfile):
        print("Setting up config file")
        config.do_setup(configfile)
        return
    botconfig.read_file(open(configfile))
    bot = IrcBot(botconfig)
    bot.server = server.init_server(bot)
    bot.start()
示例#11
0
    def __init__(self, botconfig):
        """Setup everything.

        | Setup the handler.
        | Setup the server.
        | Connect to the server.
        """
        self.reload_event = threading.Event()
        self.reload_event.set()
        self.config = botconfig
        self.handler = handler.BotHandler(botconfig)
        if botconfig['feature'].getboolean('server'):
            self.server = server.init_server(self)
        serverinfo = ServerSpec(botconfig['core']['host'], int(botconfig['core']['ircport']), botconfig['auth']['serverpass'])
        nick = botconfig['core']['nick']
        self.handle_connect(serverinfo, nick, botconfig['core'])
        # properly log quits.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'
示例#12
0
def main(args):
    """The bot's main entry point.

    | Setup logging.
    | When troubleshooting startup, it may help to change the INFO to DEBUG.
    | Initialize the bot and start processing messages.
    """
    loglevel = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=loglevel)
    botconfig = ConfigParser()
    configfile = join(dirname(__file__), 'config.cfg')
    if not exists(configfile):
        print("Setting up config file")
        config.do_setup(configfile)
        return
    botconfig.read_file(open(configfile))
    bot = IrcBot(botconfig)
    if botconfig['feature'].getboolean('server'):
        bot.server = server.init_server(bot)
    bot.start()