Skip to content

Commit

Permalink
fix concurrent map access
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvpot committed Mar 9, 2023
1 parent 2f54ba6 commit 8bf9878
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/fedfx/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fedfx
import (
"fmt"
"strings"
"sync"

"github.com/bwmarrin/discordgo"
"go.uber.org/config"
Expand Down Expand Up @@ -40,6 +41,7 @@ type fedLogger struct {
config Config
messageStore messagefx.Store
lastSong map[string]string
lastSongLock sync.Mutex
}

func New(p Params) error {
Expand Down Expand Up @@ -126,13 +128,16 @@ func (p *fedLogger) handlePresenceUpdate(s *discordgo.Session, m *discordgo.Pres
return
}

p.lastSongLock.Lock()
if lastSong, ok := p.lastSong[m.User.ID]; ok {
if songName == lastSong {
p.Log.Debug("duplicate spotify presence")
p.lastSongLock.Unlock()
return
}
}
p.lastSong[m.User.ID] = songName
p.lastSongLock.Unlock()

u, err := s.State.Member(m.GuildID, m.User.ID)
if err != nil {
Expand Down

0 comments on commit 8bf9878

Please sign in to comment.