Create discord package and connect/disconnect handlers

This change moves the discord session singleton to the internal/discord
package, and implements basic Connect/Disconnect handlers.
This commit is contained in:
Piper Pentagram 2024-11-08 16:26:05 -08:00
parent 5e4662c8b0
commit bbcf6ef6cf
5 changed files with 93 additions and 24 deletions

View file

@ -13,7 +13,7 @@ import (
"sync"
"time"
"github.com/bwmarrin/discordgo"
"gitlab.com/whom/bingobot/internal/discord"
"gitlab.com/whom/bingobot/internal/logging"
)
@ -27,7 +27,6 @@ const (
EventValidationFailedError = "event failed validation: "
)
var DiscordSession *discordgo.Session
var eventMutex sync.RWMutex
var eventSubscriptionCache = [NumEventTypes][]chan Event{}
var eventCache = []Event{}
@ -360,8 +359,8 @@ func (ue UserEvent) Data() map[string]string {
}
func (ue UserEvent) Validate() error {
if DiscordSession != nil {
_, err := DiscordSession.User(ue.uid)
if discord.Connected() {
_, err := discord.User(ue.uid)
return err
} else {
// I would love to know how to actually fail here