Search code examples
errbot

Yield from dependency plugin?


I want to make parser plugin, which will translate free form messages to the bot commands and run them from other plugins. Let's say I have PluginA and PluginB which depends on PluginA. On PluginA I have command:

    @botcmd
    def do_on_a(self, msg):
      yield "yielding first msg from A {}".format(msg)
      sleep(5)
      yield "yielding second msg from A {}".format(msg)

The only way I found to run it from PluginB is making a list from generator:

    @botcmd
    def get_from_a(self, msg, args):
      yield list(self.get_plugin('PluginA').do_on_A(msg))

But in this way I'm getting both PluginA messages in one time. Is there are a way to get messages from PluginA when they appears? Also maybe I can just form a bot command in plugin and send it to errbot like I send it from backend? Something like:

    @botcmd
    def get_from_a(self, msg, args):
      send "!do_on_a"

Solution

  • You have to make sure that the command from plugin B (which is calling A) is a generator which yields the items the command from plugin A is producing. The easiest is to use the yield from syntax introduced with Python 3.3:

    @botcmd
    def get_from_a(self, msg, args):
      yield from self.get_plugin('PluginA').do_on_A(msg)