archangelic / pinhook

the pluggable python framework for IRC bots and Twitch bots
https://archangelic.github.io/pinhook/
MIT License
31 stars 4 forks source link

Clarify Bot Extension Strategies #59

Closed ixxie closed 5 years ago

ixxie commented 5 years ago

Pinhook is designed to be extended by using command and listener plugins. Sometimes, however, it is natural to extend the Bot class in other ways. Currently I am struggling with appending a natural language processing model to the Bot class.

My current attempt involves creating a new class that instantiates a Pinhook Bot and a Model instance during init; it looks something like this:

from pinhook.bot import Bot

from mybot.nlp.model import Model

class Mybot:

    def __init__(self, **config):

        self.config = config
        self.model = Model()
        self.bot = Bot(
            use_prefix_for_plugins=True,
            **self.config
        )
        self.bot.start()

But now I want to create a listener which has access to the model attribute, and it is not clear how. I considered trying instead to extend the Bot class directly, but plugins do not have access to self anyway so this doesn't help me.

Any ideas on how I could work around this sort of issue?

ixxie commented 5 years ago

Maybe one way to do this is if Message included a bot argument that allowed passing self when the plugin is triggered. That way all plugins would have access to Bot's attributes, making it easy to extend the class with funky functionality.

ixxie commented 5 years ago

Not sure if this is really the ideal implementation, but I did just test out the concept and it works so I made a PR: https://github.com/archangelic/pinhook/pull/60

archangelic commented 5 years ago

Closed by #60