Compare commits

8 Commits

Author SHA1 Message Date
c55d5b3d07 Update config/config.go 2026-09-02 20:25:45 -04:00
45a34a1b5b Convert team names to lower to be case-insensitive 2024-11-12 11:34:57 -06:00
84b2abd98c Change to local time to avoid UTC confusion if no date is present 2024-11-11 19:24:15 -05:00
80b9402a00 The shit I do for w00t4me 2024-11-11 13:04:55 -05:00
5b7169e013 Change time zone to central and remove double timezone listing 2024-11-11 12:25:19 -05:00
34f21977ff Oops 2024-11-11 11:50:24 -05:00
94c765140a Readd modfiles 2024-11-10 21:28:24 -05:00
43e4170ad1 remove modfiles 2024-11-10 21:26:57 -05:00
5 changed files with 89 additions and 13 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
# Use the official Go 1.23 image for building the application
FROM golang:1.23-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy the Go modules manifest and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the application source code
COPY . .
# Build the Go application from the appropriate directory inside 'cmd'
RUN go build -o discord-scores-bot ./cmd/main.go
# Create a minimal runtime image
FROM alpine:latest
RUN apk --no-cache add ca-certificates
# Set the working directory
WORKDIR /root/
# Copy the built Go binaries from the builder stage
COPY --from=builder /app/discord-scores-bot .
# Run the bot (use separate Dockerfiles if needed for distinct deployments)
CMD ["./discord-scores-bot"]

View File

