help.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ##Lists modules and usage##
  2. from event import Event
  3. import sys
  4. try:
  5. if sys.version_info > (3,0,0):
  6. from .basemodule import BaseModule
  7. else:
  8. from basemodule import BaseModule
  9. except (ImportError, SystemError):
  10. from modules.basemodule import BaseModule
  11. class Help(BaseModule):
  12. def post_init(self):
  13. help = Event("__.help__")
  14. help.define(msg_definition="^\.help")
  15. help.subscribe(self)
  16. self.cmd = ".help"
  17. # register ourself to our new custom event
  18. self.bot.register_event(help, self)
  19. def handle(self, event):
  20. try:
  21. my_modules = list()
  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. """
  31. This jenky block controls how many modules to print per line
  32. To change the amount of modules print per line change the first 'q' to whatever number and match the incremented 'q and f' to the same number
  33. """
  34. #TODO make it better, probably pull out into a function
  35. self.say(event.user, "Help: \n")
  36. q = 3 # sets the starting end index
  37. f = 0 # sets the index to start from (The beginning of the list usually)
  38. for h in range(len(line_list)):
  39. self.say(event.user, ", ".join(line_list[f:q])) # Prints the line in a private message for each slice
  40. q += 3 # increments the end index
  41. f += 3 # increments the start index
  42. if q >= len(line_list):
  43. break
  44. except:
  45. pass