Yuuki-Discord / Yuuki-Bot

Free and open-source general-purpose bot for Discord.
MIT License
37 stars 7 forks source link

Provide a shared helper for clear #88

Closed spotlightishere closed 3 years ago

spotlightishere commented 3 years ago

We introduce a new helper for deleting messages named delete_messages. The majority of the size and diff within this review are related to its decoupling from the clear command.

In order for this to be useful beyond the clear command, we introduce a proc named criteria. This allows for more situational handling. For example, consider this snippet from the clear command:

message_count = Helper.delete_messages(event, clear_num, proc { |m|
  next if m.id == event.message.id
  next if m.id == info_msg.id

  true
})

By allowing a set of conditions, we could theoretically expand the clear command to things such as by author, within a date range, specific message contents, if the message has images, etc.


Beyond that, the clear command now more closely resembles the functionality of prune with a message that it edits a result to in order to save visual space. This fully resolves #31 as it will now attempt to use this helper if it has permissions.