isup.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. try:
  23. r = requests.get(self.url + event.msg.split()[1])
  24. except requests.ConnectionError:
  25. self.say("Connection error.")
  26. # we get back plain HTML. hopefully the phrases don't change.
  27. up = "It's just you."
  28. down = "looks down from here"
  29. not_a_site = "doesn't look like a site"
  30. if r.text.find(up) != -1:
  31. self.say(event.channel, event.msg.split()[1] + " looks up.")
  32. elif r.text.find(not_a_site) != -1:
  33. self.say(event.channel, event.msg.split()[1] + " is not a site.")
  34. elif r.text.find(down) != -1:
  35. self.say(event.channel, event.msg.split()[1] + " looks down.")