From e5994ae0f130cc60dfa8100a117c4ce81a535237 Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 23 Mar 2024 00:11:16 -0400 Subject: [PATCH] Fixed issue with reading webpage when getting chat info --- chat.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/chat.go b/chat.go index f06635c..40a31a5 100644 --- a/chat.go +++ b/chat.go @@ -53,13 +53,20 @@ func (c *Client) getChatInfo() (*ChatInfo, error) { defer resp.Body.Close() r := bufio.NewReader(resp.Body) - line, _, err := r.ReadLine() - var lineS string + //line, _, err := r.ReadLine() + lineS, err := r.ReadString('\n') + //var lineS string for err == nil { - lineS = string(line) + //lineS = string(line) if strings.Contains(lineS, "RumbleChat(") { start := strings.Index(lineS, "RumbleChat(") + len("RumbleChat(") + if start == -1 { + return nil, fmt.Errorf("error finding chat function in webpage") + } end := strings.Index(lineS[start:], ");") + if end == -1 { + return nil, fmt.Errorf("error finding end of chat function in webpage") + } argsS := strings.ReplaceAll(lineS[start:start+end], ", ", ",") argsS = strings.Replace(argsS, "[", "\"[", 1) n := strings.LastIndex(argsS, "]") @@ -76,7 +83,8 @@ func (c *Client) getChatInfo() (*ChatInfo, error) { } return &ChatInfo{info[0], info[1], channelID}, nil } - line, _, err = r.ReadLine() + //line, _, err = r.ReadLine() + lineS, err = r.ReadString('\n') } if err != nil { return nil, fmt.Errorf("error reading line from stream webpage: %v", err)