mirror-nourybot/cmd/bot/main.go

58 lines
1.4 KiB
Go
Raw Normal View History

2022-08-06 23:45:02 +02:00
package main
2022-08-07 01:34:31 +02:00
import (
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/internal/config"
2022-08-07 02:27:40 +02:00
"github.com/lyx0/nourybot/pkg/common"
2022-08-07 03:09:09 +02:00
"go.uber.org/zap"
2022-08-07 01:34:31 +02:00
)
type Application struct {
TwitchClient *twitch.Client
2022-08-07 03:09:09 +02:00
Logger *zap.SugaredLogger
2022-08-07 01:34:31 +02:00
}
2022-08-06 23:45:02 +02:00
func main() {
2022-08-07 01:34:31 +02:00
cfg := config.New()
2022-08-07 03:09:09 +02:00
2022-08-07 04:35:03 +02:00
tc := twitch.NewClient(cfg.TwitchUsername, cfg.TwitchOauth)
2022-08-07 03:09:09 +02:00
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
2022-08-07 01:34:31 +02:00
common.StartTime()
2022-08-07 02:27:40 +02:00
app := &Application{
TwitchClient: tc,
2022-08-07 03:09:09 +02:00
Logger: sugar,
2022-08-07 01:34:31 +02:00
}
2022-08-07 03:17:29 +02:00
2022-08-07 01:34:31 +02:00
// Received a PrivateMessage (normal chat message), pass it to
// the handler who checks for further action.
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
app.handlePrivateMessage(message)
})
// Received a WhisperMessage (Twitch DM), pass it to
// the handler who checks for further action.
2022-08-07 03:09:09 +02:00
app.TwitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
app.handleWhisperMessage(message)
})
2022-08-06 23:45:02 +02:00
2022-08-07 01:34:31 +02:00
// Successfully connected to Twitch so we log a message with the
// mode we are currently running in..
app.TwitchClient.OnConnect(func() {
2022-08-07 04:35:03 +02:00
app.Logger.Infow("Successfully connected to Twitch Servers",
2022-08-07 03:09:09 +02:00
"Bot username", cfg.TwitchUsername,
2022-08-07 04:35:03 +02:00
"Environment", cfg.Environment,
)
2022-08-07 03:09:09 +02:00
2022-08-07 02:27:40 +02:00
common.Send("nourylul", "xd", app.TwitchClient)
2022-08-07 01:34:31 +02:00
})
app.TwitchClient.Join("nourylul")
2022-08-07 02:27:40 +02:00
2022-08-07 01:34:31 +02:00
err := app.TwitchClient.Connect()
2022-08-06 23:45:02 +02:00
if err != nil {
panic(err)
}
}