Class: Discordrb::Events::TypingEventHandler

Inherits:
EventHandler show all
Defined in:
lib/discordrb/events/typing.rb

Overview

Event handler for TypingEvent

Instance Method Summary collapse

Methods inherited from EventHandler

#after_call, #call, #initialize, #match, #matches_all

Constructor Details

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

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/discordrb/events/typing.rb', line 42

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

  [
    matches_all(@attributes[:in], event.channel) do |a, e|
      case a
      when String
        a.delete('#') == e.name
      when Integer
        a == e.id
      else
        a == e
      end
    end,
    matches_all(@attributes[:from], event.user) do |a, e|
      a == case a
           when String
             e.name
           when Integer
             e.id
           else
             e
           end
    end,
    matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
    matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
  ].reduce(true, &:&)
end