Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MessageDeleteBulk event #304

Merged
merged 4 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,9 @@ type VoiceServerUpdate struct {
type VoiceStateUpdate struct {
*VoiceState
}

// MessageDeleteBulk is the data for a MessageDeleteBulk event
type MessageDeleteBulk struct {
Messages []string `json:"ids"`
ChannelID string `json:"channel_id"`
}
14 changes: 10 additions & 4 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ func (s *State) MessageAdd(message *Message) error {
}

// MessageRemove removes a message from the world state.
func (s *State) MessageRemove(message *Message) error {
func (s *State) MessageRemove(channelID, messageID string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arghh sorry to be a butthole dude. But I didn't want to change the existing API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh woops i misread what you wrote, sorry

if s == nil {
return ErrNilState
}

c, err := s.Channel(message.ChannelID)
c, err := s.Channel(channelID)
if err != nil {
return err
}
Expand All @@ -533,7 +533,7 @@ func (s *State) MessageRemove(message *Message) error {
defer s.Unlock()

for i, m := range c.Messages {
if m.ID == message.ID {
if m.ID == messageID {
c.Messages = append(c.Messages[:i], c.Messages[i+1:]...)
return nil
}
Expand Down Expand Up @@ -708,7 +708,13 @@ func (s *State) onInterface(se *Session, i interface{}) (err error) {
}
case *MessageDelete:
if s.MaxMessageCount != 0 {
err = s.MessageRemove(t.Message)
err = s.MessageRemove(t.ChannelID, t.ID)
}
case *MessageDeleteBulk:
if s.MaxMessageCount != 0 {
for _, mID := range t.Messages {
s.MessageRemove(t.ChannelID, mID)
}
}
case *VoiceStateUpdate:
if s.TrackVoice {
Expand Down