ID scoped to thread and dont out of bounds except

main
Bel LaPointe 2024-04-12 10:05:25 -06:00
parent 0d3910829d
commit 02331752fe
2 changed files with 10 additions and 5 deletions

View File

@ -2,8 +2,8 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
)
@ -99,8 +99,13 @@ func ParseSlack(b []byte) (Message, error) {
}
if s.Event.Bot.Name != "" {
if len(s.Event.Attachments) == 0 {
return Message{}, errors.New("bot message has no attachments")
} else if !strings.Contains(s.Event.Attachments[0].Title, ": Firing: ") {
return Message{}, errors.New("bot message attachment is not Firing")
}
return Message{
ID: strconv.FormatUint(s.TS, 10),
ID: fmt.Sprintf("%s/%v", s.Event.ID, s.TS),
TS: s.TS,
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ID, ".", "")),
Channel: s.Event.Channel,
@ -113,7 +118,7 @@ func ParseSlack(b []byte) (Message, error) {
}
return Message{
ID: strconv.FormatUint(s.TS, 10),
ID: fmt.Sprintf("%s/%v", s.Event.ParentID, s.TS),
TS: s.TS,
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ParentID, ".", "")),
Channel: s.Event.Channel,

View File

@ -34,7 +34,7 @@ func TestParseSlackTestdata(t *testing.T) {
},
},
message: Message{
ID: "1712930706",
ID: "1712927439.728409/1712930706",
TS: 1712930706,
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
Channel: "C06U1DDBBU4",
@ -68,7 +68,7 @@ func TestParseSlackTestdata(t *testing.T) {
},
},
message: Message{
ID: "1712927439",
ID: "1712927439.728409/1712927439",
TS: 1712927439,
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
Channel: "C06U1DDBBU4",