mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
use logrus logger instead of standard logger
This commit is contained in:
parent
9293b6ff00
commit
2ee85c47d7
|
@ -2,11 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v3"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
|
@ -18,7 +18,7 @@ type config struct {
|
|||
type application struct {
|
||||
config config
|
||||
twitchClient *twitch.Client
|
||||
logger *log.Logger
|
||||
logger *logrus.Logger
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -31,12 +31,12 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
// Initialize a new logger we attach to our application struct.
|
||||
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
||||
lgr := logrus.New()
|
||||
|
||||
// Load the .env file and check for errors.
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
logger.Fatal("Error loading .env file")
|
||||
lgr.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
// Load bot credentials from the .env file.
|
||||
|
@ -52,7 +52,7 @@ func main() {
|
|||
app := &application{
|
||||
config: cfg,
|
||||
twitchClient: twitchClient,
|
||||
logger: logger,
|
||||
logger: lgr,
|
||||
}
|
||||
|
||||
// Received a PrivateMessage (normal chat message), pass it to
|
||||
|
@ -70,7 +70,7 @@ func main() {
|
|||
// Successfully connected to Twitch so we log a message with the
|
||||
// mode we are currently running in..
|
||||
app.twitchClient.OnConnect(func() {
|
||||
app.logger.Printf("Successfully connected to Twitch Servers in %s mode!", app.config.env)
|
||||
app.logger.Infof("Successfully connected to Twitch Servers in %s mode!", app.config.env)
|
||||
})
|
||||
|
||||
// Join test channels
|
||||
|
|
|
@ -9,19 +9,19 @@ func (app *application) handlePrivateMessage(message twitch.PrivateMessage) {
|
|||
|
||||
// If there is no roomId something went wrong.
|
||||
if roomId == "" {
|
||||
app.logger.Print("Missing room-id in message tag ", roomId)
|
||||
app.logger.Error("Missing room-id in message tag ", roomId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(message.Message) >= 2 {
|
||||
if message.Message[:2] == "()" {
|
||||
// TODO: Command Handling
|
||||
app.logger.Println("[Command detected]: ", message.Message)
|
||||
app.logger.Infof("[Command detected]: ", message.Message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Message was no command so we just print it.
|
||||
app.logger.Printf("[#%s]:%s: %s", message.Channel, message.User.DisplayName, message.Message)
|
||||
app.logger.Infof("[#%s]:%s: %s", message.Channel, message.User.DisplayName, message.Message)
|
||||
|
||||
}
|
||||
|
|
|
@ -5,5 +5,5 @@ import "github.com/gempir/go-twitch-irc/v3"
|
|||
func (app *application) handleWhisperMessage(message twitch.WhisperMessage) {
|
||||
// Print the whisper message for now.
|
||||
// TODO: Implement a basic whisper handler.
|
||||
app.logger.Printf("[#whisper]:%s: %s", message.User.DisplayName, message.Message)
|
||||
app.logger.Infof("[#whisper]:%s: %s", message.User.DisplayName, message.Message)
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -5,4 +5,7 @@ go 1.17
|
|||
require (
|
||||
github.com/gempir/go-twitch-irc/v3 v3.1.0
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
|
||||
|
|
10
go.sum
10
go.sum
|
@ -1,4 +1,14 @@
|
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.1.0 h1:bUVZ5mADhH7KidJVcl+z79kgLJ7sjdAk4b/ylAvaLy0=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.1.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
|
||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
Loading…
Reference in a new issue