Ejemplo n.º 1
0
class Bot(object):
    def __init__(self):
        if settings.MATTERMOST_API_VERSION == 4:
            self._client = MattermostClientv4(settings.BOT_URL,
                                              settings.BOT_TEAM,
                                              settings.BOT_LOGIN,
                                              settings.BOT_PASSWORD,
                                              settings.SSL_VERIFY)
        else:
            self._client = MattermostClient(settings.BOT_URL,
                                            settings.BOT_TEAM,
                                            settings.BOT_LOGIN,
                                            settings.BOT_PASSWORD,
                                            settings.SSL_VERIFY)
        logger.info('connected to mattermost')
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins)

    def run(self):
        self._plugins.init_plugins()
        self._dispatcher.start()
        _thread.start_new_thread(self._keep_active, tuple())
        self._dispatcher.loop()

    def _keep_active(self):
        logger.info('keep active thread started')
        while True:
            time.sleep(60)
            self._client.ping()
Ejemplo n.º 2
0
class Bot(object):
    def __init__(self):
        if settings.MATTERMOST_API_VERSION < 4:
            raise ValueError('mmpy-bot only supports API Version 4+')
        self._client = MattermostClient(settings.BOT_URL, settings.BOT_TEAM,
                                        settings.BOT_LOGIN,
                                        settings.BOT_PASSWORD,
                                        settings.SSL_VERIFY,
                                        settings.BOT_TOKEN, settings.WS_ORIGIN)
        logger.info('connected to mattermost')
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins)
        print('_init_ bot ')

    def run(self):
        self._plugins.init_plugins()
        self._dispatcher.start()
        _thread.start_new_thread(self._keep_active, tuple())
        _thread.start_new_thread(self._run_jobs, tuple())
        self._dispatcher.loop()
        print('3333')

    def _keep_active(self):
        logger.info('keep active thread started')
        while True:
            time.sleep(60)
            self._client.ping()

    def _run_jobs(self):
        logger.info('job running thread started')
        while True:
            time.sleep(settings.JOB_TRIGGER_PERIOD)
            schedule.run_pending()
Ejemplo n.º 3
0
class Bot(object):
    def __init__(self, settings=None):
        self._settings = default_settings
        if settings:
            self._settings.update(settings)

        if self._settings["MATTERMOST_API_VERSION"] < 4:
            raise ValueError('mmpy-bot only supports API Version 4+')
        self._client = MattermostClient(
            self._settings["BOT_URL"], self._settings["BOT_TEAM"],
            self._settings["BOT_LOGIN"], self._settings["BOT_PASSWORD"],
            self._settings["SSL_VERIFY"], self._settings["BOT_TOKEN"],
            self._settings["WS_ORIGIN"])
        logger.info('connected to mattermost')
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                             self._settings)

    def run(self):
        self._plugins.init_plugins(self._settings)
        self._plugins.trigger_at_start(self._client)
        self._dispatcher.start()
        _thread.start_new_thread(self._keep_active, tuple())
        _thread.start_new_thread(self._run_jobs, tuple())
        self._dispatcher.loop()

    def _keep_active(self):
        logger.info('keep active thread started')
        while True:
            time.sleep(60)
            self._client.ping()

    def _run_jobs(self):
        logger.info('job running thread started')
        while True:
            time.sleep(self._settings["JOB_TRIGGER_PERIOD"])
            schedule.run_pending()