mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add profilepicture command
This commit is contained in:
parent
590e7b866d
commit
e7e7bc2793
3 changed files with 76 additions and 0 deletions
44
pkg/api/ivr/profilepicture.go
Normal file
44
pkg/api/ivr/profilepicture.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package ivr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://api.ivr.fi
|
||||||
|
type pfpApiResponse struct {
|
||||||
|
Logo string `json:"logo"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
baseUrl = "https://api.ivr.fi/twitch/resolve"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ProfilePicture(username string) (string, error) {
|
||||||
|
resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, username))
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseObject pfpApiResponse
|
||||||
|
json.Unmarshal(body, &responseObject)
|
||||||
|
|
||||||
|
// User not found
|
||||||
|
if responseObject.Error != "" {
|
||||||
|
return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf(responseObject.Logo), nil
|
||||||
|
}
|
||||||
|
}
|
18
pkg/commands/profilepicture.go
Normal file
18
pkg/commands/profilepicture.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
|
"github.com/lyx0/nourybot/pkg/api/ivr"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ProfilePicture(channel string, target string, client *twitch.Client) {
|
||||||
|
reply, err := ivr.ProfilePicture(target)
|
||||||
|
if err != nil {
|
||||||
|
client.Say(channel, fmt.Sprint(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Say(channel, reply)
|
||||||
|
}
|
|
@ -154,6 +154,20 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
|
||||||
case "pingme":
|
case "pingme":
|
||||||
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
|
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
|
||||||
return
|
return
|
||||||
|
case "profilepicture":
|
||||||
|
if msgLen == 1 {
|
||||||
|
twitchClient.Say(message.Channel, "Usage: ()profilepicture [user]")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
|
||||||
|
return
|
||||||
|
case "pfp":
|
||||||
|
if msgLen == 1 {
|
||||||
|
twitchClient.Say(message.Channel, "Usage: ()pfp [user]")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
commands.ProfilePicture(message.Channel, cmdParams[1], twitchClient)
|
||||||
|
return
|
||||||
case "pyramid":
|
case "pyramid":
|
||||||
if msgLen != 3 {
|
if msgLen != 3 {
|
||||||
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")
|
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")
|
||||||
|
|
Loading…
Reference in a new issue