mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 04:08:56 -05:00
Fix for recent twitch API changes
This commit is contained in:
parent
ba81bc78c9
commit
76723d5fef
@ -70,12 +70,12 @@ class Streams:
|
|||||||
async def twitch_alert(self, ctx, stream : str):
|
async def twitch_alert(self, ctx, stream : str):
|
||||||
"""Adds/removes twitch alerts from the current channel"""
|
"""Adds/removes twitch alerts from the current channel"""
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
check = await self.twitch_online(stream)
|
check = await self.twitch_exists(stream)
|
||||||
if check == None:
|
if check is False:
|
||||||
await self.bot.say("That stream doesn't exist.")
|
await self.bot.say("That stream doesn't exist.")
|
||||||
return
|
return
|
||||||
elif check == "error":
|
elif check == "error":
|
||||||
await self.bot.say("Error.")
|
await self.bot.say("Couldn't contact Twitch API. Try again later.")
|
||||||
return
|
return
|
||||||
|
|
||||||
done = False
|
done = False
|
||||||
@ -237,17 +237,14 @@ class Streams:
|
|||||||
return "error"
|
return "error"
|
||||||
|
|
||||||
async def twitch_online(self, stream):
|
async def twitch_online(self, stream):
|
||||||
url = "https://api.twitch.tv/kraken/streams/" + stream
|
url = "https://api.twitch.tv/kraken/streams?channel=" + stream
|
||||||
|
try:
|
||||||
async with aiohttp.get(url) as r:
|
async with aiohttp.get(url) as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
try:
|
if len(data["streams"]) > 0:
|
||||||
if "stream" in data:
|
|
||||||
if data["stream"] != None:
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif "error" in data:
|
|
||||||
return None
|
|
||||||
except:
|
except:
|
||||||
return "error"
|
return "error"
|
||||||
return "error"
|
return "error"
|
||||||
@ -268,6 +265,18 @@ class Streams:
|
|||||||
return "error"
|
return "error"
|
||||||
return "error"
|
return "error"
|
||||||
|
|
||||||
|
async def twitch_exists(self, stream):
|
||||||
|
url = "https://api.twitch.tv/channels/" + stream
|
||||||
|
try:
|
||||||
|
async with aiohttp.get(url) as r:
|
||||||
|
data = await r.json()
|
||||||
|
if "error" in data:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return "error"
|
||||||
|
|
||||||
async def stream_checker(self):
|
async def stream_checker(self):
|
||||||
CHECK_DELAY = 60
|
CHECK_DELAY = 60
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user