refactor commands for the new api call

This commit is contained in:
lyx0 2021-10-17 17:56:19 +02:00
parent 3432c112ac
commit dd788efb70
5 changed files with 23 additions and 53 deletions

View file

@ -2,25 +2,19 @@ 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 BotStatus(channel string, userName string, client *twitch.Client) { func BotStatus(channel string, name string, client *twitch.Client) {
resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/twitch/botStatus/%s?includeLimits=1", userName)) resp, err := aiden.ApiCall(fmt.Sprintf("api/v1/twitch/botStatus/%s?includeLimits=1", name))
if err != nil { 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))
} }

View file

@ -2,25 +2,18 @@ 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 BttvEmotes(channel string, client *twitch.Client) { 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 { if err != nil {
log.Fatalln(err) log.Error(err)
client.Say(channel, "Something went wrong FeelsBadMan")
} }
defer resp.Body.Close() client.Say(channel, string(resp))
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
client.Say(channel, string(body))
} }

View file

@ -1,28 +1,17 @@
package commands package commands
import ( import (
"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 EightBall(message twitch.PrivateMessage, client *twitch.Client) { func EightBall(channel string, client *twitch.Client) {
resp, err := http.Get("https://customapi.aidenwallis.co.uk/api/v1/misc/8ball") resp, err := aiden.ApiCall("api/v1/misc/8ball")
if err != nil { if err != nil {
client.Say(message.Channel, "Something went wrong FeelsBadMan")
log.Error(err) log.Error(err)
client.Say(channel, "Something went wrong FeelsBadMan")
} }
defer resp.Body.Close() client.Say(channel, string(resp))
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))
} }

View file

@ -2,25 +2,19 @@ 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 FfzEmotes(channel string, client *twitch.Client) { 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 { if err != nil {
log.Fatalln(err) log.Error(err)
client.Say(channel, "Something went wrong FeelsBadMan")
} }
defer resp.Body.Close() client.Say(channel, string(resp))
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
client.Say(channel, string(body))
} }

View file

@ -70,7 +70,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient) commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient)
return return
case "8ball": case "8ball":
commands.EightBall(message, twitchClient) commands.EightBall(message.Channel, twitchClient)
return return
case "ffzemotes": case "ffzemotes":
commands.FfzEmotes(message.Channel, twitchClient) commands.FfzEmotes(message.Channel, twitchClient)