Beispiel #1
0
 def check_for_plugin_route_matches(self, line, router):
     """Checks the active plugins' routes and calls functions on matches"""
     # get the active routes for this channel
     active_slugs = line._active_plugin_slugs.intersection(
         router.viewkeys())
     for plugin_slug in active_slugs:
         for rule, func, plugin in router[plugin_slug]:
             match = re.match(rule, line.text, re.IGNORECASE)
             if match:
                 LOG.info('Match: %s.%s', plugin_slug, func.__name__)
                 with statsd.timer(".".join(["plugins", plugin_slug])):
                     # FIXME: This will not have correct timing if go back to
                     # gevent.
                     # Instantiate a plugin specific to this channel
                     channel_plugin = self.setup_plugin_for_channel(
                         plugin.__class__, line)
                     # get the method from the channel-specific plugin
                     new_func = log_on_error(
                         LOG, getattr(channel_plugin, func.__name__))
                     if hasattr(self, 'gevent'):
                         grnlt = self.gevent.Greenlet(
                             new_func, line, **match.groupdict())
                         grnlt.link_value(channel_plugin.greenlet_respond)
                         grnlt.start()
                     else:
                         channel_plugin.respond(
                             new_func(line, **match.groupdict()))
Beispiel #2
0
    def dispatch(self, line):
        """Given a line, dispatch it to the right plugins & functions."""
        # This is a pared down version of the `check_for_plugin_route_matches`
        # method for firehose plugins (no regexing or return values)
        active_firehose_plugins = line._active_plugin_slugs.intersection(
            self.firehose_router.viewkeys())
        for plugin_slug in active_firehose_plugins:
            for _, func, plugin in self.firehose_router[plugin_slug]:
                # firehose gets everything, no rule matching
                LOG.info('Match: %s.%s', plugin_slug, func.__name__)
                with statsd.timer(".".join(["plugins", plugin_slug])):
                    # FIXME: This will not have correct timing if go back to
                    # gevent.
                    channel_plugin = self.setup_plugin_for_channel(
                        plugin.__class__, line)
                    new_func = log_on_error(
                        LOG, getattr(channel_plugin, func.__name__))
                    if hasattr(self, 'gevent'):
                        self.gevent.Greenlet.spawn(new_func, line)
                    else:
                        channel_plugin.respond(new_func(line))

        # pass line to other routers
        if line._is_message:
            self.check_for_plugin_route_matches(line, self.messages_router)

            if line.is_direct_message:
                self.check_for_plugin_route_matches(line, self.mentions_router)
Beispiel #3
0
 def check_for_plugin_route_matches(self, line, router):
     """Checks the active plugins' routes and calls functions on matches"""
     # get the active routes for this channel
     active_slugs = line._active_plugin_slugs.intersection(router.viewkeys())
     for plugin_slug in active_slugs:
         for rule, func, plugin in router[plugin_slug]:
             match = re.match(rule, line.text, re.IGNORECASE)
             if match:
                 LOG.info('Match: %s.%s', plugin_slug, func.__name__)
                 with statsd.timer(".".join(["plugins", plugin_slug])):
                     # FIXME: This will not have correct timing if go back to
                     # gevent.
                     # Instantiate a plugin specific to this channel
                     channel_plugin = self.setup_plugin_for_channel(
                         plugin.__class__, line)
                     # get the method from the channel-specific plugin
                     new_func = log_on_error(LOG, getattr(channel_plugin,
                                                          func.__name__))
                     if hasattr(self, 'gevent'):
                         grnlt = self.gevent.Greenlet(new_func, line,
                                                      **match.groupdict())
                         grnlt.link_value(channel_plugin.greenlet_respond)
                         grnlt.start()
                     else:
                         channel_plugin.respond(new_func(line,
                                                         **match.groupdict()))
Beispiel #4
0
    def dispatch(self, line):
        """Given a line, dispatch it to the right plugins & functions."""
        # This is a pared down version of the `check_for_plugin_route_matches`
        # method for firehose plugins (no regexing or return values)
        active_firehose_plugins = line._active_plugin_slugs.intersection(
            self.firehose_router.viewkeys())
        for plugin_slug in active_firehose_plugins:
            for _, func, plugin in self.firehose_router[plugin_slug]:
                # firehose gets everything, no rule matching
                LOG.info('Match: %s.%s', plugin_slug, func.__name__)
                with statsd.timer(".".join(["plugins", plugin_slug])):
                    # FIXME: This will not have correct timing if go back to
                    # gevent.
                    channel_plugin = self.setup_plugin_for_channel(
                        plugin.__class__, line)
                    new_func = log_on_error(LOG, getattr(channel_plugin,
                                                         func.__name__))
                    if hasattr(self, 'gevent'):
                        self.gevent.Greenlet.spawn(new_func, line)
                    else:
                        channel_plugin.respond(new_func(line))

        # pass line to other routers
        if line._is_message:
            self.check_for_plugin_route_matches(line, self.messages_router)

            if line.is_direct_message:
                self.check_for_plugin_route_matches(line, self.mentions_router)
    def run_plugin(self, line, plugin, plugin_slug, func, arg_dict):
        with statsd.timer(".".join(["plugins", plugin_slug])):
            # FIXME: This will not have correct timing if go back to
            # gevent.
            # Instantiate a plugin specific to this channel
            channel_plugin = self.setup_plugin_for_channel(
                plugin.__class__, line)
            # get the method from the channel-specific plugin
            new_func = log_on_error(LOG, getattr(channel_plugin,
                                                 func.__name__))

            if hasattr(self, 'gevent'):
                grnlt = self.gevent.Greenlet(new_func, line, **arg_dict)
                grnlt.link_value(channel_plugin.greenlet_respond)
                grnlt.start()
            else:
                channel_plugin.respond(new_func(line, **arg_dict))