0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 05:02:58 -05:00

Emotes should be handled on the client side

This commit is contained in:
dragongoose 2023-07-03 14:48:16 -04:00
parent c0103c4976
commit 4a333eed57
No known key found for this signature in database
GPG key ID: 50DB99B921579009
4 changed files with 0 additions and 138 deletions

View file

@ -1,61 +0,0 @@
package twitch
import (
"fmt"
"safetwitch-backend/extractor/structs"
)
type Emote struct {
Name string `json:"name"`
Urls map[string]string `json:"urls"`
}
func ParseFfzEmotes(emotes structs.FfzData) []Emote {
setId := emotes.Room.Set
sets := emotes.Sets[fmt.Sprint(setId)]
parsedEmotes := []Emote{}
for _, emote := range sets.Emoticons {
parsedEmotes = append(parsedEmotes, Emote{
Name: emote.Name,
Urls: emote.Urls,
})
}
return parsedEmotes
}
func generateBttvEmotesUrls(id string) map[string]string {
url := "https://cdn.betterttv.net/emote/"
createdUrls := map[string]string{}
for i := 1; i < 4; i++ {
createdUrls[fmt.Sprint(i)] = url + id + "/" + fmt.Sprint(i) + "x"
}
return createdUrls
}
func ParseBttvEmotes(emoteData []structs.BttvEmoteData) []Emote {
parsedEmotes := []Emote{}
for _, emote := range emoteData {
parsedEmotes = append(parsedEmotes, Emote{
Name: emote.Code,
Urls: generateBttvEmotesUrls(emote.Id),
})
}
return parsedEmotes
}
func ParseBttvGlobalEmotes(emoteData []structs.BttvGlobalEmoteData) []Emote {
parsedEmotes := []Emote{}
for _, emote := range emoteData {
parsedEmotes = append(parsedEmotes, Emote{
Name: emote.Code,
Urls: generateBttvEmotesUrls(emote.Id),
})
}
return parsedEmotes
}

View file

@ -562,55 +562,3 @@ func GetStreamerId(channelName string) (string, error) {
return "", errors.New("could not find user")
}
}
func GetEmotes(channelName string) ([]Emote, error) {
ffzUrl := "https://api.frankerfacez.com/v1/room/" + channelName
body, err := getResponse(ffzUrl)
if err != nil {
return []Emote{}, err
}
ffzEmotes := &structs.FfzData{}
err = json.Unmarshal(body, ffzEmotes)
if err != nil {
return []Emote{}, err
}
emotes := ParseFfzEmotes(*ffzEmotes)
id, err := GetStreamerId(channelName)
if err != nil {
return []Emote{}, err
}
bttvGlobalUrl := "https://api.betterttv.net/3/cached/emotes/global"
bttvChannelUrl := "https://api.betterttv.net/3/cached/users/twitch/" + id
body, err = getResponse(bttvGlobalUrl)
if err != nil {
return []Emote{}, err
}
bttvGlobalEmotes := &[]structs.BttvGlobalEmoteData{}
err = json.Unmarshal(body, bttvGlobalEmotes)
if err != nil {
return []Emote{}, err
}
emotes = append(emotes, ParseBttvGlobalEmotes(*bttvGlobalEmotes)...)
body, err = getResponse(bttvChannelUrl)
if err != nil {
return []Emote{}, err
}
bttvChannelEmotes := &[]structs.BttvEmoteData{}
emoteArray := gjson.Get(string(body), "channelEmotes").String()
err = json.Unmarshal([]byte(emoteArray), bttvChannelEmotes)
if err != nil {
return []Emote{}, err
}
emotes = append(emotes, ParseBttvEmotes(*bttvChannelEmotes)...)
return emotes, nil
}

View file

@ -1,23 +0,0 @@
package emotes
import (
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/twitch"
"github.com/gin-gonic/gin"
)
func Routes(route *gin.Engine) {
auth := route.Group("/api/emotes")
auth.GET("/:streamerName", func(context *gin.Context) {
streamer := context.Param("streamerName")
emotes, err := twitch.GetEmotes(streamer)
if err != nil {
context.Error(err)
return
}
context.JSON(200, extractor.FormatMessage(emotes, true))
})
}

View file

@ -3,7 +3,6 @@ package routes
import (
"safetwitch-backend/routes/api/badges"
"safetwitch-backend/routes/api/discover"
"safetwitch-backend/routes/api/emotes"
"safetwitch-backend/routes/api/search"
"safetwitch-backend/routes/api/users"
"safetwitch-backend/routes/proxy"
@ -17,7 +16,6 @@ func SetRoutes(router *gin.Engine) {
discover.Routes(router)
badges.Routes(router)
search.Routes(router)
emotes.Routes(router)
proxy.Routes(router)
root.Routes(router)