From 149712680a3ceb670aae1fca9d01f82cf1c72628 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Mon, 8 Aug 2022 16:43:40 +0200 Subject: [PATCH] restructure commands --- pkg/commands/bttvemotes.go | 2 +- pkg/commands/currency.go | 2 +- pkg/{ => commands}/decapi/bttvemotes.go | 0 pkg/{ => commands}/decapi/currency.go | 0 pkg/{ => commands}/decapi/ffzemotes.go | 0 pkg/{ => commands}/decapi/tweet.go | 0 pkg/commands/decapi/types.go | 6 +++ pkg/commands/ffzemotes.go | 2 +- pkg/commands/ivr/randomquote.go | 49 +++++++++++++++++++++++++ pkg/commands/tweet.go | 2 +- pkg/decapi/types.go | 5 --- 11 files changed, 59 insertions(+), 9 deletions(-) rename pkg/{ => commands}/decapi/bttvemotes.go (100%) rename pkg/{ => commands}/decapi/currency.go (100%) rename pkg/{ => commands}/decapi/ffzemotes.go (100%) rename pkg/{ => commands}/decapi/tweet.go (100%) create mode 100644 pkg/commands/decapi/types.go create mode 100644 pkg/commands/ivr/randomquote.go delete mode 100644 pkg/decapi/types.go diff --git a/pkg/commands/bttvemotes.go b/pkg/commands/bttvemotes.go index 58d4fa6..9962dd5 100644 --- a/pkg/commands/bttvemotes.go +++ b/pkg/commands/bttvemotes.go @@ -2,8 +2,8 @@ package commands import ( "github.com/gempir/go-twitch-irc/v3" + "github.com/lyx0/nourybot/pkg/commands/decapi" "github.com/lyx0/nourybot/pkg/common" - "github.com/lyx0/nourybot/pkg/decapi" "go.uber.org/zap" ) diff --git a/pkg/commands/currency.go b/pkg/commands/currency.go index 9142f22..010424d 100644 --- a/pkg/commands/currency.go +++ b/pkg/commands/currency.go @@ -2,8 +2,8 @@ package commands import ( "github.com/gempir/go-twitch-irc/v3" + "github.com/lyx0/nourybot/pkg/commands/decapi" "github.com/lyx0/nourybot/pkg/common" - "github.com/lyx0/nourybot/pkg/decapi" "go.uber.org/zap" ) diff --git a/pkg/decapi/bttvemotes.go b/pkg/commands/decapi/bttvemotes.go similarity index 100% rename from pkg/decapi/bttvemotes.go rename to pkg/commands/decapi/bttvemotes.go diff --git a/pkg/decapi/currency.go b/pkg/commands/decapi/currency.go similarity index 100% rename from pkg/decapi/currency.go rename to pkg/commands/decapi/currency.go diff --git a/pkg/decapi/ffzemotes.go b/pkg/commands/decapi/ffzemotes.go similarity index 100% rename from pkg/decapi/ffzemotes.go rename to pkg/commands/decapi/ffzemotes.go diff --git a/pkg/decapi/tweet.go b/pkg/commands/decapi/tweet.go similarity index 100% rename from pkg/decapi/tweet.go rename to pkg/commands/decapi/tweet.go diff --git a/pkg/commands/decapi/types.go b/pkg/commands/decapi/types.go new file mode 100644 index 0000000..4e8777c --- /dev/null +++ b/pkg/commands/decapi/types.go @@ -0,0 +1,6 @@ +package decapi + +var ( + twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist." + followageUserCannotFollowOwn = "A user cannot follow themself." +) diff --git a/pkg/commands/ffzemotes.go b/pkg/commands/ffzemotes.go index 1cfaff5..349a5df 100644 --- a/pkg/commands/ffzemotes.go +++ b/pkg/commands/ffzemotes.go @@ -2,8 +2,8 @@ package commands import ( "github.com/gempir/go-twitch-irc/v3" + "github.com/lyx0/nourybot/pkg/commands/decapi" "github.com/lyx0/nourybot/pkg/common" - "github.com/lyx0/nourybot/pkg/decapi" "go.uber.org/zap" ) diff --git a/pkg/commands/ivr/randomquote.go b/pkg/commands/ivr/randomquote.go new file mode 100644 index 0000000..dea2fda --- /dev/null +++ b/pkg/commands/ivr/randomquote.go @@ -0,0 +1,49 @@ +package ivr + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + + "go.uber.org/zap" +) + +type randomQuoteApiResponse struct { + User string `json:"user"` + Message string `json:"message"` + Time string `json:"time"` + Error string `json:"error"` +} + +// FirstLine returns the first line a given user has sent in a +// given channel. +func RandomQuote(channel, username string) (string, error) { + sugar := zap.NewExample().Sugar() + defer sugar.Sync() + baseUrl := "https://api.ivr.fi/logs/rq" + + resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, channel, username)) + if err != nil { + sugar.Error(err) + return "Something went wrong FeelsBadMan", err + } + + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + sugar.Error(err) + } + + var responseObject randomQuoteApiResponse + json.Unmarshal(body, &responseObject) + + // User or channel was not found + if responseObject.Error != "" { + return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil + } else { + return fmt.Sprintf(username + ": " + responseObject.Message + " (" + responseObject.Time + " ago)."), nil + } + +} diff --git a/pkg/commands/tweet.go b/pkg/commands/tweet.go index 9880af1..b2d9912 100644 --- a/pkg/commands/tweet.go +++ b/pkg/commands/tweet.go @@ -2,8 +2,8 @@ package commands import ( "github.com/gempir/go-twitch-irc/v3" + "github.com/lyx0/nourybot/pkg/commands/decapi" "github.com/lyx0/nourybot/pkg/common" - "github.com/lyx0/nourybot/pkg/decapi" "go.uber.org/zap" ) diff --git a/pkg/decapi/types.go b/pkg/decapi/types.go deleted file mode 100644 index 74752c7..0000000 --- a/pkg/decapi/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package decapi - -var ( - twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist." -)