· 7 years ago · Jun 23, 2018, 06:10 PM
1import sys
2import irc.bot
3import requests
4
5class TwitchBot(irc.bot.SingleServerIRCBot):
6 def __init__(self, username, client_id, token, channel):
7 self.client_id = client_id
8 self.token = token
9 self.channel = '#' + channel
10 url = 'https://api.twitch.tv/kraken/users?login=' + channel
11 headers = {'Client-ID': client_id, 'Accept': 'application/vnd.twitchtv.v5+json'}
12 r = requests.get(url, headers=headers).json()
13 self.channel_id = r['users'][0]['_id']
14 server = 'irc.chat.twitch.tv'
15 port = 6667
16 irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:'+token)], username, username)
17 print('Connecting to ' + server + ' on port ' + str(port) + '...')
18
19 def on_welcome(self, c, e):
20 print('Joining ' + self.channel)
21 c.cap('REQ', ':twitch.tv/membership')
22 c.cap('REQ', ':twitch.tv/tags')
23 c.cap('REQ', ':twitch.tv/commands')
24 c.join(self.channel)
25
26 def on_pubmsg(self, c, e):
27 print(e)
28 print(c)
29
30targetChannel = "ehhdannn"
31client_id = "ivckprk09lhjn7s201ub44ndnkkkh2"
32token = "gr27zubl7cc2jhcopk683azi2ftwk6"
33
34bot = TwitchBot(targetChannel, client_id, token, targetChannel)
35bot.start()