Skip to content

Commit

Permalink
feat: adding more logging and fixing mutex locks
Browse files Browse the repository at this point in the history
  • Loading branch information
jlehtimaki committed Jun 12, 2024
1 parent 54f8e6a commit 3150210
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Discord struct {
Requests map[string]time.Time
Faucet faucet.Faucet
logger zerolog.Logger
*sync.Mutex
}

func InitDiscord() (Discord, error) {
Expand All @@ -42,13 +43,16 @@ func InitDiscord() (Discord, error) {
if d.Token == "" {
return Discord{}, fmt.Errorf("missing discord token")
}

d.logger.Info().Msg("initialising discord connection")
d.Session, err = discordgo.New("Bot " + d.Token)
if err != nil {
return Discord{}, err
}

d.Requests = make(map[string]time.Time)

d.logger.Info().Msg("initialising faucet")
d.Faucet, err = faucet.InitFaucet()
if err != nil {
return Discord{}, err
Expand Down Expand Up @@ -134,9 +138,8 @@ func (d *Discord) requestFunds(m *discordgo.MessageCreate) {
}

func (d *Discord) purgeExpiredEntries() {
var mu sync.Mutex
mu.Lock()
defer mu.Unlock()
d.Lock()
defer d.Unlock()

now := time.Now()
for k, v := range d.Requests {
Expand Down

0 comments on commit 3150210

Please sign in to comment.