Working on: The Twitch authentication
This commit is contained in:
35
CONTEXT.md
35
CONTEXT.md
@@ -122,7 +122,7 @@ This file tracks all active development tasks. It is based on the official `DEVE
|
|||||||
4. When your Pull Request is *merged*, move it to "Done."
|
4. When your Pull Request is *merged*, move it to "Done."
|
||||||
|
|
||||||
If you want to use emojis for visibility, here's some I have used:
|
If you want to use emojis for visibility, here's some I have used:
|
||||||
✔️ - Done | 🧑🔧 - In progress | ↗️ - Task evolved (should correspond with an edit in the [DEVELOPMENT_PLAN.md](DEVELOPMENT_PLAN.md)
|
✔️ - Done | 🧑🔧 - In progress | ↗️ - Task evolved (should correspond with an edit in the [DEVELOPMENT_PLAN.md](DEVELOPMENT_PLAN.md) )
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -132,10 +132,6 @@ If you want to use emojis for visibility, here's some I have used:
|
|||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
|
|
||||||
* `[ ]` **1.4: Basic Session Management:** Create a simple session/JWT system to know *who* is logged in.
|
|
||||||
|
|
||||||
### In Progress
|
|
||||||
|
|
||||||
### Done
|
### Done
|
||||||
* `[✔️]` **1.0: Project Skeleton** - @ramforth
|
* `[✔️]` **1.0: Project Skeleton** - @ramforth
|
||||||
* *Task:* Setup `main.py`, `requirements.txt`, and `.gitignore`.
|
* *Task:* Setup `main.py`, `requirements.txt`, and `.gitignore`.
|
||||||
@@ -143,39 +139,44 @@ If you want to use emojis for visibility, here's some I have used:
|
|||||||
* `[✔️]` **1.1.5: Discord Overview:** Create an automated 'TASK-LIST' and post to Discord whenever someone pushes a change to the repository. @ramforth
|
* `[✔️]` **1.1.5: Discord Overview:** Create an automated 'TASK-LIST' and post to Discord whenever someone pushes a change to the repository. @ramforth
|
||||||
* `[✔️]` **1.2: Twitch OAuth API:** Create FastAPI endpoints for `/login/twitch` (redirect) and `/auth/twitch/callback` (handles token exchange). @ramforth
|
* `[✔️]` **1.2: Twitch OAuth API:** Create FastAPI endpoints for `/login/twitch` (redirect) and `/auth/twitch/callback` (handles token exchange). @ramforth
|
||||||
* `[✔️]` **1.3: Secure Token Storage:** Implement helper functions to `encrypt` and `decrypt` OAuth tokens before storing them in the database. @ramforth
|
* `[✔️]` **1.3: Secure Token Storage:** Implement helper functions to `encrypt` and `decrypt` OAuth tokens before storing them in the database. @ramforth
|
||||||
|
* `[✔️]` **1.4: Basic Session Management:** Create a simple session/JWT system to know *who* is logged in. @ramforth
|
||||||
* `[✔️]` **1.5: Login Frontend:** Create a basic `login.html` file with a "Login with Twitch" button. @ramforth
|
* `[✔️]` **1.5: Login Frontend:** Create a basic `login.html` file with a "Login with Twitch" button. @ramforth
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⏳ Phase 2: User Dashboard & Configuration
|
## ⏳ Phase 2: User Dashboard & Configuration
|
||||||
|
|
||||||
* **Goal:** Allow logged-in users to see a dashboard, get their overlay URL, and save settings.
|
* **Goal:** Allow logged-in users to see a dashboard, get their overlay URL, and save settings. Now that Phase 1 is done, these tasks are ready to be worked on.
|
||||||
* *(All tasks for this phase are on hold until Phase 1 is complete)*
|
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
* `[ ]` **2.1: Dashboard UI:** Create `dashboard.html` (only for logged-in users).
|
|
||||||
* `[ ]` **2.2: Config API:** Create API endpoints (`GET`, `POST`) for `/api/settings` to save/load user preferences (e.g., custom CSS).
|
* `[ ]` **2.4: Create Logo and Favicon:** The project should have a logo and a favicon.
|
||||||
* `[ ]` **2.3: Overlay URL:** Generate and display the unique overlay URL for the user (e.g., `/overlay/{user_id}`).
|
|
||||||
|
### Done
|
||||||
|
* `[✔️]` **2.0: CSS Refactor & Styling:** Improved the general look and feel of the application pages, including a light/dark theme switcher.
|
||||||
|
* `[✔️]` **2.1: Dashboard UI:** Created `dashboard.html` for logged-in users to manage settings.
|
||||||
|
* `[✔️]` **2.2: Config API:** Created API endpoints for `/api/settings` to save user preferences.
|
||||||
|
* `[✔️]` **2.3: Overlay URL:** Generated and displayed the unique overlay URL for the user on the dashboard.
|
||||||
|
* `[✔️]` **2.5: Custom CSS Themes:** Implemented a system for users to create, preview, and delete their own private CSS overlay themes.
|
||||||
|
* `[✔️]` **2.6: CSS Help Page:** Created a guide for users on how to write custom CSS for their overlays.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 💬 Phase 3: Dynamic Listeners & Basic Overlay
|
## 💬 Phase 3: Real-time Chat & Overlay
|
||||||
|
|
||||||
* **Goal:** The core magic. Start chat listeners for users and show messages in the overlay.
|
* **Goal:** The core magic. Start chat listeners for users and show messages in the overlay.
|
||||||
* *(All tasks for this phase are on hold until Phase 2 is complete)*
|
* *(All tasks for this phase are on hold until Phase 2 is complete)*
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
* `[ ]` **3.1: Dynamic Listener Manager (The Big One):** Design a system (e.g., background service) to start/stop listener processes for users.
|
|
||||||
* `[ ]` **3.2: User-Specific Broadcasting:** Update the WebSocket system to use "rooms" (e.g., `/ws/{user_id}`) so users only get their *own* chat.
|
|
||||||
* `[ ]` **3.3: Basic Overlay UI:** Create the `overlay.html` page that connects to the WebSocket and displays messages.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
### Done
|
||||||
|
* `[✔️]` **3.1: Dynamic Listener Manager:** Designed and implemented a system to start/stop listener processes for users on application startup/shutdown.
|
||||||
|
* `[✔️]` **3.2: User-Specific Broadcasting:** Implemented a WebSocket manager and endpoint (`/ws/{user_id}`) to broadcast messages to the correct user's overlay.
|
||||||
|
* `[✔️]` **3.3: Basic Overlay UI:** Created dynamic overlay templates that connect to the WebSocket and display incoming chat messages.
|
||||||
|
|
||||||
## 💡 Backlog & Future Features
|
## 💡 Backlog & Future Features
|
||||||
|
|
||||||
* *(Tasks from Phase 4, Gitea Issues, etc., will be added here as we go)*
|
|
||||||
* `[ ]` Implement YouTube OAuth & `pytchat` listener (Phase 4).
|
* `[ ]` Implement YouTube OAuth & `pytchat` listener (Phase 4).
|
||||||
* `[ ]` "Single Message Focus" feature (Issue #1).
|
* `[ ]` "Single Message Focus" feature (Issue #1).
|
||||||
* `[ ]` Moderator panels (Issue #2).
|
* `[ ]` Moderator panels (Issue #2).
|
||||||
* `[ ]` Custom CSS storage & injection (Issue #6).
|
|
||||||
|
|
||||||
```
|
```
|
||||||
63
twitch_test.py
Normal file
63
twitch_test.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import twitchio
|
||||||
|
from twitchio.ext import commands
|
||||||
|
|
||||||
|
# --- Standalone Twitch IRC Connection Test ---
|
||||||
|
|
||||||
|
class TestBot(twitchio.Client):
|
||||||
|
"""A minimal twitchio client for testing IRC connectivity."""
|
||||||
|
|
||||||
|
def __init__(self, channel_name: str):
|
||||||
|
# Load credentials from environment variables
|
||||||
|
self.TMI_TOKEN = os.getenv("TWITCH_TEST_TOKEN")
|
||||||
|
self.CLIENT_ID = os.getenv("TWITCH_CLIENT_ID")
|
||||||
|
self.TARGET_CHANNEL = channel_name
|
||||||
|
|
||||||
|
# Pre-flight checks
|
||||||
|
if not all([self.TMI_TOKEN, self.CLIENT_ID, self.TARGET_CHANNEL]):
|
||||||
|
raise ValueError("Missing required environment variables. Ensure TWITCH_TEST_TOKEN, TWITCH_CLIENT_ID, and a channel are provided.")
|
||||||
|
|
||||||
|
print("--- Configuration ---")
|
||||||
|
print(f"CLIENT_ID: {self.CLIENT_ID[:4]}...{self.CLIENT_ID[-4:]}")
|
||||||
|
print(f"TOKEN: {self.TMI_TOKEN[:12]}...")
|
||||||
|
print(f"TARGET CHANNEL: {self.TARGET_CHANNEL}")
|
||||||
|
print("-----------------------")
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
token=f"oauth:{self.TMI_TOKEN}",
|
||||||
|
client_id=self.CLIENT_ID,
|
||||||
|
initial_channels=[self.TARGET_CHANNEL],
|
||||||
|
ssl=True
|
||||||
|
)
|
||||||
|
|
||||||
|
async def event_ready(self):
|
||||||
|
"""Called once when the bot goes online."""
|
||||||
|
print("\n--- Connection Successful ---")
|
||||||
|
print(f"Logged in as: {self.nick}")
|
||||||
|
print(f"Listening for messages in #{self.TARGET_CHANNEL}...")
|
||||||
|
print("---------------------------\n")
|
||||||
|
|
||||||
|
async def event_message(self, message):
|
||||||
|
"""Runs every time a message is sent in chat."""
|
||||||
|
if message.echo:
|
||||||
|
return
|
||||||
|
print(f"#{message.channel.name} | {message.author.name}: {message.content}")
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
"""Main function to run the test bot."""
|
||||||
|
# IMPORTANT: Replace 'ramforth' with the channel you want to test.
|
||||||
|
channel_to_test = "ramforth"
|
||||||
|
|
||||||
|
print(f"Attempting to connect to Twitch IRC for channel: {channel_to_test}")
|
||||||
|
try:
|
||||||
|
bot = TestBot(channel_name=channel_to_test)
|
||||||
|
await bot.start()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n--- AN ERROR OCCURRED ---")
|
||||||
|
print(f"Error: {e}")
|
||||||
|
print("Please check your credentials and network connection.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Reference in New Issue
Block a user