Skip to content

Commit

Permalink
fix: added sub_label to msg
Browse files Browse the repository at this point in the history
  • Loading branch information
OldTyT authored Nov 11, 2024
1 parent 5daa06c commit 19880b8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/frigate/frigate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type EventsStruct []struct {
PlusID interface{} `json:"plus_id"`
RetainIndefinitely bool `json:"retain_indefinitely"`
StartTime float64 `json:"start_time"`
SubLabel interface{} `json:"sub_label"`
SubLabel []any `json:"sub_label"`
Thumbnail string `json:"thumbnail"`
TopScore interface{} `json:"top_score"`
Zones []any `json:"zones"`
Expand All @@ -65,7 +65,7 @@ type EventStruct struct {
PlusID interface{} `json:"plus_id"`
RetainIndefinitely bool `json:"retain_indefinitely"`
StartTime float64 `json:"start_time"`
SubLabel interface{} `json:"sub_label"`
SubLabel []any `json:"sub_label"`
Thumbnail string `json:"thumbnail"`
TopScore interface{} `json:"top_score"`
Zones []any `json:"zones"`
Expand All @@ -90,12 +90,15 @@ func NormalizeTagText(text string) string {
return strings.Join(NormalizedText, "")
}

func GETZones(Zones []any) []string {
var my_zones []string
for _, zone := range Zones {
my_zones = append(my_zones, NormalizeTagText(zone.(string)))
func GetTagList(Tags []any) []string {
var my_tags []string
for _, zone := range Tags {
fmt.Println(zone)
if zone != nil {
my_tags = append(my_tags, NormalizeTagText(zone.(string)))
}
}
return my_zones
return my_tags
}

func ErrorSend(TextError string, bot *tgbotapi.BotAPI, EventID string) {
Expand Down Expand Up @@ -224,7 +227,7 @@ func SendMessageEvent(FrigateEvent EventStruct, bot *tgbotapi.BotAPI) {
text += "┣*Camera*\n┗ #" + NormalizeTagText(FrigateEvent.Camera) + "\n"
text += "┣*Label*\n┗ #" + NormalizeTagText(FrigateEvent.Label) + "\n"
if FrigateEvent.SubLabel != nil {
text += "┣*SubLabel*\n┗ #" + NormalizeTagText(fmt.Sprintf("%v", FrigateEvent.SubLabel)) + "\n"
text += "┣*SubLabel*\n┗ #" + strings.Join(GetTagList(Events[Event].SubLabel), ", #") + "\n"

Check failure on line 230 in internal/frigate/frigate.go

View workflow job for this annotation

GitHub Actions / Lint check

invalid argument: index Event (variable of type EventStruct) must be integer

Check failure on line 230 in internal/frigate/frigate.go

View workflow job for this annotation

GitHub Actions / Lint check

invalid argument: index Event (variable of type EventStruct) must be integer
}
t_start := time.Unix(int64(FrigateEvent.StartTime), 0)
text += fmt.Sprintf("┣*Start time*\n┗ `%s", t_start) + "`\n"
Expand All @@ -236,9 +239,9 @@ func SendMessageEvent(FrigateEvent EventStruct, bot *tgbotapi.BotAPI) {
}
text += fmt.Sprintf("┣*Top score*\n┗ `%f", (FrigateEvent.Data.TopScore*100)) + "%`\n"
text += "┣*Event id*\n┗ `" + FrigateEvent.ID + "`\n"
text += "┣*Zones*\n┗ #" + strings.Join(GETZones(FrigateEvent.Zones), ", #") + "\n"
text += "┣*Zones*\n┗ #" + strings.Join(GetTagList(FrigateEvent.Zones), ", #") + "\n"
text += "*URLs*\n"
text += "┣[Events](" + conf.FrigateExternalURL + "/events?cameras=" + FrigateEvent.Camera + "&labels=" + FrigateEvent.Label + "&zones=" + strings.Join(GETZones(FrigateEvent.Zones), ",") + ")\n"
text += "┣[Events](" + conf.FrigateExternalURL + "/events?cameras=" + FrigateEvent.Camera + "&labels=" + FrigateEvent.Label + "&zones=" + strings.Join(GetTagList(FrigateEvent.Zones), ",") + ")\n"
text += "┣[General](" + conf.FrigateExternalURL + ")\n"
text += "┗[Source clip](" + conf.FrigateExternalURL + "/api/events/" + FrigateEvent.ID + "/clip.mp4)\n"

Expand Down

0 comments on commit 19880b8

Please sign in to comment.