mirror-nourybot/cmd/main.go

50 lines
1,015 B
Go
Raw Normal View History

2021-10-13 23:24:02 +02:00
package main
2021-10-13 23:29:29 +02:00
import (
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-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-19 22:25:47 +02:00
conf := config.LoadConfig()
2021-10-27 19:27:35 +02:00
// db.InsertInitialData()
2021-10-19 22:25:47 +02:00
nb = &bot.Bot{
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
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.
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-27 19:41:42 +02:00
// nb.TwitchClient.Join("nouryqt", "nourybot")
2021-10-28 15:16:22 +02:00
db.InitialJoin(nb)
2021-10-27 19:41:42 +02:00
// nb.Send("nourybot", "HeyGuys")
2021-10-19 22:33:08 +02:00
nb.TwitchClient.Connect()
2021-10-13 23:24:02 +02:00
}