get list of channels to join through env file

This commit is contained in:
lyx0 2024-03-05 19:29:46 +01:00
parent 7740e6fa97
commit cc41eedbbb

21
main.go
View file

@ -2,6 +2,7 @@ package main
import ( import (
"os" "os"
"strings"
"github.com/gempir/go-twitch-irc/v4" "github.com/gempir/go-twitch-irc/v4"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@ -41,12 +42,13 @@ func main() {
sugar.Fatal("Error loading .env") sugar.Fatal("Error loading .env")
} }
// Twitch config variables // Twitch account config
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME") cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
cfg.twitchOauth = os.Getenv("TWITCH_OAUTH") cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth)
userMsgStore := make(map[string][]ollamaMessage) userMsgStore := make(map[string][]ollamaMessage)
app := &application{ app := &application{
TwitchClient: tc, TwitchClient: tc,
Log: sugar, Log: sugar,
@ -75,17 +77,16 @@ func main() {
}) })
app.TwitchClient.OnConnect(func() { app.TwitchClient.OnConnect(func() {
app.TwitchClient.Say("nouryxd", "MrDestructoid") app.Log.Info("Successfully connected to Twitch Servers")
app.TwitchClient.Say("nourybot", "MrDestructoid")
// Successfully connected to Twitch
app.Log.Infow("Successfully connected to Twitch Servers",
"Bot username", cfg.twitchUsername,
)
}) })
app.TwitchClient.Join("nouryxd") channels := os.Getenv("TWITCH_CHANNELS")
app.TwitchClient.Join("nourybot") channel := strings.Split(channels, ",")
for i := 0; i < len(channel); i++ {
app.TwitchClient.Join(channel[i])
app.TwitchClient.Say(channel[i], "MrDestructoid")
app.Log.Infof("Joining channel: %s", channel[i])
}
// Actually connect to chat. // Actually connect to chat.
err = app.TwitchClient.Connect() err = app.TwitchClient.Connect()