add emote lookup command

This commit is contained in:
lyx0 2021-10-22 17:59:45 +02:00
parent 257c61b650
commit 4682657025
3 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,47 @@
package ivr
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
log "github.com/sirupsen/logrus"
)
type emoteLookupResponse struct {
Channel string `json:"channel"`
EmoteCode string `json:"emotecode"`
Tier string `json:"tier"`
Emote string `json:"emote"`
Error string `json:"error"`
}
// ProfilePicture returns a link to a given users profilepicture.
func EmoteLookup(emote string) (string, error) {
baseUrl := "https://api.ivr.fi/twitch/emotes"
resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, emote))
if err != nil {
log.Error(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error(err)
}
var responseObject emoteLookupResponse
json.Unmarshal(body, &responseObject)
log.Info(responseObject.Tier)
// Emote not found
if responseObject.Error != "" {
return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil
} else {
return fmt.Sprintf("%s is a Tier %v emote to channel %s.", responseObject.EmoteCode, responseObject.Tier, responseObject.Channel), nil
}
}

View file

@ -0,0 +1,20 @@
package commands
import (
"fmt"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/api/ivr"
)
func EmoteLookup(channel string, emote string, nb *bot.Bot) {
reply, err := ivr.EmoteLookup(emote)
if err != nil {
nb.Send(channel, fmt.Sprint(err))
return
}
nb.Send(channel, reply)
}

View file

@ -79,6 +79,12 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
commands.EightBall(target, nb)
return
case "emote":
commands.EmoteLookup(target, cmdParams[1], nb)
case "emotelookup":
commands.EmoteLookup(target, cmdParams[1], nb)
case "ffzemotes":
commands.FfzEmotes(target, nb)
return