module Boty # Public: contains de descriptive information that was associated with an # action via the `Bot#desc` method. # # Besides that also keep tracks of the regex for the associated Action, it is # used to describe the handler in case no command name and/or description was # passed via `Bot#desc`. # # The `ActionDescription` object will be stored inside the `Action#desc`. A # good usage example can be found in the `scripts/knows.rb` script. # # Examples: # # # scripts/omg.rb # desc "X omg!", "Make the bot scream X omgs." # hear(/(\d+ )?omg!/i) do |how_many| # how_many.times do say "LOL!" end # end # # # => generates an action with a description like this: # ActionDescription.new "X omg!", # description: "Make the bot scream X omgs." # regex: /(\d+ )?omg!/i class ActionDescription attr_reader :command, :description attr_writer :regex def initialize(command, description: nil, regex: nil) if description.nil? @description = command else @command = command @description = description end @regex = regex end def command return @command if @command return unless @regex match = /\?(i?)-(mx|mix):(.*)\)/.match @regex.to_s @command = "/#{match[3]}/#{match[1]}" end end end