Isup.handle()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 16
rs 8
c 0
b 0
f 0
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
18
    # register ourself to our new isup event
19
    self.bot.register_event(isup, self)
20
21
    self.url = "http://isup.me/"
22
    
23
  def handle(self, event):
24
    if len(event.msg.split()) == 2:
25
      try:
26
        r = requests.get(self.url + event.msg.split()[1])
27
      except requests.ConnectionError:
28
        self.say("Connection error.")
29
      # we get back plain HTML. hopefully the phrases don't change.
30
      up = "It's just you."
31
      down = "looks down from here"
32
      not_a_site = "doesn't look like a site"
33
      if r.text.find(up) != -1:
34
        self.say(event.channel, event.msg.split()[1] + " looks up.")
35
      elif r.text.find(not_a_site) != -1:
36
        self.say(event.channel, event.msg.split()[1] + " is not a site.")
37
      elif r.text.find(down) != -1:
38
        self.say(event.channel, event.msg.split()[1] + " looks down.")
39
        
40