ID scoped to thread and dont out of bounds except
parent
0d3910829d
commit
02331752fe
11
message.go
11
message.go
|
|
@ -2,8 +2,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -99,8 +99,13 @@ func ParseSlack(b []byte) (Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Event.Bot.Name != "" {
|
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{
|
return Message{
|
||||||
ID: strconv.FormatUint(s.TS, 10),
|
ID: fmt.Sprintf("%s/%v", s.Event.ID, s.TS),
|
||||||
TS: s.TS,
|
TS: s.TS,
|
||||||
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ID, ".", "")),
|
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ID, ".", "")),
|
||||||
Channel: s.Event.Channel,
|
Channel: s.Event.Channel,
|
||||||
|
|
@ -113,7 +118,7 @@ func ParseSlack(b []byte) (Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Message{
|
return Message{
|
||||||
ID: strconv.FormatUint(s.TS, 10),
|
ID: fmt.Sprintf("%s/%v", s.Event.ParentID, s.TS),
|
||||||
TS: s.TS,
|
TS: s.TS,
|
||||||
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ParentID, ".", "")),
|
Source: fmt.Sprintf(`https://renderinc.slack.com/archives/%s/p%s`, s.Event.Channel, strings.ReplaceAll(s.Event.ParentID, ".", "")),
|
||||||
Channel: s.Event.Channel,
|
Channel: s.Event.Channel,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func TestParseSlackTestdata(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
message: Message{
|
message: Message{
|
||||||
ID: "1712930706",
|
ID: "1712927439.728409/1712930706",
|
||||||
TS: 1712930706,
|
TS: 1712930706,
|
||||||
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
|
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
|
||||||
Channel: "C06U1DDBBU4",
|
Channel: "C06U1DDBBU4",
|
||||||
|
|
@ -68,7 +68,7 @@ func TestParseSlackTestdata(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
message: Message{
|
message: Message{
|
||||||
ID: "1712927439",
|
ID: "1712927439.728409/1712927439",
|
||||||
TS: 1712927439,
|
TS: 1712927439,
|
||||||
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
|
Source: "https://renderinc.slack.com/archives/C06U1DDBBU4/p1712927439728409",
|
||||||
Channel: "C06U1DDBBU4",
|
Channel: "C06U1DDBBU4",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue