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()
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()
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 __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 __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)
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)
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()
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 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)
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)
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")
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")
def __init__(self): self._client = SlackClient(settings.API_TOKEN) self._plugins = PluginsManager() self._dispatcher = MessageDispatcher(self._client, self._plugins)