debugger.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from event import Event
  2. import ast
  3. try:
  4. from basemodule import BaseModule
  5. except ImportError:
  6. from modules.basemodule import BaseModule
  7. class Debugger(BaseModule):
  8. def post_init(self):
  9. debug_event = Event("__.debug__")
  10. debug_event.define(msg_definition="^\.debug")
  11. debug_event.subscribe(self)
  12. # register ourself to our new debug_event event
  13. self.bot.register_event(debug_event, self)
  14. def recurse(self, obj):
  15. if type(obj) is not dict:
  16. print obj
  17. else:
  18. for k in obj:
  19. self.recurse(k)
  20. def pretty(self, d, event, indent=0):
  21. for key, value in d.iteritems():
  22. self.say(event.user, '\t' * indent + key.encode('utf-8','ignore'))
  23. if isinstance(value, dict):
  24. pretty(value, event, indent+1)
  25. else:
  26. try:
  27. self.say(event.user, '\t' * (indent+1) + str(value))
  28. except:
  29. self.say(event.user,'\t' * (indent+1) + value.encode('utf-8','ignore'))
  30. def handle(self, event):
  31. if not self.bot.brain._isAdmin(event.user):
  32. return
  33. try:
  34. key = event.msg.split()[1]
  35. keyslist = []
  36. for thing in event.msg.split()[1:]:
  37. keyslist.append(thing)
  38. # print self.bot.mem_store[thing]
  39. if len(keyslist) > 1:
  40. neststring = ""
  41. for k in keyslist:
  42. neststring = neststring+'[\''+k+'\']'
  43. # print neststring
  44. try:
  45. self.pretty(self.bot.mem_store[key], event)
  46. except KeyError:
  47. self.say(event.user, "no key by name " + key)
  48. # HIGHLY insecure; TODO
  49. #self.pretty(self.bot.mem_store[eval(neststring)])
  50. #print self.bot.mem_store['qdb']['#fg']
  51. # outstr = ", ".join(self.bot.mem_store[key])
  52. # self.say(event.user, outstr)
  53. except IndexError:
  54. print "ERROR: "
  55. print event.msg