reflect.py 989 B

123456789101112131415161718192021222324252627
  1. import sys
  2. from util import commands
  3. from util import parse_line
  4. from logger import Logger
  5. @commands(".reflect")
  6. def reflect_reload(bot, message, channel):
  7. logger = bot.logger
  8. parsed = parse_line(message)
  9. #for k,v in parsed.__dict__.iteritems():
  10. # print k, ": ", v
  11. body = message.split(":")[2:]
  12. recomposed = "".join(body)
  13. if recomposed.startswith(".reflect reload"):
  14. for m in recomposed.split()[2:]:
  15. if m in sys.modules:
  16. try:
  17. reload(sys.modules[m])
  18. bot.brain.notice(channel, 'reloaded ' + m)
  19. logger.write(Logger.INFO, bot.getName() + ": reloaded " + m, bot.NICK)
  20. except ImportError as e:
  21. bot.brain.notice(channel, 'failed to reload ' + m)
  22. logger.write(Logger.CRITICAL, bot.getName() + ": failed to reload " + m, bot.NICK)
  23. logger.write(Logger.CRITICAL, bot.getName() + ": error was:", bot.NICK)
  24. logger.write(Logger.CRITICAL, bot.getName() + ": " + e, bot.NICK)
  25. return