Class: Discordrb::Events::MessageEventHandler

Inherits:
EventHandler
  • Object
show all
Defined in:
lib/discordrb/events/message.rb

Overview

Event handler for MessageEvent

Direct Known Subclasses

MentionEventHandler

Instance Method Summary collapse

Methods inherited from EventHandler

#initialize, #match, #matches_all

Constructor Details

This class inherits a constructor from Discordrb::Events::EventHandler

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/discordrb/events/message.rb', line 28

def matches?(event)
  # Check for the proper event type
  return false unless event.is_a? MessageEvent

  [
    matches_all(@attributes[:starting_with], event.content) { |a, e| e.start_with? a },
    matches_all(@attributes[:ending_with], event.content) { |a, e| e.end_with? a },
    matches_all(@attributes[:containing], event.content) { |a, e| e.include? a },
    matches_all(@attributes[:in], event.channel) do |a, e|
      if a.is_a? String
        # Make sure to remove the "#" from channel names in case it was specified
        a.delete('#') == e.name
      elsif a.is_a? Fixnum
        a == e.id
      else
        a == e
      end
    end,
    matches_all(@attributes[:from], event.author) do |a, e|
      if a.is_a? String
        a == e.name
      elsif a.is_a? Fixnum
        a == e.id
      else
        a == e
      end
    end,
    matches_all(@attributes[:with_text], event.content) { |a, e| e == a },
    matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
    matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
  ].reduce(true, &:&)
end