]>
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
23 from BeautifulSoup
import BeautifulSoup
26 hostmask_regex
= re
.compile('^(.*)!(.*)@(.*)$')
27 url_regex
= re
.compile('(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?')
28 def parser_hostmask(hostmask
):
29 if isinstance(hostmask
, dict):
36 if hostmask
is not None:
37 match
= hostmask_regex
.match(hostmask
)
52 @lib.hooknum("PRIVMSG")
53 def privmsg_hook(bot
, line
):
54 sender
= parser_hostmask(line
[1:line
.find(' ')])
57 linetx
= line
.split(None, 3)[3][1:]
61 if checkfor
not in line
:
62 return # doesn't concern us
64 for p
, h
, c
in url_regex
.findall(linetx
):
66 url
= 'http://api.justin.tv/api/stream/list.json?channel=%s' % c
[1:]
67 respdata
= urllib2
.urlopen(url
).read()
68 twitch
= json
.loads(respdata
)
70 bot
.msg(line
.split()[2], 'Twitch: %s (%s)' % (twitch
[0]['channel']['status'], twitch
[0]['channel']['meta_game']))
72 bot
.msg(line
.split()[2], 'Twitch: Channel offline.')