def run(self): announce("\nStarting Slack Machine:") with indent(4): show_valid("Connected to Slack") Scheduler.get_instance().start() show_valid("Scheduler started") if not self._settings['DISABLE_HTTP']: self._bottle_thread = Thread( target=bottle.run, kwargs=dict( host=self._settings['HTTP_SERVER_HOST'], port=self._settings['HTTP_SERVER_PORT'], server=self._settings['HTTP_SERVER_BACKEND'], )) self._bottle_thread.daemon = True self._bottle_thread.start() show_valid("Web server started") if self._settings['KEEP_ALIVE']: self._keep_alive_thread = Thread(target=self._keepalive) self._keep_alive_thread.daemon = True self._keep_alive_thread.start() show_valid("Keepalive thread started [Interval: %ss]" % self._settings['KEEP_ALIVE']) show_valid("Dispatcher started") self._dispatcher.start()
def _register_plugin_actions(self, plugin_class, metadata, cls_instance, fn_name, fn, class_help): fq_fn_name = "{}.{}".format(plugin_class, fn_name) if fn.__doc__: self._help['human'][class_help][ fq_fn_name] = self._parse_human_help(fn.__doc__) for action, config in metadata['plugin_actions'].items(): if action == 'process': event_type = config['event_type'] RTMClient.on(event=event_type, callback=callable_with_sanitized_event(fn)) if action == 'respond_to' or action == 'listen_to': for regex in config['regex']: event_handler = { 'class': cls_instance, 'class_name': plugin_class, 'function': fn, 'regex': regex } key = "{}-{}".format(fq_fn_name, regex.pattern) self._plugin_actions[action][key] = event_handler self._help['robot'][class_help].append( self._parse_robot_help(regex, action)) if action == 'schedule': Scheduler.get_instance().add_job(fq_fn_name, trigger='cron', args=[cls_instance], id=fq_fn_name, replace_existing=True, **config) if action == 'route': for route_config in config: bottle.route(**route_config)(fn)
def send_dm_scheduled(self, when: datetime, user, text: str, **kwargs): args = [self, user, text] Scheduler.get_instance().add_job(SlackClient.send_dm, trigger='date', args=args, kwargs=kwargs, run_date=when)
def send_scheduled(self, when: datetime, channel: Union[Channel, str], text: str, **kwargs): args = [self, channel, text] Scheduler.get_instance().add_job(SlackClient.send, trigger='date', args=args, kwargs=kwargs, run_date=when)