コード例 #1
0
ファイル: core.py プロジェクト: rubedolife/slack-machine
    def run(self):
        announce("\nStarting Slack Machine:")
        with indent(4):
            connected = self._client.rtm_connect()
            if not connected:
                logger.error("Could not connect to Slack! Aborting...")
                sys.exit(1)
            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()
コード例 #2
0
ファイル: core.py プロジェクト: 7minus2/slack-machine
 def _register_plugin_actions(self, plugin_class, metadata, cls_instance, fn_name, fn):
     fq_fn_name = "{}.{}".format(plugin_class, fn_name)
     for action, config in metadata['plugin_actions'].items():
         if action == 'process':
             event_type = config['event_type']
             event_handlers = self._plugin_actions['process'].get(event_type, {})
             event_handlers[fq_fn_name] = {
                 'class': cls_instance,
                 'class_name': plugin_class,
                 'function': fn
             }
             self._plugin_actions['process'][event_type] = event_handlers
         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
         if action == 'schedule':
             Scheduler.get_instance().add_job(fq_fn_name, trigger='cron', args=[cls_instance],
                                              id=fq_fn_name, replace_existing=True, **config)
コード例 #3
0
ファイル: core.py プロジェクト: rubedolife/slack-machine
 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']
             event_handlers = self._plugin_actions['process'].get(event_type, {})
             event_handlers[fq_fn_name] = {
                 'class': cls_instance,
                 'class_name': plugin_class,
                 'function': fn
             }
             self._plugin_actions['process'][event_type] = event_handlers
         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)
コード例 #4
0
 def send_dm_scheduled(self, when, user, text, name):
     args = [self, user, text]
     Scheduler.get_instance().add_job(MessagingClient.send_dm,
                                      trigger='date',
                                      args=args,
                                      name=name,
                                      run_date=when)
コード例 #5
0
ファイル: slack.py プロジェクト: rubedolife/slack-machine
    def send_scheduled(self, when, channel, text):
        args = [self, channel, text]
        kwargs = {'thread_ts': None}

        Scheduler.get_instance().add_job(trigger='date',
                                         args=args,
                                         kwargs=kwargs,
                                         run_date=when)
コード例 #6
0
ファイル: slack.py プロジェクト: rubedolife/slack-machine
    def send_dm_webapi_scheduled(self, when, user, text, attachments=None):
        args = [self, user, text]
        kwargs = {'attachments': attachments}

        Scheduler.get_instance().add_job(MessagingClient.send_dm_webapi,
                                         trigger='data',
                                         args=args,
                                         kwargs=kwargs)
コード例 #7
0
ファイル: core.py プロジェクト: 7minus2/slack-machine
 def run(self):
     announce("\nStarting Slack Machine:")
     with indent(4):
         self._client.rtm_connect()
         show_valid("Connected to Slack")
         Scheduler.get_instance().start()
         show_valid("Scheduler started")
         show_valid("Dispatcher started")
         self._dispatcher.start()
コード例 #8
0
ファイル: slack.py プロジェクト: 7minus2/slack-machine
    def send_webapi_scheduled(self, when, channel, text, attachments=None, ephemeral_user=None):
        args = [self, channel, text]
        kwargs = {
            'attachments': attachments,
            'thread_ts': None,
            'ephemeral_user': ephemeral_user
        }

        Scheduler.get_instance().add_job(MessagingClient.send_webapi, trigger='date', args=args,
                                         kwargs=kwargs, run_date=when)
コード例 #9
0
 def topics2(self, msg):
     test = Scheduler.get_instance().get_jobs()
     print('----')
     dict = {}
     dict[msg.sender.name] = {}
     for x in test:
         dict[msg.sender.name][x.name] = {}
         dict[msg.sender.name][x.name]['id'] = x.id
         dict[msg.sender.name][x.name]['runtime'] = datetime.strftime(
             x.next_run_time, "%Y-%m-%d %H:%M:%S")
     print(dict)
     print('........')
     print(dict.get(msg.sender.name).get(msg.sender.name + "_lunch"))
     #print(Scheduler.get_instance().get_job(x.id))
     print('----')
     print("===============")