MetalAdventures/src/discord/clean_plugin.rb

25 lines
584 B
Ruby

class MetalAdventuresDiscord::CleanPlugin
include Gem::Text # #levenshtein_distance/2
def initialize(bot)
@bot = bot
@playing = {}
hook_scene!
end
HISTORY_SIZE = 100
REGEXP_TO_CLEAN = [
/^!(ref|refs|roll|clean)/,
].freeze
def hook_scene!
@bot.message(with_text: /^!clean/) do |event|
event
.channel
.history(HISTORY_SIZE)
.filter { |clean_event| clean_event.author.id == @bot.bot_user.id || REGEXP_TO_CLEAN.any? { |regexp| clean_event.content.match?(regexp) } }
.each { _1.delete; sleep 1 }
end
end
end