mirror-nourybot/pkg/bot/bot.go

52 lines
1.3 KiB
Go
Raw Normal View History

2022-06-21 00:31:17 +02:00
package bot
import (
"github.com/gempir/go-twitch-irc/v3"
2022-08-06 23:45:02 +02:00
"github.com/lyx0/nourybot/internal/config"
2022-06-21 00:31:17 +02:00
"github.com/sirupsen/logrus"
)
type Bot struct {
2022-08-06 23:45:02 +02:00
TwitchClient *twitch.Client
2022-06-21 00:31:17 +02:00
logger *logrus.Logger
}
func New() *Bot {
// Initialize a new logger we attach to our application struct.
lgr := logrus.New()
2022-08-06 23:45:02 +02:00
cfg := config.New()
2022-06-21 00:31:17 +02:00
// Initialize a new twitch client which we attach to our
// application struct.
2022-08-06 23:45:02 +02:00
logrus.Info(cfg.TwitchUsername, cfg.TwitchOauth)
twitchClient := twitch.NewClient(cfg.TwitchUsername, cfg.TwitchOauth)
2022-06-21 00:31:17 +02:00
bot := &Bot{
2022-08-06 23:45:02 +02:00
TwitchClient: twitchClient,
2022-06-21 00:31:17 +02:00
logger: lgr,
}
2022-08-06 23:45:02 +02:00
2022-06-21 00:31:17 +02:00
// Received a PrivateMessage (normal chat message), pass it to
// the handler who checks for further action.
2022-08-06 23:45:02 +02:00
bot.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
2022-06-21 00:31:17 +02:00
bot.handlePrivateMessage(message)
})
// Received a WhisperMessage (Twitch DM), pass it to
// the handler who checks for further action.
2022-08-06 23:45:02 +02:00
bot.TwitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
2022-06-21 00:31:17 +02:00
bot.handleWhisperMessage(message)
})
// Successfully connected to Twitch so we log a message with the
// mode we are currently running in..
2022-08-06 23:45:02 +02:00
bot.TwitchClient.OnConnect(func() {
bot.logger.Infof("Successfully connected to Twitch Servers in %s mode!", cfg.Environment)
bot.Send("nourylul", "xd")
2022-06-21 00:31:17 +02:00
})
return bot
}