Method: Cinch::Plugin::ClassMethods#match

Defined in:
lib/cinch/plugin.rb

#match(pattern, options = {}) ⇒ Matcher

TODO:

Document match/listener grouping

Set a match pattern.

Parameters:

  • pattern (Regexp, String)

    A pattern

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :method (Symbol) — default: :execute

    The method to execute

  • :use_prefix (Boolean) — default: true

    If true, the plugin prefix will automatically be prepended to the pattern.

  • :use_suffix (Boolean) — default: true

    If true, the plugin suffix will automatically be appended to the pattern.

  • prefix (String, Regexp, Proc) — default: nil

    A prefix overwriting the per-plugin prefix.

  • suffix (String, Regexp, Proc) — default: nil

    A suffix overwriting the per-plugin suffix.

  • react_on (Symbol, Fixnum) — default: :message

    The event to react on.

  • :group (Symbol) — default: nil

    The group the match belongs to.

  • :strip_colors (Boolean) — default: false

    Strip colors from message before attempting match

Returns:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/cinch/plugin.rb', line 195

def match(pattern, options = {})
  options = {
    :use_prefix => true,
    :use_suffix => true,
    :method => :execute,
    :group => nil,
    :prefix => nil,
    :suffix => nil,
    :react_on => nil,
    :strip_colors => false,
  }.merge(options)
  if options[:react_on]
    options[:react_on] = options[:react_on].to_s.to_sym
  end
  matcher = Matcher.new(pattern, *options.values_at(:use_prefix,
                                                    :use_suffix,
                                                    :method,
                                                    :group,
                                                    :prefix,
                                                    :suffix,
                                                    :react_on,
                                                    :strip_colors))
  @matchers << matcher

  matcher
end