diff --git a/pkg/commands/botstatus.go b/pkg/commands/botstatus.go index 8a590d5..1632da4 100644 --- a/pkg/commands/botstatus.go +++ b/pkg/commands/botstatus.go @@ -2,25 +2,19 @@ package commands import ( "fmt" - "io/ioutil" - "net/http" "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/api/aiden" log "github.com/sirupsen/logrus" ) -func BotStatus(channel string, userName string, client *twitch.Client) { - resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/twitch/botStatus/%s?includeLimits=1", userName)) +func BotStatus(channel string, name string, client *twitch.Client) { + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/botStatus/%s?includeLimits=1", name)) if err != nil { - log.Fatalln(err) + client.Say(channel, "Something went wrong FeelsBadMan") + log.Error(err) } - defer resp.Body.Close() + client.Say(channel, resp) - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - } - - client.Say(channel, string(body)) } diff --git a/pkg/commands/bttvemotes.go b/pkg/commands/bttvemotes.go index d8f44ac..db389c8 100644 --- a/pkg/commands/bttvemotes.go +++ b/pkg/commands/bttvemotes.go @@ -2,25 +2,18 @@ package commands import ( "fmt" - "io/ioutil" - "net/http" "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/api/aiden" log "github.com/sirupsen/logrus" ) func BttvEmotes(channel string, client *twitch.Client) { - resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/emotes/%s/bttv", channel)) + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/bttv", channel)) if err != nil { - log.Fatalln(err) + log.Error(err) + client.Say(channel, "Something went wrong FeelsBadMan") } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - } - - client.Say(channel, string(body)) + client.Say(channel, string(resp)) } diff --git a/pkg/commands/eightball.go b/pkg/commands/eightball.go index d3ff2e2..47aa4ea 100644 --- a/pkg/commands/eightball.go +++ b/pkg/commands/eightball.go @@ -1,28 +1,17 @@ package commands import ( - "io/ioutil" - "net/http" - "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/api/aiden" log "github.com/sirupsen/logrus" ) -func EightBall(message twitch.PrivateMessage, client *twitch.Client) { - resp, err := http.Get("https://customapi.aidenwallis.co.uk/api/v1/misc/8ball") +func EightBall(channel string, client *twitch.Client) { + resp, err := aiden.ApiCall("api/v1/misc/8ball") if err != nil { - client.Say(message.Channel, "Something went wrong FeelsBadMan") log.Error(err) + client.Say(channel, "Something went wrong FeelsBadMan") } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - client.Say(message.Channel, "Something went wrong FeelsBadMan") - log.Error(err) - } - - client.Say(message.Channel, string(body)) - + client.Say(channel, string(resp)) } diff --git a/pkg/commands/ffzemotes.go b/pkg/commands/ffzemotes.go index a9a9975..7ab9fdd 100644 --- a/pkg/commands/ffzemotes.go +++ b/pkg/commands/ffzemotes.go @@ -2,25 +2,19 @@ package commands import ( "fmt" - "io/ioutil" - "net/http" "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/api/aiden" log "github.com/sirupsen/logrus" ) func FfzEmotes(channel string, client *twitch.Client) { - resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/emotes/%s/ffz", channel)) + + resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/emotes/%s/ffz", channel)) if err != nil { - log.Fatalln(err) + log.Error(err) + client.Say(channel, "Something went wrong FeelsBadMan") } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - } - - client.Say(channel, string(body)) + client.Say(channel, string(resp)) } diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index a8b26d2..8aa9223 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -70,7 +70,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient) return case "8ball": - commands.EightBall(message, twitchClient) + commands.EightBall(message.Channel, twitchClient) return case "ffzemotes": commands.FfzEmotes(message.Channel, twitchClient)