mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add emote lookup command
This commit is contained in:
parent
257c61b650
commit
4682657025
47
pkg/api/ivr/emoteloookup.go
Normal file
47
pkg/api/ivr/emoteloookup.go
Normal 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
|
||||
}
|
||||
}
|
20
pkg/commands/emotelookup.go
Normal file
20
pkg/commands/emotelookup.go
Normal 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)
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue