From 737a9f62596695ae8ffa204e8b2fdf75362ccc80 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Thu, 14 Oct 2021 22:56:08 +0200 Subject: [PATCH] add uptime command --- pkg/commands/uptime.go | 30 ++++++++++++++++++++++++++++++ pkg/handlers/command.go | 7 +++++++ 2 files changed, 37 insertions(+) create mode 100644 pkg/commands/uptime.go diff --git a/pkg/commands/uptime.go b/pkg/commands/uptime.go new file mode 100644 index 0000000..eb9b577 --- /dev/null +++ b/pkg/commands/uptime.go @@ -0,0 +1,30 @@ +package commands + +import ( + "fmt" + "io/ioutil" + "net/http" + + "github.com/gempir/go-twitch-irc/v2" + log "github.com/sirupsen/logrus" +) + +func Uptime(channel string, target string, client *twitch.Client) { + resp, err := http.Get(fmt.Sprintf("https://customapi.aidenwallis.co.uk/api/v1/twitch/channel/%s/uptime", target)) + + if err != nil { + client.Say(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + client.Say(channel, "Something went wrong FeelsBadMan") + log.Error(err) + } + + client.Say(channel, string(body)) + +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 3f78ab4..ce9bf37 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -75,6 +75,13 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u commands.Weather(message.Channel, message.Message[9:len(message.Message)], twitchClient) return } + case "uptime": + if msgLen == 1 { + commands.Uptime(message.Channel, message.Channel, twitchClient) + } else { + commands.Uptime(message.Channel, cmdParams[1], twitchClient) + return + } } }