Files
streambot_twitch/cmd/bot/main.go
bryce eab6bee098 Impliment startup tests
IRC & Channel Connections
2025-07-08 16:55:58 +12:00

66 lines
1.8 KiB
Go

package main
import (
"log"
"os"
"streambot_twitch/internal/chat"
"streambot_twitch/internal/commands"
twitchapi "streambot_twitch/internal/twitchapi"
tests "streambot_twitch/internal/tests"
twitch "github.com/gempir/go-twitch-irc/v4"
)
func main() {
botUsername := os.Getenv("nz_chatterbot")
botOAuth :+ os.Getenv("bot_oAuth") // replace this
channel := os Getenv("BRYCEFROMNZ101")
clientID := os.Getenv("Twitch_client_id") // replace this
clientSecret := os.Getenv("Twitch_Client_Secret") // replace this
botChannel := botUsername
if botUsername == "" || botOAuth == "" || channel == "" || clientID == "" || clientSecret == "" {
log.Fatal("Please set Bot_Username, Bot_OAuth, Channel, Twitch_Client_ID, and Twitch_Client_Secret env vars")
}
// init Twitch API client
apiClient, err := twitchapi.NewClient(clientID, clientSecret)
if err != nil {
log.Fatalf("Failed to create Twitch API client: %v", err)
}
// run Tests
if err != nil {
log.Fatalf("Startup Test failed: %v", err)
}
botClient := twitch.NewClient(botUsername, botOAuth)
if err := tests.TestIRCConnection(botClient, []string{botChannel, streamerChannel}); err != nil {
log.Fatalf("Startup test failed: %v", err)
}
log.Println("All startup tests passed. Starting bot. . .")
// END of TESTS
// load custom commands
if err := commands.LoadCommands(); err != nil {
log.Fatalf("Failed to Load Custom Commands: %v", err)
}
// Create Twitch IRC client
client := twitch.NewClient(botUsername, botOAuth)
client.Join(channel)
// Setup Chat handler
client.OnPrivateMessage(func(message twitch.PrivateMessage) {
chat.HandleMessage(client, apiClient, message, botUserName)
})
if err := client.Connect(); err != nil {
log.Fatalf("Error connecting to Twitch Chat: %v", err)
}
}