help.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from time import sleep
  2. from event import Event
  3. class Help:
  4. def __init__(self, events=None, printer_handle=None, bot=None, say=None):
  5. self.events = events
  6. self.printer = printer_handle
  7. self.interests = ['__.help__']
  8. self.bot = bot
  9. self.say = say
  10. for event in events:
  11. if event._type in self.interests:
  12. event.subscribe(self)
  13. help = Event("__.help__")
  14. help.define(msg_definition="^\.help")
  15. help.subscribe(self)
  16. self.bot.register_event(help,self)
  17. self.help = ".help"
  18. def handle(self, event):
  19. try:
  20. my_modules = list()
  21. self.printer("PRIVMSG " + event.user + " :Help: \n")
  22. for m in self.bot.events_list:
  23. for s in m.subscribers:
  24. my_modules.append(s)
  25. modules_set = set(my_modules)
  26. line_list = list()
  27. for sm in modules_set:
  28. if hasattr(sm, "help") and sm.help is not None:
  29. line_list.append(sm.help)
  30. self.say(event.user, ", ".join(line_list))
  31. #self.printer("PRIVMSG " + event.user + " :" + ", ".join(line_list) + "\n")
  32. except:
  33. pass