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
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 #4
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 #5
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")