Ejemplo n.º 1
0
class Bot(object):
    def __init__(self):
        self._client = SlackClient(settings.API_TOKEN,
                                   bot_icon=settings.BOT_ICON if hasattr(
                                       settings, 'BOT_ICON') else None,
                                   bot_emoji=settings.BOT_EMOJI if hasattr(
                                       settings, 'BOT_EMOJI') else None)
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                             settings.ERRORS_TO)

    def run(self):
        self._plugins.init_plugins()
        self._dispatcher.start()
        if not self._client.connected:
            self._client.rtm_connect()

        _thread.start_new_thread(self._keepactive, tuple())
        logger.info('connected to slack RTM api')
        self._dispatcher.loop()

    def _keepactive(self):
        logger.info('keep active thread started')
        while True:
            time.sleep(30 * 60)
            self._client.ping()
Ejemplo n.º 2
0
def test_get_plugins_none_text():
    p = PluginsManager()
    p.commands['respond_to'][re.compile(r'^dummy regexp$')] = lambda x: x
    # Calling get_plugins() with `text == None`
    for func, args in p.get_plugins('respond_to', None):
        assert func is None
        assert args is None
Ejemplo n.º 3
0
class Bot(object):
    def __init__(self):
        self._client = SlackClient(
            settings.API_TOKEN,
            bot_icon=settings.BOT_ICON if hasattr(settings,
                                                  'BOT_ICON') else None,
            bot_emoji=settings.BOT_EMOJI if hasattr(settings,
                                                    'BOT_EMOJI') else None
        )
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                             settings.ERRORS_TO)

    def run(self):
        self._plugins.init_plugins()
        self._dispatcher.start()
        self._client.rtm_connect()
        _thread.start_new_thread(self._keepactive, tuple())
        logger.info('connected to slack RTM api')
        self._dispatcher.loop()

    def _keepactive(self):
        logger.info('keep active thread started')
        while True:
            time.sleep(30 * 60)
            self._client.ping()
Ejemplo n.º 4
0
 def __init__(self):
     self._client = SlackClient(settings.API_TOKEN,
                                bot_icon=settings.BOT_ICON if hasattr(
                                    settings, 'BOT_ICON') else None,
                                bot_emoji=settings.BOT_EMOJI if hasattr(
                                    settings, 'BOT_EMOJI') else None)
     self._plugins = PluginsManager()
     self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                          settings.ERRORS_TO)
Ejemplo n.º 5
0
 def __init__(self):
     self._client = SlackClient(
         CONFIG.slack_api_token,
         timeout=settings.TIMEOUT if hasattr(settings, 'TIMEOUT') else None,
         bot_icon=settings.BOT_ICON
         if hasattr(settings, 'BOT_ICON') else None,
         bot_emoji=settings.BOT_EMOJI
         if hasattr(settings, 'BOT_EMOJI') else None)
     self._plugins = PluginsManager()
     self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                          settings.ERRORS_TO)
Ejemplo n.º 6
0
def handle_message(text, *, category="respond_to", expect_reaction=True):
    client = SlackClient("api_token", connect=False)
    plugins = PluginsManager()
    plugins.init_plugins()
    dispatcher = MessageDispatcher(client, plugins, None)
    msg = [
        category,
        {
            "text": text,
            "channel": "channel",
            "ts": TS
        },
    ]

    if expect_reaction:
        with assert_slack_client_reacts_to_message():
            dispatcher.dispatch_msg(msg)
    else:
        with assert_slack_client_doesnt_react_to_message():
            dispatcher.dispatch_msg(msg)
Ejemplo n.º 7
0
 def __init__(self):
     self._client = SlackClient(
         settings.API_TOKEN,
         bot_icon=settings.BOT_ICON if hasattr(settings,
                                               'BOT_ICON') else None,
         bot_emoji=settings.BOT_EMOJI if hasattr(settings,
                                                 'BOT_EMOJI') else None
     )
     self._plugins = PluginsManager()
     self._dispatcher = MessageDispatcher(self._client, self._plugins,
                                          settings.ERRORS_TO)
Ejemplo n.º 8
0
def handle_message(text, expect_reaction=True):
    client = SlackClient("api_token", connect=False)
    plugins = PluginsManager()
    dispatcher = MessageDispatcher(client, plugins, None)
    msg = [
        "respond_to",
        {"text": text, "channel": "channel", "ts": str(time.mktime(T0.timetuple()))},
    ]

    if expect_reaction:
        with assert_slack_client_reacts_to_message():
            dispatcher.dispatch_msg(msg)
    else:
        with assert_slack_client_doesnt_react_to_message():
            dispatcher.dispatch_msg(msg)
Ejemplo n.º 9
0
 def __init__(self, slackclient, body):
     self._client = slackclient
     self._body = body
     self._plugins = PluginsManager()
Ejemplo n.º 10
0
def test_import_plugin_single_module():
    assert 'fake_plugin_module' not in sys.modules
    PluginsManager()._load_plugins('fake_plugin_module')
    assert 'fake_plugin_module' in sys.modules