summaryrefslogtreecommitdiff
path: root/internal/emotes.go
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-10-14 22:34:59 +0500
committerilotterytea <iltsu@alright.party>2025-10-14 22:34:59 +0500
commit8b9188b2c0ac192150201c511944d68862275f69 (patch)
tree67dae6db7a2f54aa2afd45e92be802b35e2b236a /internal/emotes.go
parente4c92920e627b7ad17f51637f52ca36e8468341f (diff)
feat: get bttv emotes
Diffstat (limited to 'internal/emotes.go')
-rw-r--r--internal/emotes.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/emotes.go b/internal/emotes.go
new file mode 100644
index 0000000..d85eca2
--- /dev/null
+++ b/internal/emotes.go
@@ -0,0 +1,47 @@
+package stats
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/http"
+)
+
+type Emote struct {
+ Id string
+ Name string
+}
+
+func GetBetterTTVEmotes(channelId string) (emotes []Emote, err error) {
+ resp, err := http.Get(fmt.Sprintf("https://api.betterttv.net/3/cached/users/twitch/%s", channelId))
+ if err != nil {
+ return
+ }
+ defer resp.Body.Close()
+
+ var data map[string]any
+ if err = json.NewDecoder(resp.Body).Decode(&data); err != nil {
+ return
+ }
+
+ if msg, ok := data["message"]; ok {
+ err = fmt.Errorf("error while searching user: %s", msg)
+ return
+ }
+
+ ejson := []map[string]any{}
+ for _, v := range data["channelEmotes"].([]any) {
+ ejson = append(ejson, v.(map[string]any))
+ }
+ for _, v := range data["sharedEmotes"].([]any) {
+ ejson = append(ejson, v.(map[string]any))
+ }
+
+ for _, e := range ejson {
+ emotes = append(emotes, Emote{
+ Id: e["id"].(string),
+ Name: e["code"].(string),
+ })
+ }
+
+ return
+}