Пример #1
0
    def run(self):
        """Connect to Hangouts and run bot"""
        cookies = self.login(self._cookies_path)
        if cookies:
            # Start asyncio event loop
            loop = asyncio.get_event_loop()

            # initialise pluggable framework
            hooks.load(self)
            sinks.start(self)

            # Connect to Hangouts
            # If we are forcefully disconnected, try connecting again
            for retry in range(self._max_retries):
                try:
                    # create Hangups client (recreate if its a retry)
                    self._client = hangups.Client(cookies)
                    self._client.on_connect.add_observer(self._on_connect)
                    self._client.on_disconnect.add_observer(self._on_disconnect)

                    loop.run_until_complete(self._client.connect())
                    sys.exit(0)
                except Exception as e:
                    logging.exception(_("unrecoverable low-level error"))
                    print(_('Client unexpectedly disconnected:\n{}').format(e))
                    print(_('Waiting {} seconds...').format(5 + retry * 5))
                    time.sleep(5 + retry * 5)
                    print(_('Trying to connect again (try {} of {})...').format(retry + 1, self._max_retries))
            print(_('Maximum number of retries reached! Exiting...'))
        sys.exit(1)
Пример #2
0
    def run(self):
        """Connect to Hangouts and run bot"""
        cookies = self.login(self._cookies_path)
        if cookies:
            # Start asyncio event loop
            loop = asyncio.get_event_loop()

            # initialise pluggable framework
            hooks.load(self)
            sinks.start(self)

            # Connect to Hangouts
            # If we are forcefully disconnected, try connecting again
            for retry in range(self._max_retries):
                try:
                    # create Hangups client (recreate if its a retry)
                    self._client = hangups.Client(cookies)
                    self._client.on_connect.add_observer(self._on_connect)
                    self._client.on_disconnect.add_observer(
                        self._on_disconnect)

                    loop.run_until_complete(self._client.connect())

                    logger.info("bot is exiting")

                    loop.run_until_complete(plugins.unload_all(self))

                    self.memory.flush()
                    self.config.flush()

                    sys.exit(0)
                except Exception as e:
                    logger.exception("CLIENT: unrecoverable low-level error")
                    print('Client unexpectedly disconnected:\n{}'.format(e))

                    loop.run_until_complete(plugins.unload_all(self))

                    logger.info('Waiting {} seconds...'.format(5 + retry * 5))
                    time.sleep(5 + retry * 5)
                    logger.info(
                        'Trying to connect again (try {} of {})...'.format(
                            retry + 1, self._max_retries))

            logger.error('Maximum number of retries reached! Exiting...')

        logger.error("Valid login required, exiting")

        sys.exit(1)
Пример #3
0
    def run(self):
        """Connect to Hangouts and run bot"""
        cookies = self.login(self._cookies_path)
        if cookies:
            # Start asyncio event loop
            loop = asyncio.get_event_loop()
            threads = self.get_config_option("max_threads") or 5
            loop.set_default_executor(ThreadPoolExecutor(max_workers=threads))

            # initialise pluggable framework
            hooks.load(self)
            sinks.start(self)

            # Connect to Hangouts
            # If we are forcefully disconnected, try connecting again
            for retry in range(self._max_retries):
                try:
                    # create Hangups client (recreate if its a retry)
                    self._client = hangups.Client(cookies)
                    self._client.on_connect.add_observer(self._on_connect)
                    self._client.on_disconnect.add_observer(
                        self._on_disconnect)

                    loop.run_until_complete(self._client.connect())

                except SystemExit:
                    logger.info("bot is exiting")
                    raise

                except:  # pylint:disable=bare-except
                    logger.exception("CLIENT: unrecoverable low-level error")
                finally:
                    loop.run_until_complete(plugins.unload_all(self))

                    self.memory.flush()
                    self.config.flush()

                logger.info('Waiting %s seconds...', 5 + retry * 5)
                time.sleep(5 + retry * 5)
                logger.info('Trying to connect again (try %s of %s)...',
                            retry + 1, self._max_retries)

            logger.error('Maximum number of retries reached! Exiting...')

        logger.error("Valid login required, exiting")

        sys.exit(1)