]>
jfr.im git - erebus.git/blob - modules/twitch.py
1 # Erebus IRC bot - Author: Conny Sjoblom
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Conny Sjoblom',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
25 url_regex
= re
.compile('(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?')
27 @lib.hooknum("PRIVMSG")
28 def privmsg_hook(bot
, line
):
30 linetx
= line
.split(None, 3)[3][1:]
34 if checkfor
not in line
:
35 return # doesn't concern us
37 for p
, h
, c
in url_regex
.findall(linetx
):
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
)
43 bot
.msg(line
.split()[2], 'Twitch: %s (%s)' % (twitch
[0]['channel']['status'], twitch
[0]['channel']['meta_game']))
45 bot
.msg(line
.split()[2], 'Twitch: Channel offline.')