Add message bulk delete handler, make member attribute optional on deleted messages. #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. TheAuthor
attribute will always be set, and it will try to set theMember
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:
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.