restructure commands

This commit is contained in:
lyx0 2022-08-08 16:43:40 +02:00
parent 8e8342998f
commit 149712680a
11 changed files with 59 additions and 9 deletions

View file

@ -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"
)

View file

@ -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"
)

View file

@ -0,0 +1,6 @@
package decapi
var (
twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist."
followageUserCannotFollowOwn = "A user cannot follow themself."
)

View file

@ -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"
)

View file

@ -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
}
}

View file

@ -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"
)

View file

@ -1,5 +0,0 @@
package decapi
var (
twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist."
)