예제 #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()
예제 #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()
예제 #3
0
파일: bot.py 프로젝트: phospodka/slackbot
 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)
예제 #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()
예제 #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)
예제 #6
0
파일: bot.py 프로젝트: venkytv/slackbot
 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)
예제 #7
0
파일: bot.py 프로젝트: lowks/slackbot
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()
예제 #8
0
파일: bot.py 프로젝트: zatonovo/slackbot
 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()
예제 #9
0
파일: test_bot.py 프로젝트: somulu/ebmbot
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)
예제 #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)
예제 #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")
예제 #12
0
파일: bot.py 프로젝트: zatonovo/slackbot
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")
예제 #13
0
파일: bot.py 프로젝트: lowks/slackbot
 def __init__(self):
     self._client = SlackClient(settings.API_TOKEN)
     self._plugins = PluginsManager()
     self._dispatcher = MessageDispatcher(self._client, self._plugins)