Fix cookie refresh and reconnection bugs

This commit is contained in:
Salastil
2025-11-03 22:28:47 -05:00
parent 0d92a3aeb0
commit 04f3ef2500
4 changed files with 115 additions and 55 deletions

19
main.go
View File

@@ -5,7 +5,6 @@ import (
"os"
"os/signal"
"syscall"
"time"
"local/sneedchatbridge/config"
"local/sneedchatbridge/cookie"
@@ -29,7 +28,7 @@ func main() {
log.Printf("Using Sneedchat room ID: %d", cfg.SneedchatRoomID)
log.Printf("Bridge username: %s", cfg.BridgeUsername)
// Cookie service
// Cookie service (now handles its own refresh loop)
cookieSvc, err := cookie.NewCookieRefreshService(cfg.BridgeUsername, cfg.BridgePassword, "kiwifarms.st")
if err != nil {
log.Fatalf("Failed to create cookie service: %v", err)
@@ -53,20 +52,6 @@ func main() {
}
log.Println("🌉 Discord-Sneedchat Bridge started successfully")
// Background 4h refresh loop
go func() {
t := time.NewTicker(4 * time.Hour)
defer t.Stop()
for range t.C {
log.Println("🔄 Starting automatic cookie refresh")
if _, err := cookieSvc.FetchFreshCookie(); err != nil {
log.Printf("⚠️ Cookie refresh failed: %v", err)
continue
}
log.Println("✅ Cookie refresh completed")
}
}()
// Connect to Sneedchat
go func() {
if err := sneedClient.Connect(); err != nil {
@@ -84,4 +69,4 @@ func main() {
sneedClient.Disconnect()
cookieSvc.Stop()
log.Println("Bridge stopped successfully")
}
}