feat: Start twitch user auth module.

This commit is contained in:
2024-09-06 10:59:47 +10:00
parent 7069c87e8e
commit 41f755795f
4 changed files with 75 additions and 0 deletions

9
src/twitch/__init__.py Normal file
View File

@@ -0,0 +1,9 @@
import logging
logger = logging.getLogger(__name__)
from .cog import TwitchAuthCog
async def setup(bot):
await bot.add_cog(TwitchAuthCog(bot))

7
src/twitch/authserver.py Normal file
View File

@@ -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?
"""

31
src/twitch/cog.py Normal file
View File

@@ -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):
...

28
src/twitch/data.py Normal file
View File

@@ -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