base.py 958 B

1234567891011121314151617181920212223242526272829
  1. import logging
  2. from functools import reduce
  3. class RollbotPlugin:
  4. def __init__(self, command, bot, logger=logging.getLogger(__name__)):
  5. self.command = command
  6. self.bot = bot
  7. self.logger = logger
  8. self.logger.info(f"Intializing {type(self).__name__} matching {command}")
  9. def on_start(self, db):
  10. self.logger.info(f"No on_start initialization of {type(self).__name__}")
  11. def on_shutdown(self, db):
  12. self.logger.info(f"No on_shutdown de-initialization of {type(self).__name__}")
  13. def on_command(self, db, message):
  14. raise NotImplementedError
  15. def help_msg(self):
  16. return f"No help message provided for {self.command} command!"
  17. @staticmethod
  18. def find_all_plugins():
  19. def get_subclasses(clazz):
  20. s = set(clazz.__subclasses__())
  21. return s | reduce(set.union, (get_subclasses(sc) for sc in s), set())
  22. return get_subclasses(RollbotPlugin)