From 3989896273f97b95cbb26fc87021870d778e03d8 Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 17 Mar 2023 16:35:23 +0100 Subject: [PATCH] Add helpers to add/remove handlers --- sid/plugin.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sid/plugin.py b/sid/plugin.py index b21cff9..efc9a14 100644 --- a/sid/plugin.py +++ b/sid/plugin.py @@ -31,6 +31,20 @@ class Plugin: def __init__(self, bot): self.bot = bot self.log = bot.log.getChild(self.__class__.__name__) + #: :py:obj:`list` : List of tuples (event, handler) + self.handlers = [] + + def add_handlers(self): + """Add handlers declared in self.hanlders""" + for event, handler in self.handlers: + self.log.debug(f'Add {event} > {self.__class__.__name__}().{handler.__name__}') + self.bot.add_event_handler(event, handler) + + def rm_handlers(self): + """Remove handlers declared in self.hanlders""" + for event, handler in self.handlers: + self.log.debug(f'Remove {event} > {self.__class__.__name__}().{handler.__name__}') + self.bot.del_event_handler(event, handler) def send(self, dest, msg, mtype='chat'): """Send msg to dest @@ -67,4 +81,5 @@ class Plugin: self.send(to, msg, mtype=rcv['type']) def shutdown(self): + """Empty method to override. Called on bot shutdown""" pass -- 2.39.5