@ -1,12 +1,12 @@
package config package config
var BotToken = " " var BotToken = "YOUR_TOKEN"
var CustomTeamNames = map[string]string{ var CustomTeamNames = map[string]string{
"UGA": "Georgia", "uga": "Georgia",
"Booger Eaters": "Auburn", "booger eaters": "Auburn",
"Rape Enablers": "LSU", "rape enablers": "LSU",
"Checkerboard Clowns": "Tennessee", "checkerboard clowns": "Tennessee",
} }
func LoadConfig() { func LoadConfig() {

2
go.mod
View File

@ -1,4 +1,4 @@
module discord-cfb-bot module discord-scores-bot
go 1.19 go 1.19

View File

@ -35,12 +35,20 @@ type Team struct {
func GetGameInfo(teamName, date string) string { func GetGameInfo(teamName, date string) string {
// If no date is provided, use today's date // If no date is provided, use today's date
if date == "" { if date == "" {
date = time.Now().Format("2006/01/02") // Format as YYYY/MM/DD // Load Central Time location
loc, err := time.LoadLocation("America/Chicago")
if err != nil {
loc = time.FixedZone("CST", -6*60*60) // Fallback to a fixed offset if loading fails
}
// Get current time in Central Time
currentTime := time.Now().In(loc)
date = currentTime.Format("2006/01/02") // Format as YYYY/MM/DD in Central Time
} else { } else {
// Check if the last 5 characters are in MM/DD format for date input // Check if the last 5 characters are in MM/DD format for date input
if len(date) == 5 && unicode.IsDigit(rune(date[0])) && unicode.IsDigit(rune(date[1])) && date[2] == '/' && if len(date) == 5 && unicode.IsDigit(rune(date[0])) && unicode.IsDigit(rune(date[1])) && date[2] == '/' &&
unicode.IsDigit(rune(date[3])) && unicode.IsDigit(rune(date[4])) { unicode.IsDigit(rune(date[3])) && unicode.IsDigit(rune(date[4])) {
date = fmt.Sprintf("2024/%s", strings.ReplaceAll(date, "/", "/")) // Add the year and reformat date = fmt.Sprintf("2024/%s", date) // Add the year and format
} else { } else {
return "Invalid date format. Please use MM/DD." return "Invalid date format. Please use MM/DD."
} }
@ -89,8 +97,16 @@ func fetchAndParseGames(apiURL, teamName string) string {
game.Game.Home.Names.Short, game.Game.Home.Score, game.Game.Home.Names.Short, game.Game.Home.Score,
currentPeriod, game.Game.ContestClock) currentPeriod, game.Game.ContestClock)
} else if game.Game.GameState == "pre" { } else if game.Game.GameState == "pre" {
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s ET", startTime, err := time.Parse("03:04PM ET", game.Game.StartTime)
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime) if err == nil {
startTime = startTime.Add(-1 * time.Hour) // Subtract 1 hour for Central Time
formattedTime := startTime.Format("03:04 PM CT")
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s",
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, formattedTime)
} else {
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s",
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime)
}
} else if game.Game.GameState == "final" { } else if game.Game.GameState == "final" {
gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**", gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**",
game.Game.Away.Names.Short, game.Game.Away.Score, game.Game.Away.Names.Short, game.Game.Away.Score,

View File

@ -6,8 +6,11 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time"
"unicode" "unicode"
"discord-scores-bot/config"
) )
type Game struct { type Game struct {
@ -15,6 +18,7 @@ type Game struct {
GameID string `json:"gameID"` GameID string `json:"gameID"`
StartDate string `json:"startDate"` StartDate string `json:"startDate"`
StartTime string `json:"startTime"` StartTime string `json:"startTime"`
StartTimeEpoch string `json:"startTimeEpoch"`
GameState string `json:"gameState"` GameState string `json:"gameState"`
CurrentPeriod string `json:"currentPeriod"` CurrentPeriod string `json:"currentPeriod"`
ContestClock string `json:"contestClock"` ContestClock string `json:"contestClock"`
@ -33,9 +37,15 @@ type Team struct {
} }
func GetGameInfo(teamName string) string { func GetGameInfo(teamName string) string {
teamName = strings.TrimSpace(teamName) teamName = strings.TrimSpace(strings.ToLower(teamName))
week := "" week := ""
// Check if the teamName matches a custom name and replace if found
if customName, exists := config.CustomTeamNames[teamName]; exists {
log.Printf("Custom team name detected: %s -> %s", teamName, customName)
teamName = customName
}
// Check if the last two characters of the input are integers for the week // Check if the last two characters of the input are integers for the week
if len(teamName) >= 2 && unicode.IsDigit(rune(teamName[len(teamName)-1])) && unicode.IsDigit(rune(teamName[len(teamName)-2])) { if len(teamName) >= 2 && unicode.IsDigit(rune(teamName[len(teamName)-1])) && unicode.IsDigit(rune(teamName[len(teamName)-2])) {
week = teamName[len(teamName)-2:] week = teamName[len(teamName)-2:]
@ -90,8 +100,13 @@ func GetGameInfo(teamName string) string {
game.Game.Home.Names.Short, game.Game.Home.Score, game.Game.Home.Names.Short, game.Game.Home.Score,
period, game.Game.ContestClock) period, game.Game.ContestClock)
} else if game.Game.GameState == "pre" { } else if game.Game.GameState == "pre" {
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s ET", centralTime, err := convertEpochToCentralTime(game.Game.StartTimeEpoch)
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime) if err != nil {
log.Printf("Time conversion error: %v", err)
centralTime = game.Game.StartTime // Fall back to original time if conversion fails
}
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s CT",
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, centralTime)
} else if game.Game.GameState == "final" { } else if game.Game.GameState == "final" {
gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**", gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**",
game.Game.Away.Names.Short, game.Game.Away.Score, game.Game.Away.Names.Short, game.Game.Away.Score,
@ -109,3 +124,20 @@ func GetGameInfo(teamName string) string {
return "No game found for the specified team." return "No game found for the specified team."
} }
func convertEpochToCentralTime(epochStr string) (string, error) {
epoch, err := strconv.ParseInt(epochStr, 10, 64)
if err != nil {
return "", fmt.Errorf("error parsing epoch: %w", err)
}
// Convert the epoch time to time.Time and set it to Central Time
t := time.Unix(epoch, 0).UTC()
locCT, err := time.LoadLocation("America/Chicago")
if err != nil {
return "", fmt.Errorf("error loading Central Time location: %w", err)
}
centralTime := t.In(locCT)
return centralTime.Format("03:04 PM"), nil
}