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

Add message bulk delete handler, make member attribute optional on deleted messages. #6

Merged
merged 4 commits into from
Sep 5, 2020

Conversation

Jack073
Copy link
Contributor

@Jack073 Jack073 commented Aug 3, 2020

This PR allows you to handle message bulk delete events, as well as adds checks to avoid runtime panics from a nil pointer dereference if a message edit/delete handler isn't set.

It also changes the behaviour of the deleted message handler slightly, previously it guaranteed that the Member attribute of the message was set, however this meant for example if someone left a server and a mod or staff member deleted one of their messages, it wouldn't be logged passed to the DeletedCallback. The Author attribute will always be set, and it will try to set the Member attribute, but it will be nil if there was an error getting the member. The edited message handler remains unaffected besides from adding the nil handler check mentioned above.

This new behaviour partially comes from the new bulk delete handler where (for consistency and ease of use) it fetched the member and set the member on the message. There was 3 main options to handle members that couldn't be fetched:

  1. returning from the function here as the single message delete handler did (though you would miss out on any bulk deletes if even one of the message authors had left the server)
  2. continuing to the next message, ignoring this message, but this would also cause missing messages is someone left the server
  3. make the Member attribute optional, but try to add it, adding the Author attribute anyway.

This does however add another method to the MessageCacheStorageAdapter interface - BulkGetAndDelete(ChannelID disgord.Snowflake, MessageIDs []disgord.Snowflake) []*disgord.Message, so this will be a breaking change if you use a custom MessageCacheStorageAdapter, however it does enable easy logging / handling of message bulk deletes.

Copy link
Contributor

@IAmJSD IAmJSD left a comment

Choose a reason for hiding this comment

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

LGTM

@IAmJSD IAmJSD merged commit 5c2739d into auttaja:master Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants