Class: Discordrb::Events::MessageEventHandler
- Inherits:
-
EventHandler
- Object
- EventHandler
- Discordrb::Events::MessageEventHandler
- Defined in:
- lib/discordrb/events/message.rb
Overview
Event handler for MessageEvent
Direct Known Subclasses
MentionEventHandler, MessageEditEventHandler, PrivateMessageEventHandler
Instance Method Summary collapse
Methods inherited from EventHandler
#call, #initialize, #match, #matches_all
Constructor Details
This class inherits a constructor from Discordrb::Events::EventHandler
Instance Method Details
#after_call(event) ⇒ Object
137 138 139 |
# File 'lib/discordrb/events/message.rb', line 137 def after_call(event) event.(event.) unless event..empty? end |
#matches?(event) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/discordrb/events/message.rb', line 75 def matches?(event) # Check for the proper event type return false unless event.is_a? MessageEvent [ matches_all(@attributes[:starting_with] || @attributes[:start_with], event.content) do |a, e| if a.is_a? String e.start_with? a elsif a.is_a? Regexp (e =~ a) == 0 end end, matches_all(@attributes[:ending_with] || @attributes[:end_with], event.content) do |a, e| if a.is_a? String e.end_with? a elsif a.is_a? Regexp a.match(e) ? e.end_with?(a.match(e)[-1]) : false end end, matches_all(@attributes[:containing] || @attributes[:contains], event.content) do |a, e| if a.is_a? String e.include? a elsif a.is_a? Regexp (e =~ a) end end, 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.) do |a, e| if a.is_a? String a == e.name elsif a.is_a? Fixnum a == e.id elsif a == :bot e.current_bot? else a == e end end, matches_all(@attributes[:with_text] || @attributes[:content] || @attributes[:exact_text], event.content) do |a, e| if a.is_a? String e == a elsif a.is_a? Regexp match = a.match(e) match ? (e == match[0]) : false end end, matches_all(@attributes[:after], event.) { |a, e| a > e }, matches_all(@attributes[:before], event.) { |a, e| a < e }, matches_all(@attributes[:private], event.channel.private?) { |a, e| !e == !a } ].reduce(true, &:&) end |