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()
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()
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) logger.info('connected to mattermost') self._plugins = PluginsManager() self._dispatcher = MessageDispatcher(self._client, self._plugins)
def test_ignore_sender(): dispatcher = MessageDispatcher(None, None) event = {'event': 'posted', 'data': {'sender_name': 'betty'}} event2 = {'event': 'posted', 'data': {'sender_name': 'Carter'}} # test by lowercase / uppercase settings # set as 'Betty' settings.IGNORE_USERS = [] # clean up settings.IGNORE_USERS.append('Betty') if dispatcher._ignore_sender(event) is not True: raise AssertionError() # set as 'CARTER' settings.IGNORE_USERS.append('CARTER') if dispatcher._ignore_sender(event2) is not True: raise AssertionError()
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 __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 __init__(self): self._client = MattermostClientv4(driver_settings.BOT_URL, driver_settings.BOT_TEAM, driver_settings.BOT_LOGIN, driver_settings.BOT_PASSWORD, driver_settings.SSL_VERIFY) self._plugins = PluginsManager() self._plugins.init_plugins() self._dispatcher = MessageDispatcher(self._client, self._plugins)
def __init__(self): self._client = MattermostClient(bot_settings.BOT_URL, bot_settings.BOT_TEAM, bot_settings.BOT_LOGIN, bot_settings.BOT_PASSWORD, bot_settings.SSL_VERIFY) self._plugins = PluginsManager() self._plugins.plugins = bot_settings.PLUGINS self._plugins.init_plugins() self._dispatcher = MessageDispatcher(self._client, self._plugins)
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()
def test_get_message(message): if MessageDispatcher.get_message(message) != "hello": raise AssertionError()