mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"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"
|
|
"github.com/nicklaw5/helix"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var nb *bot.Bot
|
|
|
|
func main() {
|
|
|
|
// runMode is either dev or production so that we don't join every channel
|
|
// everytime we do a small test.
|
|
runMode := flag.String("mode", "production", "Mode in which to run. (dev/production")
|
|
flag.Parse()
|
|
|
|
conf := config.LoadConfig()
|
|
|
|
helixClient, err := helix.NewClient(&helix.Options{
|
|
ClientID: conf.ClientId,
|
|
ClientSecret: conf.ClientSecret,
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("Error creating helix client: %s", err)
|
|
}
|
|
|
|
nb = &bot.Bot{
|
|
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
|
|
HelixClient: helixClient,
|
|
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)
|
|
})
|
|
|
|
// Depending on the mode we run in, join different channel.
|
|
if *runMode == "production" {
|
|
log.Info("[PRODUCTION]: Joining every channel.")
|
|
|
|
// Production, joining all regular channels
|
|
db.InitialJoin(nb)
|
|
|
|
} else if *runMode == "dev" {
|
|
log.Info("[DEV]: Joining nouryqt and nourybot.")
|
|
|
|
// Development, only join my two channels
|
|
nb.TwitchClient.Join("nouryqt", "nourybot")
|
|
nb.Send("nourybot", "[DEV] Badabing Badaboom Pepepains")
|
|
}
|
|
|
|
nb.TwitchClient.Connect()
|
|
}
|