Пример #1
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)
Пример #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)

    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()