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, MessageUpdateEventHandler, 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
260 261 262 263 264 265 266 |
# File 'lib/discordrb/events/message.rb', line 260 def after_call(event) if event.file.nil? event.(event.) unless event..empty? else event.send_file(event.file, caption: event., filename: event.filename, spoiler: event.file_spoiler) end end |
#matches?(event) ⇒ Boolean
192 193 194 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/discordrb/events/message.rb', line 192 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| case a when String e.start_with? a when Regexp (e =~ a)&.zero? end end, matches_all(@attributes[:ending_with] || @attributes[:end_with], event.content) do |a, e| case a when String e.end_with? a when Regexp !(e =~ Regexp.new("#{a}$")).nil? end end, matches_all(@attributes[:containing] || @attributes[:contains], event.content) do |a, e| case a when String e.include? a when Regexp (e =~ a) end end, matches_all(@attributes[:in], event.channel) do |a, e| case a when String # Make sure to remove the "#" from channel names in case it was specified a.delete('#') == e.name when Integer a == e.id else a == e end end, matches_all(@attributes[:from], event.) do |a, e| case a when String a == e.name when Integer a == e.id when :bot e.current_bot? else a == e end end, matches_all(@attributes[:with_text] || @attributes[:content] || @attributes[:exact_text], event.content) do |a, e| case a when String e == a when 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 |