diff --git a/CHANGELOG.md b/CHANGELOG.md index c6256922..504995a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Minor: Added support for FrankerFaceZ animated emote links. (#455) - Dev: Only upload Ubuntu binaries to releases. (#454) ## 2.0.0 diff --git a/internal/resolvers/frankerfacez/emote_loader.go b/internal/resolvers/frankerfacez/emote_loader.go index 4467f6d1..524659b9 100644 --- a/internal/resolvers/frankerfacez/emote_loader.go +++ b/internal/resolvers/frankerfacez/emote_loader.go @@ -21,33 +21,40 @@ var ( } ) -/* Example JSON data generated from https://api.frankerfacez.com/v1/emote/131001 2020-11-18 +/* Example JSON data generated from https://api.frankerfacez.com/v1/emote/720810 2023-3-25 { "emote": { - "created_at": "2016-09-25T12:30:30.313Z", - "css": null, - "height": 21, + "id": 720810, + "name": "miniDink", + "height": 19, + "width": 23, + "public": true, "hidden": false, - "id": 131001, - "last_updated": "2016-09-25T14:25:01.408Z", - "margins": null, "modifier": false, - "name": "pajaE", + "modifier_flags": 0, "offset": null, + "margins": null, + "css": null, "owner": { - "_id": 63119, - "display_name": "pajaSWA", - "name": "pajaswa" + "_id": 578242, + "name": "soda_", + "display_name": "soda_" }, - "public": true, - "status": 1, + "artist": null, "urls": { - "1": "//cdn.frankerfacez.com/emote/131001/1", - "2": "//cdn.frankerfacez.com/emote/131001/2", - "4": "//cdn.frankerfacez.com/emote/131001/4" + "1": "https://cdn.frankerfacez.com/emote/720810/1", + "2": "https://cdn.frankerfacez.com/emote/720810/2", + "4": "https://cdn.frankerfacez.com/emote/720810/4" + }, + "animated": { + "1": "https://cdn.frankerfacez.com/emote/720810/animated/1", + "2": "https://cdn.frankerfacez.com/emote/720810/animated/2", + "4": "https://cdn.frankerfacez.com/emote/720810/animated/4" }, - "usage_count": 9, - "width": 32 + "status": 1, + "usage_count": 3, + "created_at": "2023-03-05T13:13:42.963Z", + "last_updated": "2023-03-05T13:52:07.225Z" } } */ @@ -76,6 +83,12 @@ type EmoteAPIResponse struct { Size2 string `json:"2"` Size4 string `json:"4"` } `json:"urls"` + + AnimatedURLs *struct { + Size1 string `json:"1"` + Size2 string `json:"2"` + Size4 string `json:"4"` + } `json:"animated,omitempty"` } type TooltipData struct { @@ -102,7 +115,6 @@ func (l *EmoteLoader) Load(ctx context.Context, emoteID string, r *http.Request) "emoteID", emoteID, ) apiURL := l.buildURL(emoteID) - thumbnailURL := fmt.Sprintf(thumbnailFormat, emoteID) // Create FrankerFaceZ API request resp, err := resolver.RequestGET(ctx, apiURL) @@ -126,6 +138,13 @@ func (l *EmoteLoader) Load(ctx context.Context, emoteID string, r *http.Request) } jsonResponse := temp.Emote + var thumbnailURL string + if jsonResponse.AnimatedURLs == nil { + thumbnailURL = fmt.Sprintf(thumbnailFormat, emoteID) + } else { + thumbnailURL = fmt.Sprintf(animatedThumbnailFormat, emoteID) + } + // Build tooltip data from the API response data := TooltipData{ Code: jsonResponse.Name, diff --git a/internal/resolvers/frankerfacez/initialize.go b/internal/resolvers/frankerfacez/initialize.go index 5494d29f..c93ed9a0 100644 --- a/internal/resolvers/frankerfacez/initialize.go +++ b/internal/resolvers/frankerfacez/initialize.go @@ -13,7 +13,8 @@ import ( ) const ( - thumbnailFormat = "https://cdn.frankerfacez.com/emoticon/%s/4" + thumbnailFormat = "https://cdn.frankerfacez.com/emoticon/%s/4" + animatedThumbnailFormat = "https://cdn.frankerfacez.com/emoticon/%s/animated/4" tooltipTemplate = `