Skip to content

Commit

Permalink
feat: Add support for ffz animated emote urls (#455)
Browse files Browse the repository at this point in the history
Co-authored-by: Kasia <zneix@zneix.eu>
  • Loading branch information
brian6932 and zneix authored Mar 26, 2023
1 parent 14e390e commit 13079e1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 38 additions & 19 deletions internal/resolvers/frankerfacez/emote_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
*/
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion internal/resolvers/frankerfacez/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<div style="text-align: left;">
<b>{{.Code}}</b><br>
Expand Down

0 comments on commit 13079e1

Please sign in to comment.