mirror-nourybot/cmd/bot/main.go
2022-08-07 03:17:29 +02:00

56 lines
1.3 KiB
Go

package main
import (
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/internal/config"
"github.com/lyx0/nourybot/pkg/common"
"go.uber.org/zap"
)
type Application struct {
TwitchClient *twitch.Client
Logger *zap.SugaredLogger
}
func main() {
cfg := config.New()
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
tc := twitch.NewClient(cfg.TwitchUsername, cfg.TwitchOauth)
app := &Application{
TwitchClient: tc,
Logger: sugar,
}
// 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.
app.TwitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
app.handleWhisperMessage(message)
})
// Successfully connected to Twitch so we log a message with the
// mode we are currently running in..
app.TwitchClient.OnConnect(func() {
sugar.Infow("Successfully connected to Twitch Servers",
"Bot username", cfg.TwitchUsername,
"Environment", cfg.Environment)
common.Send("nourylul", "xd", app.TwitchClient)
})
app.TwitchClient.Join("nourylul")
err := app.TwitchClient.Connect()
if err != nil {
panic(err)
}
}