Module: Discordrb::Events

Included in:
EventContainer
Defined in:
lib/discordrb/events/raw.rb,
lib/discordrb/events/bans.rb,
lib/discordrb/events/await.rb,
lib/discordrb/events/roles.rb,
lib/discordrb/events/guilds.rb,
lib/discordrb/events/typing.rb,
lib/discordrb/events/generic.rb,
lib/discordrb/events/invites.rb,
lib/discordrb/events/members.rb,
lib/discordrb/events/message.rb,
lib/discordrb/events/threads.rb,
lib/discordrb/events/channels.rb,
lib/discordrb/events/lifetime.rb,
lib/discordrb/events/presence.rb,
lib/discordrb/events/webhooks.rb,
lib/discordrb/events/reactions.rb,
lib/discordrb/events/interactions.rb,
lib/discordrb/events/voice_state_update.rb,
lib/discordrb/events/voice_server_update.rb

Overview

Events used by discordrb

Defined Under Namespace

Modules: Respondable Classes: ApplicationCommandEvent, ApplicationCommandEventHandler, AwaitEvent, AwaitEventHandler, ButtonEvent, ButtonEventHandler, ChannelCreateEvent, ChannelCreateEventHandler, ChannelDeleteEvent, ChannelDeleteEventHandler, ChannelRecipientAddEvent, ChannelRecipientAddEventHandler, ChannelRecipientEvent, ChannelRecipientEventHandler, ChannelRecipientRemoveEvent, ChannelRecipientRemoveEventHandler, ChannelSelectEvent, ChannelSelectEventHandler, ChannelUpdateEvent, ChannelUpdateEventHandler, ComponentEvent, ComponentEventHandler, DisconnectEvent, DisconnectEventHandler, Event, EventHandler, HeartbeatEvent, HeartbeatEventHandler, InteractionCreateEvent, InteractionCreateEventHandler, InviteCreateEvent, InviteCreateEventHandler, InviteDeleteEvent, InviteDeleteEventHandler, LifetimeEvent, MentionEvent, MentionEventHandler, MentionableSelectEvent, MentionableSelectEventHandler, MessageDeleteEvent, MessageDeleteEventHandler, MessageEditEvent, MessageEditEventHandler, MessageEvent, MessageEventHandler, MessageIDEvent, MessageIDEventHandler, MessageUpdateEvent, MessageUpdateEventHandler, ModalSubmitEvent, ModalSubmitEventHandler, Negated, PlayingEvent, PlayingEventHandler, PresenceEvent, PresenceEventHandler, PrivateMessageEvent, PrivateMessageEventHandler, RawEvent, RawEventHandler, ReactionAddEvent, ReactionAddEventHandler, ReactionEvent, ReactionEventHandler, ReactionRemoveAllEvent, ReactionRemoveAllEventHandler, ReactionRemoveEvent, ReactionRemoveEventHandler, ReadyEvent, ReadyEventHandler, RoleSelectEvent, RoleSelectEventHandler, ServerCreateEvent, ServerCreateEventHandler, ServerDeleteEvent, ServerDeleteEventHandler, ServerEmojiCDEvent, ServerEmojiCDEventHandler, ServerEmojiChangeEvent, ServerEmojiChangeEventHandler, ServerEmojiCreateEvent, ServerEmojiCreateEventHandler, ServerEmojiDeleteEvent, ServerEmojiDeleteEventHandler, ServerEmojiUpdateEvent, ServerEmojiUpdateEventHandler, ServerEvent, ServerEventHandler, ServerMemberAddEvent, ServerMemberAddEventHandler, ServerMemberDeleteEvent, ServerMemberDeleteEventHandler, ServerMemberEvent, ServerMemberEventHandler, ServerMemberUpdateEvent, ServerMemberUpdateEventHandler, ServerRoleCreateEvent, ServerRoleCreateEventHandler, ServerRoleDeleteEvent, ServerRoleDeleteEventHandler, ServerRoleUpdateEvent, ServerRoleUpdateEventHandler, ServerUpdateEvent, ServerUpdateEventHandler, StringSelectEvent, StringSelectEventHandler, SubcommandBuilder, ThreadCreateEvent, ThreadCreateEventHandler, ThreadMembersUpdateEvent, ThreadMembersUpdateEventHandler, ThreadUpdateEvent, ThreadUpdateEventHandler, TrueEventHandler, TypingEvent, TypingEventHandler, UnknownEvent, UnknownEventHandler, UserBanEvent, UserBanEventHandler, UserSelectEvent, UserSelectEventHandler, UserUnbanEvent, UserUnbanEventHandler, VoiceServerUpdateEvent, VoiceServerUpdateEventHandler, VoiceStateUpdateEvent, VoiceStateUpdateEventHandler, WebhookUpdateEvent, WebhookUpdateEventHandler

Class Method Summary collapse

Class Method Details

.matches_all(attributes, to_check) {|a, e| ... } ⇒ true, false

Attempts to match possible formats of event attributes to a set comparison value, using a comparison block. It allows five kinds of attribute formats:

  1. nil -> always returns true
  2. A single attribute, not negated
  3. A single attribute, negated
  4. An array of attributes, not negated
  5. An array of attributes, not negated Note that it doesn't allow an array of negated attributes. For info on negation stuff, see #not!

Parameters:

  • attributes (Object, Array<Object>, Negated<Object>, Negated<Array<Object>>, nil)

    One or more attributes to compare to the to_check value.

  • to_check (Object)

    What to compare the attributes to.

Yields:

  • (a, e)

    The block will be called when a comparison happens.

Yield Parameters:

  • a (Object)

    The attribute to compare to the value to check. Will always be a single not-negated object, all the negation and array handling is done by the method

  • e (Object)

    The value to compare the attribute to. Will always be the value passed to the function as to_check.

Yield Returns:

  • (true, false)

    Whether or not the attribute a matches the given comparison value e.

Returns:

  • (true, false)

    whether the attributes match the comparison value in at least one way.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/discordrb/events/generic.rb', line 33

def self.matches_all(attributes, to_check, &block)
  # "Zeroth" case: attributes is nil
  return true if attributes.nil?

  # First case: there's a single negated attribute
  if attributes.is_a? Negated
    # The contained object might also be an array, so recursively call matches_all (and negate the result)
    return !matches_all(attributes.object, to_check, &block)
  end

  # Second case: there's a single, not-negated attribute
  return yield(attributes, to_check) unless attributes.is_a? Array

  # Third case: it's an array of attributes
  attributes.reduce(false) do |result, element|
    result || yield(element, to_check)
  end
end