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 Channel#delete_messages #235

Merged
merged 3 commits into from
Oct 8, 2016
Merged

add Channel#delete_messages #235

merged 3 commits into from
Oct 8, 2016

Conversation

z64
Copy link
Collaborator

@z64 z64 commented Sep 28, 2016

allows for selective pruning of messages in a channel (instead of just last N messages) to make better use of the bulk_delete endpoint, for example, unless a Member has a certain role:

command(:prune_unless_role, 
        required_permissions: [:manage_messages]) do |event|
  role = event.server.roles.find { |r| r.name == 'moderator' }
  messages = event.channel.history(100).select do |m|
    m.author.role? role
  end
  event.channel.delete_messages(messages)
end

@meew0 meew0 added this to the 3.1.0 milestone Sep 28, 2016
def delete_messages(messages)
raise ArgumentError, 'Can only delete between 2 and 100 messages!' unless messages.count.between?(2, 100)

messages.map! { |m| m.is_a?(Integer) ? m : m.id }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be replaced with messages.map!(&:resolve_id), as that is what the resolve_id function is intended for. (Bonus feature: it allows IDs as strings too)

@meew0 meew0 merged commit da20fec into discordrb:master Oct 8, 2016
@z64 z64 deleted the enhance/bulk_delete branch May 10, 2017 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants