Skip to content

Commit

Permalink
Merge pull request #6 from cByst/v0.1.2
Browse files Browse the repository at this point in the history
Fixed a bug where bot would look at reaction removals on all messages…
  • Loading branch information
cByst authored Nov 29, 2020
2 parents 20491c5 + 2e9c0e5 commit 91f6b77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 15 additions & 9 deletions amongusevents/amongusevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ func extractEventState(session *discordgo.Session, message *discordgo.Message) (
}

var attendingUsers []string
for _, user := range rsvpYes {
if !user.Bot {
attendingUsers = append(attendingUsers, user.Username)
if rsvpYes != nil {
for _, user := range rsvpYes {
if !user.Bot {
attendingUsers = append(attendingUsers, user.Username)
}
}
}

Expand All @@ -75,9 +77,11 @@ func extractEventState(session *discordgo.Session, message *discordgo.Message) (
}

var notAttendingUsers []string
for _, user := range rsvpNo {
if !user.Bot {
notAttendingUsers = append(notAttendingUsers, user.Username)
if rsvpNo != nil {
for _, user := range rsvpNo {
if !user.Bot {
notAttendingUsers = append(notAttendingUsers, user.Username)
}
}
}

Expand All @@ -87,9 +91,11 @@ func extractEventState(session *discordgo.Session, message *discordgo.Message) (
}

var timeChangeRequestedUsers []string
for _, user := range timeChangeRequested {
if !user.Bot {
timeChangeRequestedUsers = append(timeChangeRequestedUsers, user.Username)
if timeChangeRequested != nil {
for _, user := range timeChangeRequested {
if !user.Bot {
timeChangeRequestedUsers = append(timeChangeRequestedUsers, user.Username)
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion amongushandlers/amongushandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func messageReactionRemoveHandle(s *discordgo.Session, m *discordgo.MessageReact
if err != nil {
log.Error(errors.WithMessage(err, "Error finding message in message reaction remove handler"))
}

// ignore messages that were not created by the bot
if message.Author.ID != s.State.User.ID {
return
}

err = amongusevents.ReSyncEvent(s, message)
if err != nil {
log.Error(errors.WithMessage(err, "Error resyncing event state in reaction remove handler"))
Expand All @@ -45,7 +51,7 @@ func messageReactionAddHandle(s *discordgo.Session, m *discordgo.MessageReaction
log.Error(errors.WithMessage(err, "Error finding message in message reaction add handler"))
}

// Ignore if action was performed by the bot
// Ignore if action was performed by the bot or the message was not created by the bot
if m.MessageReaction.UserID == s.State.User.ID || message.Author.ID != s.State.User.ID {
return
}
Expand Down

0 comments on commit 91f6b77

Please sign in to comment.