| Total Complexity | 7 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from event import Event |
||
| 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 |