2021-10-13 23:24:02 +02:00
|
|
|
package main
|
|
|
|
|
2021-10-13 23:29:29 +02:00
|
|
|
import (
|
2021-10-29 17:05:07 +02:00
|
|
|
"flag"
|
2021-10-19 22:25:47 +02:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
2021-10-13 23:37:46 +02:00
|
|
|
"github.com/lyx0/nourybot/cmd/bot"
|
2021-10-14 00:19:35 +02:00
|
|
|
"github.com/lyx0/nourybot/pkg/config"
|
2021-10-27 19:27:35 +02:00
|
|
|
"github.com/lyx0/nourybot/pkg/db"
|
2021-10-19 22:25:47 +02:00
|
|
|
"github.com/lyx0/nourybot/pkg/handlers"
|
2021-10-29 17:05:07 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-10-13 23:29:29 +02:00
|
|
|
)
|
|
|
|
|
2021-10-19 22:25:47 +02:00
|
|
|
var nb *bot.Bot
|
|
|
|
|
2021-10-13 23:24:02 +02:00
|
|
|
func main() {
|
2021-10-25 23:33:00 +02:00
|
|
|
|
2021-10-29 17:05:07 +02:00
|
|
|
// No need to join every channel when on development mode.
|
|
|
|
runMode := flag.String("mode", "dev", "Mode in which to run. (dev/production")
|
|
|
|
flag.Parse()
|
|
|
|
|
2021-10-19 22:25:47 +02:00
|
|
|
conf := config.LoadConfig()
|
|
|
|
|
|
|
|
nb = &bot.Bot{
|
|
|
|
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
|
2021-10-28 17:48:18 +02:00
|
|
|
MongoClient: db.Connect(conf),
|
2021-10-19 22:25:47 +02:00
|
|
|
Uptime: time.Now(),
|
|
|
|
}
|
2021-10-13 23:29:29 +02:00
|
|
|
|
2021-10-19 22:25:47 +02:00
|
|
|
nb.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
2021-10-20 23:03:20 +02:00
|
|
|
|
2021-10-19 22:25:47 +02:00
|
|
|
// 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
|
|
|
|
}
|
2021-10-13 23:37:46 +02:00
|
|
|
|
2021-10-20 23:03:20 +02:00
|
|
|
// Don't act on bots own messages.
|
2021-10-24 17:35:45 +02:00
|
|
|
if message.Tags["user-id"] == conf.BotUserId {
|
2021-10-19 22:25:47 +02:00
|
|
|
return
|
|
|
|
}
|
2021-10-13 23:37:46 +02:00
|
|
|
|
2021-10-20 22:59:05 +02:00
|
|
|
// Forward the message for further processing.
|
2021-10-19 22:25:47 +02:00
|
|
|
handlers.PrivateMessage(message, nb)
|
|
|
|
})
|
2021-10-19 22:33:08 +02:00
|
|
|
|
2021-10-29 17:05:07 +02:00
|
|
|
if *runMode == "production" {
|
|
|
|
// Production, joining all regular channels
|
|
|
|
logrus.Info("[PRODUCTION]: Joining every channel.")
|
|
|
|
db.InitialJoin(nb)
|
|
|
|
|
|
|
|
} else if *runMode == "dev" {
|
|
|
|
// Development, only join my two channels
|
|
|
|
logrus.Info("[DEV]: Joining nouryqt and nourybot.")
|
|
|
|
|
|
|
|
nb.TwitchClient.Join("nouryqt", "nourybot")
|
|
|
|
nb.Send("nourybot", "[DEV] Badabing Badaboom Pepepains")
|
|
|
|
}
|
|
|
|
|
2021-10-19 22:33:08 +02:00
|
|
|
nb.TwitchClient.Connect()
|
2021-10-13 23:24:02 +02:00
|
|
|
}
|