mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-09 19:02:32 -05:00
[Streams] Added command to set Twitch's Client-ID
[p]streamset twitchtoken <token> It will soon be mandatory to make Twitch API calls
This commit is contained in:
@@ -3,6 +3,7 @@ from discord.ext import commands
|
|||||||
from .utils.dataIO import fileIO
|
from .utils.dataIO import fileIO
|
||||||
from .utils.chat_formatting import *
|
from .utils.chat_formatting import *
|
||||||
from .utils import checks
|
from .utils import checks
|
||||||
|
from __main__ import send_cmd_help
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@@ -21,6 +22,7 @@ class Streams:
|
|||||||
self.twitch_streams = fileIO("data/streams/twitch.json", "load")
|
self.twitch_streams = fileIO("data/streams/twitch.json", "load")
|
||||||
self.hitbox_streams = fileIO("data/streams/hitbox.json", "load")
|
self.hitbox_streams = fileIO("data/streams/hitbox.json", "load")
|
||||||
self.beam_streams = fileIO("data/streams/beam.json", "load")
|
self.beam_streams = fileIO("data/streams/beam.json", "load")
|
||||||
|
self.settings = fileIO("data/streams/settings.json", "load")
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def hitbox(self, stream: str):
|
async def hitbox(self, stream: str):
|
||||||
@@ -253,6 +255,22 @@ class Streams:
|
|||||||
await self.bot.say("There will be no more stream alerts in this "
|
await self.bot.say("There will be no more stream alerts in this "
|
||||||
"channel.")
|
"channel.")
|
||||||
|
|
||||||
|
@commands.group(pass_context=True)
|
||||||
|
@checks.is_owner()
|
||||||
|
async def streamset(self, ctx):
|
||||||
|
"""Stream settings"""
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await send_cmd_help(ctx)
|
||||||
|
|
||||||
|
@streamset.command()
|
||||||
|
async def twitchtoken(self, token : str):
|
||||||
|
"""Sets the Client-ID for Twitch
|
||||||
|
|
||||||
|
https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843"""
|
||||||
|
self.settings["TWITCH_TOKEN"] = token
|
||||||
|
fileIO("data/streams/settings.json", "save", self.settings)
|
||||||
|
await self.bot.say('Twitch Client-ID set.')
|
||||||
|
|
||||||
async def hitbox_online(self, stream):
|
async def hitbox_online(self, stream):
|
||||||
url = "https://api.hitbox.tv/user/" + stream
|
url = "https://api.hitbox.tv/user/" + stream
|
||||||
try:
|
try:
|
||||||
@@ -269,8 +287,9 @@ class Streams:
|
|||||||
|
|
||||||
async def twitch_online(self, stream):
|
async def twitch_online(self, stream):
|
||||||
url = "https://api.twitch.tv/kraken/streams?channel=" + stream
|
url = "https://api.twitch.tv/kraken/streams?channel=" + stream
|
||||||
|
header = {'Client-ID': self.settings.get("TWITCH_TOKEN", "")}
|
||||||
try:
|
try:
|
||||||
async with aiohttp.get(url) as r:
|
async with aiohttp.get(url, headers=header) as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
if len(data["streams"]) > 0:
|
if len(data["streams"]) > 0:
|
||||||
return True
|
return True
|
||||||
@@ -404,6 +423,11 @@ def check_files():
|
|||||||
print("Creating empty beam.json...")
|
print("Creating empty beam.json...")
|
||||||
fileIO(f, "save", [])
|
fileIO(f, "save", [])
|
||||||
|
|
||||||
|
f = "data/streams/settings.json"
|
||||||
|
if not fileIO(f, "check"):
|
||||||
|
print("Creating empty settings.json...")
|
||||||
|
fileIO(f, "save", {})
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
logger = logging.getLogger('aiohttp.client')
|
logger = logging.getLogger('aiohttp.client')
|
||||||
|
|||||||
Reference in New Issue
Block a user