From ba26735378de1db1a47d80fd1a51b09bcc65f2cb Mon Sep 17 00:00:00 2001 From: tyler Date: Sat, 18 May 2024 12:41:13 -0400 Subject: [PATCH] Added message time to chat view --- chat.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/chat.go b/chat.go index d62c9f0..f09d32a 100644 --- a/chat.go +++ b/chat.go @@ -65,24 +65,6 @@ func (c *Client) getChatInfo() (*ChatInfo, error) { lineS, err := r.ReadString('\n') for err == nil { 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, "]") - //argsS = argsS[:n] + "]\"" + argsS[n+1:] - //c := csv.NewReader(strings.NewReader(argsS)) - //args, err := c.ReadAll() - //if err != nil { - // return nil, fmt.Errorf("error parsing csv: %v", err) - //} - //info := args[0] start := strings.Index(lineS, "RumbleChat(") + len("RumbleChat(") if start == -1 { return nil, fmt.Errorf("error finding chat function in webpage") @@ -398,6 +380,7 @@ type ChatView struct { IsFollower bool Rant int Text string + Time time.Time Type string Username string } @@ -463,6 +446,11 @@ func parseMessages(eventType string, messages []ChatEventMessage, users map[stri view.Rant = message.Rant.PriceCents } view.Text = message.Text + t, err := time.Parse(time.RFC3339, message.Time) + if err != nil { + return nil, fmt.Errorf("error parsing message time: %v", err) + } + view.Time = t view.Type = eventType view.Username = user.Username