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:29:44 +02:00
|
|
|
log "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:40:28 +02:00
|
|
|
// runMode is either dev or production so that we don't join every channel
|
|
|
|
// everytime we do a small test.
|
2021-10-29 17:19:41 +02:00
|
|
|
runMode := flag.String("mode", "production", "Mode in which to run. (dev/production")
|
2021-10-29 17:05:07 +02:00
|
|
|
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:29:44 +02:00
|
|
|
// Depending on the mode we run in, join different channel.
|
2021-10-29 17:05:07 +02:00
|
|
|
if *runMode == "production" {
|
2021-10-29 17:29:44 +02:00
|
|
|
log.Info("[PRODUCTION]: Joining every channel.")
|
2021-10-29 17:40:28 +02:00
|
|
|
|
|
|
|
// Production, joining all regular channels
|
2021-10-29 17:05:07 +02:00
|
|
|
db.InitialJoin(nb)
|
|
|
|
|
|
|
|
} else if *runMode == "dev" {
|
2021-10-29 17:29:44 +02:00
|
|
|
log.Info("[DEV]: Joining nouryqt and nourybot.")
|
2021-10-29 17:05:07 +02:00
|
|
|
|
2021-10-29 17:40:28 +02:00
|
|
|
// Development, only join my two channels
|
2021-10-29 17:05:07 +02:00
|
|
|
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
|
|
|
}
|