Add actual support for live scores.
This commit is contained in:
@ -1,41 +1,41 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"discord-cfb-bot/config"
|
||||
"discord-cfb-bot/internal/clients"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"fmt"
|
||||
"strings"
|
||||
"discord-cfb-bot/config"
|
||||
"discord-cfb-bot/internal/clients"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Bot *discordgo.Session
|
||||
|
||||
func Start() error {
|
||||
var err error
|
||||
Bot, err = discordgo.New("Bot " + config.BotToken)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating a Discord session: %w", err)
|
||||
}
|
||||
var err error
|
||||
Bot, err = discordgo.New("Bot " + config.BotToken)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating a Discord session: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Discord session created successfully")
|
||||
fmt.Println("Discord session created successfully")
|
||||
|
||||
Bot.AddHandler(commandHandler)
|
||||
err = Bot.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error opening connection: %w", err)
|
||||
}
|
||||
fmt.Println("Bot is now running.")
|
||||
return nil
|
||||
Bot.AddHandler(commandHandler)
|
||||
err = Bot.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error opening connection: %w", err)
|
||||
}
|
||||
fmt.Println("Bot is now running.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func commandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.Bot {
|
||||
return
|
||||
}
|
||||
if m.Author.Bot {
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(m.Content, "!s ") {
|
||||
teamName := strings.TrimSpace(strings.TrimPrefix(m.Content, "!s "))
|
||||
response := clients.GetGameInfo(teamName)
|
||||
s.ChannelMessageSend(m.ChannelID, response)
|
||||
}
|
||||
if strings.HasPrefix(m.Content, "!s ") {
|
||||
teamName := strings.TrimSpace(strings.TrimPrefix(m.Content, "!s "))
|
||||
response := clients.GetGameInfo(teamName)
|
||||
s.ChannelMessageSend(m.ChannelID, response)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user