Files
discord-scores-bot/internal/bot/bot.go
2024-11-10 17:23:41 -06:00

42 lines
1.2 KiB
Go

package bot
import (
"fmt"
"strings"
"discord-cfb-bot/internal/clients/cfb" // Adjust this import path as needed
"github.com/bwmarrin/discordgo"
)
// MessageCreate handles incoming messages and triggers the appropriate response
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore messages from the bot itself
if m.Author.ID == s.State.User.ID {
return
}
// Command for fetching college football scores
if strings.HasPrefix(m.Content, "!cfb") {
// Extract any arguments (e.g., week number) if needed
weekNumber := 10 // Replace this with dynamic parsing if necessary
games, err := cfb.FetchScoreboard(weekNumber)
if err != nil {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Error fetching games: %s", err))
return
}
if len(games) == 0 {
s.ChannelMessageSend(m.ChannelID, "No games found for this week.")
return
}
// Send formatted game summaries
for _, game := range games {
gameSummary := cfb.FormatGameOutput(game)
s.ChannelMessageSend(m.ChannelID, gameSummary)
}
}
}