Changed client id to be sent as a get variable, as it's not working sending through the headers
This commit is contained in:
parent
2fef94db0f
commit
99fad1d184
|
@ -15,12 +15,13 @@ class Twitch:
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.key = config.twitch_key
|
||||||
self.headers = {"User-Agent": "Bonfire/1.0.0",
|
self.headers = {"User-Agent": "Bonfire/1.0.0",
|
||||||
"Client-ID": config.twitch_key}
|
"Client-ID": self.key}
|
||||||
|
|
||||||
async def channel_online(self, channel: str):
|
async def channel_online(self, channel: str):
|
||||||
# Check a specific channel's data, and get the response in text format
|
# Check a specific channel's data, and get the response in text format
|
||||||
url = "https://api.twitch.tv/kraken/streams/{}".format(channel)
|
url = "https://api.twitch.tv/kraken/streams/{}?client_id={}".format(channel, self.key)
|
||||||
with aiohttp.ClientSession() as s:
|
with aiohttp.ClientSession() as s:
|
||||||
async with s.get(url, headers=self.headers) as r:
|
async with s.get(url, headers=self.headers) as r:
|
||||||
response = await r.text()
|
response = await r.text()
|
||||||
|
@ -105,7 +106,7 @@ class Twitch:
|
||||||
url = result['twitch_url']
|
url = result['twitch_url']
|
||||||
user = re.search("(?<=twitch.tv/)(.*)", url).group(1)
|
user = re.search("(?<=twitch.tv/)(.*)", url).group(1)
|
||||||
with aiohttp.ClientSession() as s:
|
with aiohttp.ClientSession() as s:
|
||||||
async with s.get("https://api.twitch.tv/kraken/channels/{}".format(user), headers=self.headers) as r:
|
async with s.get("https://api.twitch.tv/kraken/channels/{}?client_id={}".format(user, self.key)) as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
|
|
||||||
fmt = "Username: {}".format(data['display_name'])
|
fmt = "Username: {}".format(data['display_name'])
|
||||||
|
@ -129,13 +130,13 @@ class Twitch:
|
||||||
try:
|
try:
|
||||||
url = re.search("((?<=://)?twitch.tv/)+(.*)", url).group(0)
|
url = re.search("((?<=://)?twitch.tv/)+(.*)", url).group(0)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
url = "https://www.twitch.tv/{}".format(url)
|
url = "https://www.twitch.tv/{}?client_id={}".format(url, self.key)
|
||||||
else:
|
else:
|
||||||
url = "https://www.{}".format(url)
|
url = "https://www.{}".format(url)
|
||||||
|
|
||||||
# Try to find the channel provided, we'll get a 404 response if it does not exist
|
# Try to find the channel provided, we'll get a 404 response if it does not exist
|
||||||
with aiohttp.ClientSession() as s:
|
with aiohttp.ClientSession() as s:
|
||||||
async with s.get(url, headers=self.headers) as r:
|
async with s.get(url) as r:
|
||||||
if not r.status == 200:
|
if not r.status == 200:
|
||||||
await self.bot.say("That twitch user does not exist! "
|
await self.bot.say("That twitch user does not exist! "
|
||||||
"What would be the point of adding a nonexistant twitch user? Silly")
|
"What would be the point of adding a nonexistant twitch user? Silly")
|
||||||
|
|
Loading…
Reference in a new issue