Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for ffz animated emote urls #455

Merged
merged 3 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Dev: Only upload Ubuntu binaries to releases. (#454)
- Added support for FrankerFaceZ animated emote links. (#455)
brian6932 marked this conversation as resolved.
Show resolved Hide resolved

## 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