mirror-nourybot/cmd/main.go
2021-10-28 21:49:54 +02:00

49 lines
1,021 B
Go

package main
import (
"fmt"
"time"
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/config"
"github.com/lyx0/nourybot/pkg/db"
"github.com/lyx0/nourybot/pkg/handlers"
)
var nb *bot.Bot
func main() {
conf := config.LoadConfig()
nb = &bot.Bot{
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
MongoClient: db.Connect(conf),
Uptime: time.Now(),
}
nb.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
// If channelID is missing something must have gone wrong.
channelID := message.Tags["room-id"]
if channelID == "" {
fmt.Printf("Missing room-id tag in message")
return
}
// Don't act on bots own messages.
if message.Tags["user-id"] == conf.BotUserId {
return
}
// Forward the message for further processing.
handlers.PrivateMessage(message, nb)
})
// nb.TwitchClient.Join("nouryqt", "nourybot")
db.InitialJoin(nb)
// nb.Send("nourybot", "HeyGuys")
nb.TwitchClient.Connect()
}