isup.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from event import Event
  2. try:
  3. import requests
  4. except ImportError:
  5. print "Warning: isup module requires requests."
  6. requests = object
  7. from xml.dom.minidom import parseString
  8. try:
  9. from basemodule import BaseModule
  10. except ImportError:
  11. from modules.basemodule import BaseModule
  12. class Isup(BaseModule):
  13. def post_init(self):
  14. isup = Event("__.isup__")
  15. isup.define(msg_definition="^\.isup")
  16. isup.subscribe(self)
  17. # register ourself to our new isup event
  18. self.bot.register_event(isup, self)
  19. self.url = "http://isup.me/"
  20. def handle(self, event):
  21. if len(event.msg.split()) == 2:
  22. r = requests.get(self.url + event.msg.split()[1])
  23. # we get back plain HTML. hopefully the phrases don't change.
  24. up = "It's just you."
  25. down = "looks down from here"
  26. not_a_site = "doesn't look like a site"
  27. if r.text.find(up) != -1:
  28. self.say(event.channel, event.msg.split()[1] + " looks up.")
  29. elif r.text.find(not_a_site) != -1:
  30. self.say(event.channel, event.msg.split()[1] + " is not a site.")
  31. elif r.text.find(down) != -1:
  32. self.say(event.channel, event.msg.split()[1] + " looks down.")