]>
Commit | Line | Data |
---|---|---|
1 | # Erebus IRC bot - Author: Conny Sjoblom | |
2 | # Twitch URL Checker | |
3 | # This file is released into the public domain; see http://unlicense.org/ | |
4 | ||
5 | # module info | |
6 | modinfo = { | |
7 | 'author': 'Conny Sjoblom', | |
8 | 'license': 'public domain', | |
9 | 'compatible': [1], # compatible module API versions | |
10 | 'depends': [], # other modules required to work properly? | |
11 | } | |
12 | ||
13 | # preamble | |
14 | import modlib | |
15 | lib = modlib.modlib(__name__) | |
16 | modstart = lib.modstart | |
17 | modstop = lib.modstop | |
18 | ||
19 | # module code | |
20 | import re | |
21 | import urllib2 | |
22 | import json | |
23 | ||
24 | checkfor = "twitch" | |
25 | url_regex = re.compile('(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?') | |
26 | ||
27 | @lib.hooknum("PRIVMSG") | |
28 | def privmsg_hook(bot, line): | |
29 | try: | |
30 | linetx = line.split(None, 3)[3][1:] | |
31 | except IndexError: | |
32 | linetx = '' | |
33 | ||
34 | if checkfor not in line: | |
35 | return # doesn't concern us | |
36 | ||
37 | for p, h, c in url_regex.findall(linetx): | |
38 | if checkfor in h: | |
39 | url = 'http://api.justin.tv/api/stream/list.json?channel=%s' % c[1:] | |
40 | respdata = urllib2.urlopen(url).read() | |
41 | twitch = json.loads(respdata) | |
42 | try: | |
43 | bot.msg(line.split()[2], 'Twitch: %s (%s)' % (twitch[0]['channel']['status'], twitch[0]['channel']['meta_game'])) | |
44 | except: | |
45 | bot.msg(line.split()[2], 'Twitch: Channel offline.') |