<commit_before>class Command
  include MongoMapper::Document
  
  set_collection_name "commands"
  
  key :_type, String
  key :name, String, :required => true, :unique => true
  key :regex, Boolean, :default => false
  key :url_title, String, :unique => true
  key :body, String, :required => true
  key :desc, String
  key :usage, String
  key :help, Array
  key :events, Array, :default => []
  key :uses, Integer, :default => 0
  key :used_by, String
  key :used_at, Time
  key :created_by, String, :required => true
  key :updated_by, String
  timestamps!

  validates_format_of :name, :with => /^[a-zA-Z0-9_\^\$\:\[\]\(\)\{\}\.\*\+\-\?\!\,\/\\]+$/,
                      :message => "may only contain letters, numbers and common regex symbols"
  
  before_create :update_metadata
  before_create :update_url_title
  
  def update_url_title
    hex = Digest::SHA1.hexdigest(name)[0..5]
    title = name.gsub("_", "-").parameterize
    self.url_title = hex + (title =~ /^[\-\s]*$/ ? "" : "-#{title}")
  end
  
  def update_metadata
    self.class.update_metadata(self)
  end
  
  def used!(nick)
    self.used_by = nick
    self.used_at = Time.now
    self.uses += 1
    save
  end
  
  def eval!(context); end
  
  class << self
    def first_by_regex(name)
      all(:regex => true).each do |command|
        if match = name.match(/#{command.name}/i)
          command.instance_eval! do
            def match=(match)
              @match = match.dup
            end
            
            def match
              @match
            end
          end
          command.match = match
          return command
        end
      end
      nil<commit_msg>There is no such thing as Object#instance_eval!; this was a find-and-replace bug<commit_after>class Command
  include MongoMapper::Document
  
  set_collection_name "commands"
  
  key :_type, String
  key :name, String, :required => true, :unique => true
  key :regex, Boolean, :default => false
  key :url_title, String, :unique => true
  key :body, String, :required => true
  key :desc, String
  key :usage, String
  key :help, Array
  key :events, Array, :default => []
  key :uses, Integer, :default => 0
  key :used_by, String
  key :used_at, Time
  key :created_by, String, :required => true
  key :updated_by, String
  timestamps!

  validates_format_of :name, :with => /^[a-zA-Z0-9_\^\$\:\[\]\(\)\{\}\.\*\+\-\?\!\,\/\\]+$/,
                      :message => "may only contain letters, numbers and common regex symbols"
  
  before_create :update_metadata
  before_create :update_url_title
  
  def update_url_title
    hex = Digest::SHA1.hexdigest(name)[0..5]
    title = name.gsub("_", "-").parameterize
    self.url_title = hex + (title =~ /^[\-\s]*$/ ? "" : "-#{title}")
  end
  
  def update_metadata
    self.class.update_metadata(self)
  end
  
  def used!(nick)
    self.used_by = nick
    self.used_at = Time.now
    self.uses += 1
    save
  end
  
  def eval!(context); end
  
  class << self
    def first_by_regex(name)
      all(:regex => true).each do |command|
        if match = name.match(/#{command.name}/i)
          command.instance_eval do
            def match=(match)
              @match = match.dup
            end
            
            def match
              @match
            end
          end
          command.match = match
          return command
        end
      end
      nil
{'fraction_non_alphanumeric': 0.13719692489651095, 'fraction_numerical': 0.004139562389118865, 'mean_word_length': 2.1854990583804144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1654318', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1090, 'n_words': 294}