changeset 9:228ab74e8321

Add index.html
author Dennis C. M. <dennis@denniscm.com>
date Thu, 13 Mar 2025 18:27:25 +0000
parents e9df3bb010f4
children 5c124578fed2
files README.md main.go www/index.html
diffstat 3 files changed, 153 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Thu Mar 13 17:41:42 2025 +0000
+++ b/README.md	Thu Mar 13 18:27:25 2025 +0000
@@ -1,1 +1,13 @@
 # pacobot
+
+## Instructions
+
+### Create a `.config.json` file with the following fields.
+
+```json
+{
+    "client_id": "",
+    "client_secret": "",
+    "broadcaster_user_id": ""
+}
+```
--- a/main.go	Thu Mar 13 17:41:42 2025 +0000
+++ b/main.go	Thu Mar 13 18:27:25 2025 +0000
@@ -1,35 +1,44 @@
 package main
 
 import (
+	"log"
 	"net/http"
 
-	"github.com/denniscmcom/pacobot/cmd"
+	"github.com/denniscmcom/pacobot/auth"
+	"github.com/denniscmcom/pacobot/bot"
+	"github.com/denniscmcom/pacobot/socket"
 	"github.com/gin-gonic/gin"
 )
 
+type PageData struct {
+	Title string
+}
+
 func main() {
 	gin.SetMode(gin.DebugMode)
-	r := gin.Default()
 
-	var authRes cmd.AuthRes
+	r := gin.Default()
+	r.LoadHTMLGlob("./www/*.html")
+
+	var authRes auth.AuthRes
 
 	r.GET("/", func(c *gin.Context) {
-		c.JSON(http.StatusOK, gin.H{
-			"message": "Hello world",
+		c.HTML(http.StatusOK, "index.html", gin.H{
+			"Title": "Index",
 		})
 	})
 
-	// TODO: Pass username in parameters
-	r.GET("/id", func(c *gin.Context) {
-		cmd.GetBroadcasterUserId("denniscmartin", authRes.AccessToken)
+	r.GET("/user", func(c *gin.Context) {
+		userName := c.Query("username")
+		user := auth.GetUser(userName, authRes.AccessToken)
 
 		c.JSON(http.StatusOK, gin.H{
-			"message": "ok",
+			"message": user.Data[len(user.Data)-1].Id,
 		})
 	})
 
 	r.GET("/auth", func(c *gin.Context) {
-		authUrl := cmd.GetAuthUrl()
+		authUrl := auth.GetAuthUrl()
 
 		c.Redirect(http.StatusMovedPermanently, authUrl)
 	})
@@ -37,7 +46,7 @@
 	r.GET("/auth-validate", func(c *gin.Context) {
 		msg := "failed"
 
-		if cmd.IsAuthTokenValid(authRes.AccessToken) {
+		if auth.IsAuthTokenValid(authRes.AccessToken) {
 			msg = "ok"
 		}
 
@@ -47,7 +56,7 @@
 	})
 
 	r.GET("/auth-refresh", func(c *gin.Context) {
-		authRes = cmd.RefreshAuthToken(authRes.AccessToken, authRes.RefreshToken)
+		authRes = auth.RefreshAuthToken(authRes.AccessToken, authRes.RefreshToken)
 
 		c.JSON(http.StatusOK, gin.H{
 			"message": "ok",
@@ -55,7 +64,7 @@
 	})
 
 	r.GET("/auth-revoke", func(c *gin.Context) {
-		cmd.RevokeAuthToken(authRes.AccessToken)
+		auth.RevokeAuthToken(authRes.AccessToken)
 
 		c.JSON(http.StatusOK, gin.H{
 			"message": "ok",
@@ -64,19 +73,24 @@
 
 	r.GET("/twitch-auth-code-callback", func(c *gin.Context) {
 		authCode := c.Query("code")
-		authRes = cmd.GetAuthToken(authCode)
+		authRes = auth.GetAuthToken(authCode)
 
-		c.JSON(http.StatusOK, gin.H{
-			"message": "ok",
-		})
+		c.Redirect(http.StatusMovedPermanently, "/")
 	})
 
 	r.GET("/connect", func(c *gin.Context) {
-		go cmd.ConnSocket(authRes.AccessToken)
+		go socket.Connect(authRes.AccessToken)
+
+		c.Redirect(http.StatusMovedPermanently, "/")
+	})
 
-		c.JSON(http.StatusOK, gin.H{
-			"message": "ok",
-		})
+	r.POST("/timer", func(c *gin.Context) {
+		form := c.Request.PostForm
+		log.Println(form)
+		timesec := form.Get("tiempo-oculto")
+		log.Println(timesec)
+		args := []string{"timer", timesec}
+		bot.HandleCmd(args)
 	})
 
 	r.Run()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/index.html	Thu Mar 13 18:27:25 2025 +0000
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="es">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Redirección con Gin</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            background-color: #f0f0f0;
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            height: 100vh;
+            margin: 0;
+        }
+
+        .container {
+            text-align: center;
+            background-color: white;
+            padding: 20px;
+            border-radius: 8px;
+            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
+        }
+
+        h1 {
+            margin-bottom: 20px;
+        }
+
+        .btn {
+            background-color: #4CAF50;
+            color: white;
+            padding: 10px 20px;
+            margin: 10px;
+            border: none;
+            border-radius: 5px;
+            cursor: pointer;
+            font-size: 16px;
+            transition: background-color 0.3s ease;
+        }
+
+        .btn:hover {
+            background-color: #45a049;
+        }
+
+        #tiempo-mostrar {
+            font-size: 20px;
+            margin-top: 10px;
+        }
+    </style>
+</head>
+
+<body>
+    <div class="container">
+        <h1>Minutos del timer</h1>
+        <div>
+            <button id="decrementar-btn" class="btn">-</button>
+            <span id="tiempo-mostrar">0</span>
+            <button id="incrementar-btn" class="btn">+</button>
+        </div>
+        <br>
+        <form action="/timer" method="POST" id="form-timer">
+            <input type="hidden" id="tiempo-oculto" name="time" value="0">
+            <br>
+            <button type="button" id="btn-auth" class="btn">Ir a Auth</button>
+            <button type="submit" class="btn">Ir a Connect</button>
+        </form>
+    </div>
+
+    <script>
+        const disminuirBtn = document.getElementById('decrementar-btn');
+        const aumentarBtn = document.getElementById('incrementar-btn');
+        const mostrarTiempo = document.getElementById('tiempo-mostrar');
+        const tiempoInput = document.getElementById('tiempo-oculto');
+        const formTimer = document.getElementById('form-timer');
+        const btnAuth = document.getElementById('btn-auth');
+
+        let tiempo = 0;
+
+        disminuirBtn.addEventListener('click', function () {
+            if (tiempo > 0) {
+                tiempo--;
+                mostrarTiempo.textContent = tiempo;
+                tiempoInput.value = tiempo;
+            }
+        });
+
+        aumentarBtn.addEventListener('click', function () {
+            tiempo++;
+            mostrarTiempo.textContent = tiempo;
+            tiempoInput.value = tiempo;
+        });
+
+        formTimer.addEventListener('submit', function () {
+            tiempoInput.value = tiempo * 60;
+        });
+
+        btnAuth.addEventListener('click', function () {
+            window.location.href = '/auth';
+        });
+    </script>
+
+</body>
+
+</html>
\ No newline at end of file