From d4d90c317cc030efb29c6b6a362a7190b0899c38 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Wed, 22 Jan 2025 20:36:29 -0300 Subject: [PATCH] feat(parser): Add chatty support for badges --- cmd/vanity-tester-backend/parser.go | 48 +++++++++++++++++++---------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/cmd/vanity-tester-backend/parser.go b/cmd/vanity-tester-backend/parser.go index 66e91f6..5d6d6e1 100644 --- a/cmd/vanity-tester-backend/parser.go +++ b/cmd/vanity-tester-backend/parser.go @@ -32,7 +32,13 @@ type _FrankerFz struct { } // TODO -type _Chatty struct{} +type _Chatty struct { + Badges []struct { + Name string `json:"name"` + Url string `json:"url"` + Users []string `json:"users"` + } `json:"badges"` +} type _DankChat struct { Badges []struct { @@ -129,7 +135,7 @@ func formatFfz(format *Format) { } } -// Done +// TODO func formatBttv(format *Format) { defer format.wg.Done() data := &Bttv{} @@ -209,26 +215,31 @@ func formatPurpleTv(format *Format) { }) } -// TODO +// TODO: Replace the data from the Chatty struct in place to use less memory. func formatChatty(format *Format) { defer format.wg.Done() data := &Chatty{} + newData := Chatty{} data.getBadges() - // var users []string - // for _, user := range data.Users { - // users = append(users, user.UserName) - // } + // Removes the elements containing "ffz" or "ffzap" in the ID. + for _, element := range *data { + if (element.ID != "ffz") && (element.ID != "ffzap") { + newData = append(newData, element) + } + } - // format.PurpleTv.Badges = append(format.PurpleTv.Badges, struct { - // Name string `json:"name"` - // Url string `json:"url"` - // Users []string `json:"users"` - // }{ - // Name: "PurpleTV Supporter", - // Url: data.DefaultBadgeURL, - // Users: users, - // }) + for _, badge := range newData { + format.Chatty.Badges = append(format.Chatty.Badges, struct { + Name string `json:"name"` + Url string `json:"url"` + Users []string `json:"users"` + }{ + Name: badge.MetaTitle, + Url: badge.ImageURL4, + Users: badge.Usernames, + }) + } } func formatSevenTvBadges() string { @@ -278,6 +289,9 @@ func formatAllBadges() string { format.wg.Wait() - json, _ := json.Marshal(format) + json, err := json.Marshal(format) + if err != nil { + logger.Error().Msg("Failed to json.Marshal badges: " + err.Error()) + } return string(json) }