mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
restructure commands
This commit is contained in:
parent
8e8342998f
commit
149712680a
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
6
pkg/commands/decapi/types.go
Normal file
6
pkg/commands/decapi/types.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package decapi
|
||||
|
||||
var (
|
||||
twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist."
|
||||
followageUserCannotFollowOwn = "A user cannot follow themself."
|
||||
)
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
49
pkg/commands/ivr/randomquote.go
Normal file
49
pkg/commands/ivr/randomquote.go
Normal 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
|
||||
}
|
||||
|
||||
}
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package decapi
|
||||
|
||||
var (
|
||||
twitterUserNotFoundError = "[Error] - [34] Sorry, that page does not exist."
|
||||
)
|
Loading…
Reference in a new issue