Example #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()
Example #2
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()
Example #3
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)
Example #4
0
 def __init__(self, api_token=None):
     if api_token is None:
         api_token = settings.API_TOKEN
     self._client = SlackClient(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)
     self._stop = threading.Event()
Example #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)
Example #6
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)
Example #7
0
class Bot(object):
    def __init__(self):
        self._client = SlackClient(settings.API_TOKEN)
        self._plugins = PluginsManager()
        self._dispatcher = MessageDispatcher(self._client, self._plugins)

    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()
Example #8
0
 def __init__(self, api_token=None):
   if api_token is None:
     api_token = settings.API_TOKEN
   self._client = SlackClient(
     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)
   self._stop = threading.Event()
Example #9
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)
Example #10
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)
Example #11
0
class Bot(object):
    def __init__(self, api_token=None):
        if api_token is None:
            api_token = settings.API_TOKEN
        self._client = SlackClient(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)
        self._stop = threading.Event()

    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 stop(self):
        self._stop.set()
        self._dispatcher.stop()

    def send_message(self, channel, message, **kwargs):
        """
      Send a message using the web API
      """
        logger.info("Send to %s: %s" % (channel, message))
        self._client.webapi.chat.post_message(channel,
                                              message,
                                              as_user=True,
                                              **kwargs)

    def _keepactive(self):
        logger.info('Start heartbeat thread')
        while not self._stop.isSet():
            self._stop.wait(30.0 * 60)
            self._client.ping()
        logger.info("Stop heartbeat thread")
Example #12
0
class Bot(object):
    def __init__(self, api_token=None):
      if api_token is None:
        api_token = settings.API_TOKEN
      self._client = SlackClient(
        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)
      self._stop = threading.Event()

    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 stop(self):
      self._stop.set()
      self._dispatcher.stop()

    def send_message(self, channel, message, **kwargs):
      """
      Send a message using the web API
      """
      logger.info("Send to %s: %s" % (channel,message))
      self._client.webapi.chat.post_message(channel, message, as_user=True, **kwargs)

    def _keepactive(self):
      logger.info('Start heartbeat thread')
      while not self._stop.isSet():
        self._stop.wait(30.0 * 60)
        self._client.ping()
      logger.info("Stop heartbeat thread")
Example #13
0
 def __init__(self):
     self._client = SlackClient(settings.API_TOKEN)
     self._plugins = PluginsManager()
     self._dispatcher = MessageDispatcher(self._client, self._plugins)