Mercurial > public > pacobot
comparison main.go @ 10:5c124578fed2
fix timer bug
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sat, 15 Mar 2025 17:03:53 +0000 |
parents | 228ab74e8321 |
children | aaf85ae1f942 |
comparison
equal
deleted
inserted
replaced
9:228ab74e8321 | 10:5c124578fed2 |
---|---|
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "log" | 4 "github.com/denniscmcom/pacobot/api" |
5 "net/http" | |
6 | |
7 "github.com/denniscmcom/pacobot/auth" | |
8 "github.com/denniscmcom/pacobot/bot" | |
9 "github.com/denniscmcom/pacobot/socket" | |
10 "github.com/gin-gonic/gin" | 5 "github.com/gin-gonic/gin" |
11 ) | 6 ) |
12 | |
13 type PageData struct { | |
14 Title string | |
15 } | |
16 | 7 |
17 func main() { | 8 func main() { |
18 gin.SetMode(gin.DebugMode) | 9 gin.SetMode(gin.DebugMode) |
19 | 10 |
20 r := gin.Default() | 11 r := gin.Default() |
21 r.LoadHTMLGlob("./www/*.html") | |
22 | 12 |
23 var authRes auth.AuthRes | 13 r.GET("/user", api.GetUserHandler) |
24 | 14 r.GET("/auth", api.AuthHandler) |
25 r.GET("/", func(c *gin.Context) { | 15 r.GET("/auth-validate", api.AuthValidateHandler) |
26 c.HTML(http.StatusOK, "index.html", gin.H{ | 16 r.GET("/auth-refresh", api.AuthRefreshHandler) |
27 "Title": "Index", | 17 r.GET("/auth-revoke", api.AuthRevokeHandler) |
28 }) | 18 r.GET("/twitch-auth-code-callback", api.TwitchCallbackHandler) |
29 }) | 19 r.GET("/connect", api.ConnectHandler) |
30 | |
31 r.GET("/user", func(c *gin.Context) { | |
32 userName := c.Query("username") | |
33 user := auth.GetUser(userName, authRes.AccessToken) | |
34 | |
35 c.JSON(http.StatusOK, gin.H{ | |
36 "message": user.Data[len(user.Data)-1].Id, | |
37 }) | |
38 }) | |
39 | |
40 r.GET("/auth", func(c *gin.Context) { | |
41 authUrl := auth.GetAuthUrl() | |
42 | |
43 c.Redirect(http.StatusMovedPermanently, authUrl) | |
44 }) | |
45 | |
46 r.GET("/auth-validate", func(c *gin.Context) { | |
47 msg := "failed" | |
48 | |
49 if auth.IsAuthTokenValid(authRes.AccessToken) { | |
50 msg = "ok" | |
51 } | |
52 | |
53 c.JSON(http.StatusOK, gin.H{ | |
54 "message": msg, | |
55 }) | |
56 }) | |
57 | |
58 r.GET("/auth-refresh", func(c *gin.Context) { | |
59 authRes = auth.RefreshAuthToken(authRes.AccessToken, authRes.RefreshToken) | |
60 | |
61 c.JSON(http.StatusOK, gin.H{ | |
62 "message": "ok", | |
63 }) | |
64 }) | |
65 | |
66 r.GET("/auth-revoke", func(c *gin.Context) { | |
67 auth.RevokeAuthToken(authRes.AccessToken) | |
68 | |
69 c.JSON(http.StatusOK, gin.H{ | |
70 "message": "ok", | |
71 }) | |
72 }) | |
73 | |
74 r.GET("/twitch-auth-code-callback", func(c *gin.Context) { | |
75 authCode := c.Query("code") | |
76 authRes = auth.GetAuthToken(authCode) | |
77 | |
78 c.Redirect(http.StatusMovedPermanently, "/") | |
79 }) | |
80 | |
81 r.GET("/connect", func(c *gin.Context) { | |
82 go socket.Connect(authRes.AccessToken) | |
83 | |
84 c.Redirect(http.StatusMovedPermanently, "/") | |
85 }) | |
86 | |
87 r.POST("/timer", func(c *gin.Context) { | |
88 form := c.Request.PostForm | |
89 log.Println(form) | |
90 timesec := form.Get("tiempo-oculto") | |
91 log.Println(timesec) | |
92 args := []string{"timer", timesec} | |
93 bot.HandleCmd(args) | |
94 }) | |
95 | 20 |
96 r.Run() | 21 r.Run() |
97 } | 22 } |