diff --git a/src/twitch/__init__.py b/src/twitch/__init__.py new file mode 100644 index 00000000..53e33e89 --- /dev/null +++ b/src/twitch/__init__.py @@ -0,0 +1,9 @@ +import logging + +logger = logging.getLogger(__name__) + +from .cog import TwitchAuthCog + +async def setup(bot): + await bot.add_cog(TwitchAuthCog(bot)) + diff --git a/src/twitch/authserver.py b/src/twitch/authserver.py new file mode 100644 index 00000000..e87c433c --- /dev/null +++ b/src/twitch/authserver.py @@ -0,0 +1,7 @@ +""" +We want to open an aiohttp server and listen on a configured port. +When we get a request, we validate it to be 'of twitch form', +parse out the error or access token, state, etc, and then pass that information on. + +Passing on maybe done through webhook server? +""" diff --git a/src/twitch/cog.py b/src/twitch/cog.py new file mode 100644 index 00000000..5dfdc39d --- /dev/null +++ b/src/twitch/cog.py @@ -0,0 +1,31 @@ +import asyncio +from enum import Enum +from typing import Optional +from datetime import timedelta + +import discord +from discord.ext import commands as cmds +import twitchio +from twitchio.ext import commands + + +from data.queries import ORDER +from meta import LionCog, LionBot, CrocBot +from utils.lib import utc_now +from . import logger +from .data import TwitchAuthData + + +class TwitchAuthCog(LionCog): + def __init__(self, bot: LionBot): + self.bot = bot + self.data = bot.db.load_registry(TwitchAuthData()) + + async def cog_load(self): + await self.data.init() + + # ----- Auth API ----- + + async def fetch_client_for(self, userid: int): + ... + diff --git a/src/twitch/data.py b/src/twitch/data.py new file mode 100644 index 00000000..eed13589 --- /dev/null +++ b/src/twitch/data.py @@ -0,0 +1,28 @@ +from data import Registry, RowModel +from data.columns import Integer, String, Timestamp + + +class TwitchAuthData(Registry): + class UserAuthRow(RowModel): + """ + Schema + ------ + CREATE TABLE twitch_tokens( + userid BIGINT PRIMARY KEY, + access_token TEXT NOT NULL, + expires_at TIMESTAMPTZ NOT NULL, + refresh_token TEXT NOT NULL, + obtained_at TIMESTAMPTZ + ); + + """ + _tablename_ = 'twitch_tokens' + _cache_ = {} + + userid = Integer(primary=True) + access_token = String() + expires_at = Timestamp() + refresh_token = String() + obtained_at = Timestamp() + +# TODO: Scopes