Files
streambot_twitch/cmd/bot/main.go
bryce d6c77a3c93 Impliment StartupTesting and started OAuth Server
Testing for IRC & Channels connection for debugging
OAuth Server (because it's better to roll my own for this)
internal/auth/oauth.go
tests/startup_checks.go

More tests to come for debugging

Plan to impliment Logging in internal/stoage/logs for internal & UI
debugging
2025-07-08 19:46:24 +12:00

75 lines
1.9 KiB
Go

package main
import (
"log"
"os"
"streambot_twitch/internal/auth"
"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() {
go func() {
if err := oauth.StartOAuthServer(":8080"); err != nil {
log.Fatalf("OAuth server error: %v", err)
}
}()
log.Println("OAuth server started on port 8080")
botUsername := os.Getenv("nz_chatterbot")
botOAuth :+ os.Getenv("BOT_OAUTH")
channel := os Getenv("brycefromnz101")
clientID := os.Getenv("TWITCH_CLIENTID")
clientSecret := os.Getenv("TWITCH_CLIENT_SECRET")
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)
}
}