]> git.openfl.eu Git - twitch-chat.git/commitdiff
panic on bad pingpong, and append when recording chat
authorFl_GUI <flor.guilini@hotmail.com>
Mon, 24 Jun 2024 15:39:28 +0000 (17:39 +0200)
committerFl_GUI <flor.guilini@hotmail.com>
Mon, 24 Jun 2024 15:40:06 +0000 (17:40 +0200)
twitch/core/pingpong.go
x/rechat/main.go

index 6fbd5a6d1c23409c1b0a36c3dc6bf8ce100b9244..68e42657fb702bbe37e906cbb73bf934eea34e95 100644 (file)
@@ -1,6 +1,7 @@
 package core
 
 import (
+       "errors"
        "fmt"
        "time"
 
@@ -14,7 +15,10 @@ func (c *Conn) PingPong(msgs <-chan messages.Message) <-chan messages.Message {
        var pingMessage string
        // send ping
        go func() {
-               for _ = range time.Tick(time.Minute * 4) {
+               for _ = range time.Tick(time.Minute * 2) {
+                       if pingMessage != "" {
+                               panic(errors.New("Ping message ignored by twitch."))
+                       }
                        pingMessage = randomString(10, AlphaNum)
                        c.WriteMessage(messages.Ping(pingMessage))
                }
@@ -30,6 +34,7 @@ func (c *Conn) PingPong(msgs <-chan messages.Message) <-chan messages.Message {
                                if pongText != pingMessage {
                                        fmt.Fprintf(DebugLogger, "Error: send PING %s but received a PONG %s\n", pingMessage, pongText)
                                }
+                               pingMessage = ""
                        } else {
                                res <- msg
                        }
index d522e13cdacb8b3e9d159a783861008677f57f5a..7e4b068cbc2a856b509be4a58a1b106da1cba405 100644 (file)
@@ -21,7 +21,7 @@ func openFile() (io.WriteCloser, error) {
        if fileName == "" {
                return os.Stdout, nil
        }
-       return os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fs.ModePerm)
+       return os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, fs.ModePerm)
 }
 
 func openChat() (conn *core.Conn, msgs <-chan messages.Message, err error) {