1234567891011121314151617181920212223242526272829 |
- import logging
- from functools import reduce
- class RollbotPlugin:
- def __init__(self, command, bot, logger=logging.getLogger(__name__)):
- self.command = command
- self.bot = bot
- self.logger = logger
- self.logger.info(f"Intializing {type(self).__name__} matching {command}")
- def on_start(self, db):
- self.logger.info(f"No on_start initialization of {type(self).__name__}")
- def on_shutdown(self, db):
- self.logger.info(f"No on_shutdown de-initialization of {type(self).__name__}")
- def on_command(self, db, message):
- raise NotImplementedError
- def help_msg(self):
- return f"No help message provided for {self.command} command!"
- @staticmethod
- def find_all_plugins():
- def get_subclasses(clazz):
- s = set(clazz.__subclasses__())
- return s | reduce(set.union, (get_subclasses(sc) for sc in s), set())
- return get_subclasses(RollbotPlugin)
|