mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 11:20:08 -05:00
Emotes should be handled on the client side
This commit is contained in:
parent
c0103c4976
commit
4a333eed57
4 changed files with 0 additions and 138 deletions
|
@ -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
|
|
||||||
}
|
|
|
@ -562,55 +562,3 @@ func GetStreamerId(channelName string) (string, error) {
|
||||||
return "", errors.New("could not find user")
|
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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -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))
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ package routes
|
||||||
import (
|
import (
|
||||||
"safetwitch-backend/routes/api/badges"
|
"safetwitch-backend/routes/api/badges"
|
||||||
"safetwitch-backend/routes/api/discover"
|
"safetwitch-backend/routes/api/discover"
|
||||||
"safetwitch-backend/routes/api/emotes"
|
|
||||||
"safetwitch-backend/routes/api/search"
|
"safetwitch-backend/routes/api/search"
|
||||||
"safetwitch-backend/routes/api/users"
|
"safetwitch-backend/routes/api/users"
|
||||||
"safetwitch-backend/routes/proxy"
|
"safetwitch-backend/routes/proxy"
|
||||||
|
@ -17,7 +16,6 @@ func SetRoutes(router *gin.Engine) {
|
||||||
discover.Routes(router)
|
discover.Routes(router)
|
||||||
badges.Routes(router)
|
badges.Routes(router)
|
||||||
search.Routes(router)
|
search.Routes(router)
|
||||||
emotes.Routes(router)
|
|
||||||
|
|
||||||
proxy.Routes(router)
|
proxy.Routes(router)
|
||||||
root.Routes(router)
|
root.Routes(router)
|
||||||
|
|
Loading…
Reference in a new issue