1

I have several helper methods I'd like to include on all of my plugins (things like manipulating lists in persistent storage or setting up config templates), however it looks like from the docs (and in practice) that plugins must inherit from BotPlugin and BotPlugin only. This scuppers my initial idea of having my own base bot class that includes all of these useful behaviors and then having individual plugins inherit from there.

I'm curious why errbot was setup this way and if there might be a reasonable workaround to enable inheritance of plugin classes?

For example:

class BaseBot(BotPlugin):
    # common methods

from base_bot import BaseBot
class MyPlugin1(BaseBot):
    # doesn't work, errbot won't detect the plugin
Alex Schokking
  • 656
  • 1
  • 6
  • 13

1 Answers1

1

however it looks like from the docs (and in practice) that plugins must inherit from BotPlugin and BotPlugin only.

This is correct and the reasons for this mostly have to do with the fact that we use yapsy as our plugin manager. It must know which class from a plugin to actually load (in case a plugin contains multiple classes).

The BotPlugin class also contains all the methods a plugin has at it's disposal (and all the callbacks it may implement) so it also serves as a framework for that.

Now, on to your actual question, you could use a mixin for the shared functionality. Define a common class (lets say, class CommonFunctionalityMixin) which can be imported by all your plugins, then let those plugins inherit from it in addition to BotPlugin:

class MyPlugin(BotPlugin, CommonFunctionalityMixin):
  # ...has all of BotPlugin as well as CommonFunctionalityMixin

See errcron for a real-world example of this technique.

Community
  • 1
  • 1
Nick Groenen
  • 144
  • 1
  • 3