add error responses

This commit is contained in:
lyx0 2021-10-17 17:48:05 +02:00
parent c22e4d73bd
commit 3432c112ac
3 changed files with 16 additions and 15 deletions

View file

@ -5,11 +5,16 @@ import (
"github.com/gempir/go-twitch-irc/v2" "github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api/aiden" "github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
) )
func Game(channel string, name string, client *twitch.Client) { func Game(channel string, name string, client *twitch.Client) {
game := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/game", name)) game, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/game", name))
if err != nil {
client.Say(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
reply := fmt.Sprintf("@%s was last seen playing: %s", name, game) reply := fmt.Sprintf("@%s was last seen playing: %s", name, game)
client.Say(channel, reply) client.Say(channel, reply)
} }

View file

@ -2,29 +2,20 @@ package commands
import ( import (
"fmt" "fmt"
"io/ioutil"
"net/http"
"github.com/gempir/go-twitch-irc/v2" "github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func Uptime(channel string, target string, client *twitch.Client) { func Uptime(channel string, name string, client *twitch.Client) {
resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/twitch/channel/%s/uptime", target))
resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/channel/%s/uptime", name))
if err != nil { if err != nil {
client.Say(channel, "Something went wrong FeelsBadMan") client.Say(channel, "Something went wrong FeelsBadMan")
log.Error(err) log.Error(err)
} }
defer resp.Body.Close() client.Say(channel, resp)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
client.Say(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
client.Say(channel, string(body))
} }

View file

@ -5,11 +5,16 @@ import (
"github.com/gempir/go-twitch-irc/v2" "github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api/aiden" "github.com/lyx0/nourybot/pkg/api/aiden"
log "github.com/sirupsen/logrus"
) )
func Weather(channel string, location string, client *twitch.Client) { func Weather(channel string, location string, client *twitch.Client) {
reply := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location)) reply, err := aiden.ApiCall(fmt.Sprintf("api/v1/misc/weather/%s", location))
if err != nil {
client.Say(channel, "Something went wrong FeelsBadMan")
log.Error(err)
}
client.Say(channel, reply) client.Say(channel, reply)
} }