errbot-pomodoro-timerの修正メモ

公開しているErrbot用のプラグイン errbot-pomodoro-timer について、 Errbot 5.0.1で使用するときに読み込み失敗するエラーがあったので修正してました。

出てたエラー

❯ errbot -c demo.py
(略)
21:25:50 ERROR    yapsy                     Unable to create plugin object: ~~/errbot-pomodoro-timer/pomodoro
Traceback (most recent call last):
  File "~/venv/lib/python3.6/site-packages/yapsy/PluginManager.py", line 512, in loadPlugins
    plugin_info.plugin_object = self.instanciateElement(element)
  File "~/venv/lib/python3.6/site-packages/errbot/plugin_manager.py", line 265, in instanciateElement
    return element(self.bot, name=self._current_pluginfo.name)
TypeError: __init__() got an unexpected keyword argument 'name'
(略)
>>> !pomodoro start
Command "pomodoro" not found.

何が悪いのか

プラグインのロードに使っていると思われる、 instanciateElement が Errbot 5.0以降引数を2個取るようになっていた模様。

4.3 におけるplugin_manager.py

def instanciateElement(self, element) -> BotPlugin:
    """Overrides the instanciation of plugins to inject the bot reference."""
    return element(self.bot)

5.0 におけるplugin_manager.py

def instanciateElement(self, element) -> BotPlugin:
    """Overrides the instanciation of plugins to inject the bot reference."""
    return element(self.bot, name=self._current_pluginfo.name)

そして、 うかつにも__init__をオーバライドしていた自分のプラグイン

class Pomodoro(BotPlugin):
    WORK_MIN = 25
    REST_MIN = 5

    def __init__(self, bot):
        super().__init__(bot)
        self._runners = {}

直す

冷静に見返せば、 __init__() で追加でやろうとしていたのは別に activate でできるので、とっとと移植して終了。