Class: Discordrb::Events::EventHandler
- Inherits:
-
Object
- Object
- Discordrb::Events::EventHandler
- Defined in:
- lib/discordrb/events/generic.rb
Overview
Generic event handler that can be extended
Direct Known Subclasses
AwaitEventHandler, ChannelCreateEventHandler, ChannelDeleteEventHandler, ChannelRecipientEventHandler, MessageEventHandler, MessageIDEventHandler, PlayingEventHandler, PresenceEventHandler, ServerEventHandler, ServerMemberEventHandler, ServerRoleCreateEventHandler, ServerRoleDeleteEventHandler, TrueEventHandler, TypingEventHandler, UserBanEventHandler, VoiceStateUpdateEventHandler
Instance Method Summary collapse
-
#after_call(event) ⇒ Object
to be overwritten by extending event handlers.
-
#call(event) ⇒ Object
Calls this handler.
-
#initialize(attributes, block) ⇒ EventHandler
constructor
A new instance of EventHandler.
-
#match(event) ⇒ Object
Checks whether this handler matches the given event, and then calls it.
-
#matches?(_) ⇒ Boolean
Whether or not this event handler matches the given event with its attributes.
- #matches_all(attributes, to_check, &block) ⇒ Object
Constructor Details
#initialize(attributes, block) ⇒ EventHandler
Returns a new instance of EventHandler.
62 63 64 65 |
# File 'lib/discordrb/events/generic.rb', line 62 def initialize(attributes, block) @attributes = attributes @block = block end |
Instance Method Details
#after_call(event) ⇒ Object
to be overwritten by extending event handlers
86 |
# File 'lib/discordrb/events/generic.rb', line 86 def after_call(event); end |
#call(event) ⇒ Object
Calls this handler
81 82 83 |
# File 'lib/discordrb/events/generic.rb', line 81 def call(event) @block.call(event) end |
#match(event) ⇒ Object
Checks whether this handler matches the given event, and then calls it.
75 76 77 |
# File 'lib/discordrb/events/generic.rb', line 75 def match(event) call(event) if matches? event end |
#matches?(_) ⇒ Boolean
Whether or not this event handler matches the given event with its attributes.
69 70 71 |
# File 'lib/discordrb/events/generic.rb', line 69 def matches?(_) raise 'Attempted to call matches?() from a generic EventHandler' end |
#matches_all(attributes, to_check, &block) ⇒ Object
89 90 91 |
# File 'lib/discordrb/events/generic.rb', line 89 def matches_all(attributes, to_check, &block) Discordrb::Events.matches_all(attributes, to_check, &block) end |