mirror-nourybot/cmd/bot/main.go

62 lines
1.1 KiB
Go
Raw Normal View History

2022-06-04 02:21:20 +02:00
package main
import (
"flag"
"log"
"os"
2022-06-04 02:29:05 +02:00
"github.com/gempir/go-twitch-irc/v3"
2022-06-04 02:21:20 +02:00
"github.com/joho/godotenv"
)
type config struct {
env string
botUsername string
botOauth string
}
type application struct {
config config
twitchClient *twitch.Client
logger *log.Logger
}
func main() {
var cfg config
flag.StringVar(&cfg.env, "env", "development", "Environment (development|string|production)")
flag.Parse()
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
2022-06-04 02:29:05 +02:00
cfg.botUsername = os.Getenv("BOT_USER")
cfg.botOauth = os.Getenv("BOT_OAUTH")
2022-06-04 02:21:20 +02:00
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
twitchClient := twitch.NewClient(cfg.botUsername, cfg.botOauth)
app := &application{
config: cfg,
twitchClient: twitchClient,
logger: logger,
}
2022-06-04 02:40:43 +02:00
app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
app.handlePrivateMessage(message)
})
2022-06-04 02:29:05 +02:00
app.twitchClient.Join("nourylul")
app.twitchClient.Join("nourybot")
app.twitchClient.Say("nourylul", "xd")
app.twitchClient.Say("nourybot", "xd")
err = app.twitchClient.Connect()
if err != nil {
panic(err)
}
2022-06-04 02:21:20 +02:00
}