Module: OnyxCord::EventContainer
- Includes:
- Events
- Included in:
- Bot
- Defined in:
- lib/onyxcord/container.rb,
lib/onyxcord/events/handlers/raw.rb,
lib/onyxcord/events/handlers/core.rb,
lib/onyxcord/events/handlers/voice.rb,
lib/onyxcord/events/handlers/guilds.rb,
lib/onyxcord/events/handlers/channels.rb,
lib/onyxcord/events/handlers/lifetime.rb,
lib/onyxcord/events/handlers/messages.rb,
lib/onyxcord/events/handlers/presence.rb,
lib/onyxcord/events/handlers/reactions.rb,
lib/onyxcord/events/handlers/interactions.rb,
lib/onyxcord/events/handlers/scheduled_events.rb
Overview
This module provides the functionality required for events and awaits. It is separated from the Bot class so users can make their own container modules and include them.
Class Method Summary collapse
-
.class_from_string(str) ⇒ Class
Utility method to return a class object from a string of its name.
-
.event_class(handler_class) ⇒ Class?
Returns the event class for a handler class type.
-
.handler_class(event_class) ⇒ Class
Returns the handler class for an event class type.
Instance Method Summary collapse
-
#add_handler(handler) ⇒ Object
(also: #<<)
Adds an event handler to this container.
-
#application_command(name, attributes = {}) {|event| ... } ⇒ ApplicationCommandEventHandler
This event is raised whenever an application command (slash command) is executed.
-
#application_command_permissions_update(attributes = {}) {|event| ... } ⇒ ApplicationCommandPermissionsUpdateEventHandler
This event is raised whenever an application command's permissions are updated.
-
#audit_log_entry(attributes = {}) {|event| ... } ⇒ AuditLogEntryCreateEventHandler
This event is raised whenever an audit log entry is created in a server.
-
#autocomplete(name = nil, attributes = {}) {|event| ... } ⇒ AutocompleteEventHandler
This event is raised whenever an autocomplete interaction is created.
-
#await(attributes = {}) {|event| ... } ⇒ AwaitEventHandler
This event is raised when an Await is triggered.
-
#button(attributes = {}) {|event| ... } ⇒ ButtonEventHandler
This event is raised whenever an button interaction is created.
-
#channel_create(attributes = {}) {|event| ... } ⇒ ChannelCreateEventHandler
This event is raised when a channel is created.
-
#channel_delete(attributes = {}) {|event| ... } ⇒ ChannelDeleteEventHandler
This event is raised when a channel is deleted.
-
#channel_pins_update(attributes = {}) {|event| ... } ⇒ ChannelPinsUpdateEventHandler
This event is raised whenever a message is pinned or unpinned.
-
#channel_recipient_add(attributes = {}) {|event| ... } ⇒ ChannelRecipientAddHandler
This event is raised when a recipient is added to a group channel.
-
#channel_recipient_remove(attributes = {}) {|event| ... } ⇒ ChannelRecipientRemoveHandler
This event is raised when a recipient is removed from a group channel.
-
#channel_select(attributes = {}) {|event| ... } ⇒ ChannelSelectEventHandler
This event is raised whenever an select channel interaction is created.
-
#channel_update(attributes = {}) {|event| ... } ⇒ ChannelUpdateEventHandler
This event is raised when a channel is updated.
-
#clear! ⇒ Object
Removes all events from this event handler.
-
#disconnected(attributes = {}) {|event| ... } ⇒ DisconnectEventHandler
This event is raised when the bot has disconnected from the WebSocket, due to the Bot::Runtime#stop method or external causes.
-
#heartbeat(attributes = {}) {|event| ... } ⇒ HeartbeatEventHandler
This event is raised every time the bot sends a heartbeat over the galaxy.
-
#include_events(container) ⇒ Object
(also: #include!)
Adds all event handlers from another container into this one.
-
#integration_create(attributes = {}) {|event| ... } ⇒ IntegrationCreateEventHandler
This event is raised whenever an integration is added to a server.
-
#integration_delete(attributes = {}) {|event| ... } ⇒ IntegrationDeleteEventHandler
This event is raised whenever an integration is removed from a server.
-
#integration_update(attributes = {}) {|event| ... } ⇒ IntegrationUpdateEventHandler
This event is raised whenever an integration is updated in a server.
-
#interaction_create(attributes = {}) {|event| ... } ⇒ InteractionCreateEventHandler
This event is raised whenever an interaction event is received.
-
#invite_create(attributes = {}) {|event| ... } ⇒ InviteCreateEventHandler
This event is raised when an invite is created.
-
#invite_delete(attributes = {}) {|event| ... } ⇒ InviteDeleteEventHandler
This event is raised when an invite is deleted.
-
#member_join(attributes = {}) {|event| ... } ⇒ ServerMemberAddEventHandler
This event is raised when a new user joins a server.
-
#member_leave(attributes = {}) {|event| ... } ⇒ ServerMemberDeleteEventHandler
This event is raised when a member leaves a server.
-
#member_update(attributes = {}) {|event| ... } ⇒ ServerMemberUpdateEventHandler
This event is raised when a member update happens.
-
#mention(attributes = {}) {|event| ... } ⇒ MentionEventHandler
This event is raised when the bot is mentioned in a message.
-
#mentionable_select(attributes = {}) {|event| ... } ⇒ MentionableSelectEventHandler
This event is raised whenever an select mentionable interaction is created.
-
#message(attributes = {}) {|event| ... } ⇒ MessageEventHandler
This event is raised when a message is sent to a text channel the bot is currently in.
-
#message_delete(attributes = {}) {|event| ... } ⇒ MessageDeleteEventHandler
This event is raised when a message is deleted in a channel.
-
#message_edit(attributes = {}) {|event| ... } ⇒ MessageEditEventHandler
This event is raised when a message is edited in a channel.
-
#message_update(attributes = {}) {|event| ... } ⇒ MessageUpdateEventHandler
This event is raised whenever a message is updated.
-
#modal_submit(attributes = {}) {|event| ... } ⇒ ModalSubmitEventHandler
This event is raised whenever a modal is submitted.
-
#playing(attributes = {}) {|event| ... } ⇒ PlayingEventHandler
This event is raised when the game a user is playing changes.
-
#pm(attributes = {}) {|event| ... } ⇒ PrivateMessageEventHandler
(also: #private_message, #direct_message, #dm)
This event is raised when a private message is sent to the bot.
-
#poll_vote_add(attributes = {}) {|event| ... } ⇒ PollVoteAddEventHandler
This event is raised whenever a user votes on a poll.
-
#poll_vote_remove(attributes = {}) {|event| ... } ⇒ PollVoteRemoveEventHandler
This event is raised whenever a user removes their vote on a poll.
-
#presence(attributes = {}) {|event| ... } ⇒ PresenceEventHandler
This event is raised when a user's status (online/offline/idle) changes.
-
#raw(filter = nil) {|event| ... } ⇒ RawEventHandler
This event is raised for every dispatch received over the gateway, whether supported by onyxcord or not.
-
#reaction_add(attributes = {}) {|event| ... } ⇒ ReactionAddEventHandler
This event is raised when somebody reacts to a message.
-
#reaction_remove(attributes = {}) {|event| ... } ⇒ ReactionRemoveEventHandler
This event is raised when somebody removes a reaction from a message.
-
#reaction_remove_all(attributes = {}) {|event| ... } ⇒ ReactionRemoveAllEventHandler
This event is raised when somebody removes all reactions from a message.
-
#reaction_remove_emoji(attributes = {}) {|event| ... } ⇒ ReactionRemoveEmojiEventHandler
This event is raised when somebody removes all instances of a single reaction from a message.
-
#ready(attributes = {}) {|event| ... } ⇒ ReadyEventHandler
This event is raised when the READY packet is received, i.e.
-
#remove_application_command_handler(name) ⇒ Object
Remove an application command handler.
-
#remove_handler(handler) ⇒ Object
Removes an event handler from this container.
-
#role_select(attributes = {}) {|event| ... } ⇒ RoleSelectEventHandler
This event is raised whenever an select role interaction is created.
-
#scheduled_event_create(attributes = {}) {|event| ... } ⇒ ScheduledEventCreateEventHandler
This event is raised when a scheduled event is created.
-
#scheduled_event_delete(attributes = {}) {|event| ... } ⇒ ScheduledEventDeleteEventHandler
This event is raised when a scheduled event is deleted.
-
#scheduled_event_update(attributes = {}) {|event| ... } ⇒ ScheduledEventUpdateEventHandler
This event is raised when a scheduled event is updated.
-
#scheduled_event_user_add(attributes = {}) {|event| ... } ⇒ ScheduledEventUserAddEventHandler
This event is raised when a user is added to a scheduled event.
-
#scheduled_event_user_remove(attributes = {}) {|event| ... } ⇒ ScheduledEventUserRemoveEventHandler
This event is raised when a user is removed from a scheduled event.
-
#server_create(attributes = {}) {|event| ... } ⇒ ServerCreateEventHandler
This event is raised when a server is created respective to the bot, i.e.
-
#server_delete(attributes = {}) {|event| ... } ⇒ ServerDeleteEventHandler
This event is raised when a server is deleted, or when the bot leaves a server.
-
#server_emoji(attributes = {}) {|event| ... } ⇒ ServerEmojiChangeEventHandler
This event is raised when an emoji or collection of emojis is created/deleted/updated.
-
#server_emoji_create(attributes = {}) {|event| ... } ⇒ ServerEmojiCreateEventHandler
This event is raised when an emoji is created.
-
#server_emoji_delete(attributes = {}) {|event| ... } ⇒ ServerEmojiDeleteEventHandler
This event is raised when an emoji is deleted.
-
#server_emoji_update(attributes = {}) {|event| ... } ⇒ ServerEmojiUpdateEventHandler
This event is raised when an emoji is updated.
-
#server_role_create(attributes = {}) {|event| ... } ⇒ ServerRoleCreateEventHandler
This event is raised when a role is created.
-
#server_role_delete(attributes = {}) {|event| ... } ⇒ ServerRoleDeleteEventHandler
This event is raised when a role is deleted.
-
#server_role_update(attributes = {}) {|event| ... } ⇒ ServerRoleUpdateEventHandler
This event is raised when a role is updated.
-
#server_update(attributes = {}) {|event| ... } ⇒ ServerUpdateEventHandler
This event is raised when a server is updated, for example if the name or region has changed.
-
#string_select(attributes = {}) {|event| ... } ⇒ StringSelectEventHandler
(also: #select_menu)
This event is raised whenever an select string interaction is created.
-
#typing(attributes = {}) {|event| ... } ⇒ TypingEventHandler
This event is raised when somebody starts typing in a channel the bot is also in.
-
#unknown(attributes = {}) {|event| ... } ⇒ UnknownEventHandler
This event is raised for a dispatch received over the gateway that is not currently handled otherwise by onyxcord.
-
#user_ban(attributes = {}) {|event| ... } ⇒ UserBanEventHandler
This event is raised when a user is banned from a server.
-
#user_select(attributes = {}) {|event| ... } ⇒ UserSelectEventHandler
This event is raised whenever an select user interaction is created.
-
#user_unban(attributes = {}) {|event| ... } ⇒ UserUnbanEventHandler
This event is raised when a user is unbanned from a server.
-
#voice_server_update(attributes = {}) {|event| ... } ⇒ VoiceServerUpdateEventHandler
This event is raised when first connecting to a server's voice channel.
-
#voice_state_update(attributes = {}) {|event| ... } ⇒ VoiceStateUpdateEventHandler
This event is raised when a user's voice state changes.
-
#webhook_update(attributes = {}) {|event| ... } ⇒ WebhookUpdateEventHandler
This event is raised when a webhook is updated.
Methods included from Events
Class Method Details
.class_from_string(str) ⇒ Class
Utility method to return a class object from a string of its name. Mostly useful for internal stuff
115 116 117 118 119 |
# File 'lib/onyxcord/events/handlers/core.rb', line 115 def self.class_from_string(str) str.split('::').inject(Object) do |mod, class_name| mod.const_get(class_name) end end |
.event_class(handler_class) ⇒ Class?
Returns the event class for a handler class type
101 102 103 104 105 106 |
# File 'lib/onyxcord/events/handlers/core.rb', line 101 def self.event_class(handler_class) class_name = handler_class.to_s return nil unless class_name.end_with? 'Handler' EventContainer.class_from_string(class_name[0..-8]) end |
.handler_class(event_class) ⇒ Class
Returns the handler class for an event class type
88 89 90 |
# File 'lib/onyxcord/events/handlers/core.rb', line 88 def self.handler_class(event_class) class_from_string("#{event_class}Handler") end |
Instance Method Details
#add_handler(handler) ⇒ Object Also known as: <<
Adds an event handler to this container. Usually, it's more expressive to just use one of the shorthand adder methods like #message, but if you want to create one manually you can use this.
44 45 46 47 48 49 |
# File 'lib/onyxcord/events/handlers/core.rb', line 44 def add_handler(handler) clazz = EventContainer.event_class(handler.class) @event_handlers ||= {} @event_handlers[clazz] ||= [] @event_handlers[clazz] << handler end |
#application_command(name, attributes = {}) {|event| ... } ⇒ ApplicationCommandEventHandler
This event is raised whenever an application command (slash command) is executed.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 32 def application_command(name, attributes = {}, &block) name = name.to_sym @application_commands ||= {} unless block @application_commands[name] ||= ApplicationCommandEventHandler.new(attributes, nil) return @application_commands[name] end @application_commands[name] = ApplicationCommandEventHandler.new(attributes, block) end |
#application_command_permissions_update(attributes = {}) {|event| ... } ⇒ ApplicationCommandPermissionsUpdateEventHandler
This event is raised whenever an application command's permissions are updated.
223 224 225 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 223 def (attributes = {}, &block) register_event(ApplicationCommandPermissionsUpdateEvent, attributes, block) end |
#audit_log_entry(attributes = {}) {|event| ... } ⇒ AuditLogEntryCreateEventHandler
This event is raised whenever an audit log entry is created in a server.
91 92 93 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 91 def audit_log_entry(attributes = {}, &block) register_event(AuditLogEntryCreateEvent, attributes, block) end |
#autocomplete(name = nil, attributes = {}) {|event| ... } ⇒ AutocompleteEventHandler
This event is raised whenever an autocomplete interaction is created.
202 203 204 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 202 def autocomplete(name = nil, attributes = {}, &block) register_event(AutocompleteEvent, attributes.merge!({ name: name&.to_s }), block) end |
#await(attributes = {}) {|event| ... } ⇒ AwaitEventHandler
This event is raised when an Await is triggered. It provides an easy way to execute code on an await without having to rely on the await's block.
199 200 201 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 199 def await(attributes = {}, &block) register_event(AwaitEvent, attributes, block) end |
#button(attributes = {}) {|event| ... } ⇒ ButtonEventHandler
This event is raised whenever an button interaction is created.
59 60 61 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 59 def (attributes = {}, &block) register_event(ButtonEvent, attributes, block) end |
#channel_create(attributes = {}) {|event| ... } ⇒ ChannelCreateEventHandler
This event is raised when a channel is created.
12 13 14 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 12 def channel_create(attributes = {}, &block) register_event(ChannelCreateEvent, attributes, block) end |
#channel_delete(attributes = {}) {|event| ... } ⇒ ChannelDeleteEventHandler
This event is raised when a channel is deleted.
50 51 52 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 50 def channel_delete(attributes = {}, &block) register_event(ChannelDeleteEvent, attributes, block) end |
#channel_pins_update(attributes = {}) {|event| ... } ⇒ ChannelPinsUpdateEventHandler
This event is raised whenever a message is pinned or unpinned.
117 118 119 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 117 def channel_pins_update(attributes = {}, &block) register_event(ChannelPinsUpdateEvent, attributes, block) end |
#channel_recipient_add(attributes = {}) {|event| ... } ⇒ ChannelRecipientAddHandler
This event is raised when a recipient is added to a group channel.
71 72 73 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 71 def channel_recipient_add(attributes = {}, &block) register_event(ChannelRecipientAddEvent, attributes, block) end |
#channel_recipient_remove(attributes = {}) {|event| ... } ⇒ ChannelRecipientRemoveHandler
This event is raised when a recipient is removed from a group channel.
92 93 94 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 92 def channel_recipient_remove(attributes = {}, &block) register_event(ChannelRecipientRemoveEvent, attributes, block) end |
#channel_select(attributes = {}) {|event| ... } ⇒ ChannelSelectEventHandler
This event is raised whenever an select channel interaction is created.
179 180 181 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 179 def channel_select(attributes = {}, &block) register_event(ChannelSelectEvent, attributes, block) end |
#channel_update(attributes = {}) {|event| ... } ⇒ ChannelUpdateEventHandler
This event is raised when a channel is updated.
31 32 33 |
# File 'lib/onyxcord/events/handlers/channels.rb', line 31 def channel_update(attributes = {}, &block) register_event(ChannelUpdateEvent, attributes, block) end |
#clear! ⇒ Object
Removes all events from this event handler.
31 32 33 34 35 |
# File 'lib/onyxcord/events/handlers/core.rb', line 31 def clear! @event_handlers&.clear @raw_handlers&.clear @application_commands&.clear end |
#disconnected(attributes = {}) {|event| ... } ⇒ DisconnectEventHandler
This event is raised when the bot has disconnected from the WebSocket, due to the Bot::Runtime#stop method or external causes. It's the recommended way to do clean-up tasks.
28 29 30 |
# File 'lib/onyxcord/events/handlers/lifetime.rb', line 28 def disconnected(attributes = {}, &block) register_event(DisconnectEvent, attributes, block) end |
#heartbeat(attributes = {}) {|event| ... } ⇒ HeartbeatEventHandler
This event is raised every time the bot sends a heartbeat over the galaxy. This happens roughly every 40 seconds, but may happen at a lower rate should Discord change their interval. It may also happen more quickly for periods of time, especially for unstable connections, since onyxcord rather sends a heartbeat than not if there's a choice. (You shouldn't rely on all this to be accurately timed.)
All this makes this event useful to periodically trigger something, like doing some API request every hour, setting some kind of uptime variable or whatever else. The only limit is yourself.
55 56 57 |
# File 'lib/onyxcord/events/handlers/lifetime.rb', line 55 def heartbeat(attributes = {}, &block) register_event(HeartbeatEvent, attributes, block) end |
#include_events(container) ⇒ Object Also known as: include!
Adds all event handlers from another container into this one. Existing event handlers will be overwritten.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/onyxcord/events/handlers/core.rb', line 56 def include_events(container) application_command_handlers = container.instance_variable_get(:@application_commands) handlers = container.instance_variable_get :@event_handlers raw_handlers = container.instance_variable_get(:@raw_handlers) return unless handlers || application_command_handlers || raw_handlers @event_handlers ||= {} @event_handlers.merge!(handlers || {}) { |_, old, new| old + new } @raw_handlers ||= [] @raw_handlers.concat(raw_handlers || []) @application_commands ||= {} @application_commands.merge!(application_command_handlers || {}) do |_, old, new| old.subcommands.merge!(new.subcommands) old end end |
#integration_create(attributes = {}) {|event| ... } ⇒ IntegrationCreateEventHandler
This event is raised whenever an integration is added to a server.
190 191 192 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 190 def integration_create(attributes = {}, &block) register_event(IntegrationCreateEvent, attributes, block) end |
#integration_delete(attributes = {}) {|event| ... } ⇒ IntegrationDeleteEventHandler
This event is raised whenever an integration is removed from a server.
232 233 234 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 232 def integration_delete(attributes = {}, &block) register_event(IntegrationDeleteEvent, attributes, block) end |
#integration_update(attributes = {}) {|event| ... } ⇒ IntegrationUpdateEventHandler
This event is raised whenever an integration is updated in a server.
211 212 213 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 211 def integration_update(attributes = {}, &block) register_event(IntegrationUpdateEvent, attributes, block) end |
#interaction_create(attributes = {}) {|event| ... } ⇒ InteractionCreateEventHandler
This event is raised whenever an interaction event is received.
15 16 17 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 15 def interaction_create(attributes = {}, &block) register_event(InteractionCreateEvent, attributes, block) end |
#invite_create(attributes = {}) {|event| ... } ⇒ InviteCreateEventHandler
This event is raised when an invite is created.
341 342 343 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 341 def invite_create(attributes = {}, &block) register_event(InviteCreateEvent, attributes, block) end |
#invite_delete(attributes = {}) {|event| ... } ⇒ InviteDeleteEventHandler
This event is raised when an invite is deleted.
360 361 362 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 360 def invite_delete(attributes = {}, &block) register_event(InviteDeleteEvent, attributes, block) end |
#member_join(attributes = {}) {|event| ... } ⇒ ServerMemberAddEventHandler
This event is raised when a new user joins a server.
11 12 13 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 11 def member_join(attributes = {}, &block) register_event(ServerMemberAddEvent, attributes, block) end |
#member_leave(attributes = {}) {|event| ... } ⇒ ServerMemberDeleteEventHandler
This event is raised when a member leaves a server.
47 48 49 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 47 def member_leave(attributes = {}, &block) register_event(ServerMemberDeleteEvent, attributes, block) end |
#member_update(attributes = {}) {|event| ... } ⇒ ServerMemberUpdateEventHandler
This event is raised when a member update happens. This includes when a members nickname or roles are updated.
30 31 32 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 30 def member_update(attributes = {}, &block) register_event(ServerMemberUpdateEvent, attributes, block) end |
#mention(attributes = {}) {|event| ... } ⇒ MentionEventHandler
This event is raised when the bot is mentioned in a message.
147 148 149 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 147 def mention(attributes = {}, &block) register_event(MentionEvent, attributes, block) end |
#mentionable_select(attributes = {}) {|event| ... } ⇒ MentionableSelectEventHandler
This event is raised whenever an select mentionable interaction is created.
160 161 162 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 160 def mentionable_select(attributes = {}, &block) register_event(MentionableSelectEvent, attributes, block) end |
#message(attributes = {}) {|event| ... } ⇒ MessageEventHandler
This event is raised when a message is sent to a text channel the bot is currently in.
21 22 23 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 21 def (attributes = {}, &block) register_event(MessageEvent, attributes, block) end |
#message_delete(attributes = {}) {|event| ... } ⇒ MessageDeleteEventHandler
This event is raised when a message is deleted in a channel.
87 88 89 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 87 def (attributes = {}, &block) register_event(MessageDeleteEvent, attributes, block) end |
#message_edit(attributes = {}) {|event| ... } ⇒ MessageEditEventHandler
This event is raised when a message is edited in a channel.
66 67 68 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 66 def (attributes = {}, &block) register_event(MessageEditEvent, attributes, block) end |
#message_update(attributes = {}) {|event| ... } ⇒ MessageUpdateEventHandler
This event is raised whenever a message is updated. Message updates can be triggered from a user editing their own message, or from Discord automatically attaching embeds to the user's message for URLs contained in the message's content. If you only want to listen for users editing their own messages, use the #message_edit handler instead.
116 117 118 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 116 def (attributes = {}, &block) register_event(MessageUpdateEvent, attributes, block) end |
#modal_submit(attributes = {}) {|event| ... } ⇒ ModalSubmitEventHandler
This event is raised whenever a modal is submitted.
103 104 105 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 103 def modal_submit(attributes = {}, &block) register_event(ModalSubmitEvent, attributes, block) end |
#playing(attributes = {}) {|event| ... } ⇒ PlayingEventHandler
This event is raised when the game a user is playing changes.
35 36 37 |
# File 'lib/onyxcord/events/handlers/presence.rb', line 35 def (attributes = {}, &block) register_event(PlayingEvent, attributes, block) end |
#pm(attributes = {}) {|event| ... } ⇒ PrivateMessageEventHandler Also known as: private_message, direct_message, dm
This event is raised when a private message is sent to the bot.
173 174 175 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 173 def pm(attributes = {}, &block) register_event(PrivateMessageEvent, attributes, block) end |
#poll_vote_add(attributes = {}) {|event| ... } ⇒ PollVoteAddEventHandler
This event is raised whenever a user votes on a poll.
15 16 17 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 15 def poll_vote_add(attributes = {}, &block) register_event(PollVoteAddEvent, attributes, block) end |
#poll_vote_remove(attributes = {}) {|event| ... } ⇒ PollVoteRemoveEventHandler
This event is raised whenever a user removes their vote on a poll.
40 41 42 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 40 def poll_vote_remove(attributes = {}, &block) register_event(PollVoteRemoveEvent, attributes, block) end |
#presence(attributes = {}) {|event| ... } ⇒ PresenceEventHandler
This event is raised when a user's status (online/offline/idle) changes.
14 15 16 |
# File 'lib/onyxcord/events/handlers/presence.rb', line 14 def presence(attributes = {}, &block) register_event(PresenceEvent, attributes, block) end |
#raw(filter = nil) {|event| ... } ⇒ RawEventHandler
This event is raised for every dispatch received over the gateway, whether supported by onyxcord or not.
11 12 13 14 |
# File 'lib/onyxcord/events/handlers/raw.rb', line 11 def raw(filter = nil, &block) filter = filter[:type] || filter[:t] if filter.is_a?(Hash) register_raw_handler(filter, block) end |
#reaction_add(attributes = {}) {|event| ... } ⇒ ReactionAddEventHandler
This event is raised when somebody reacts to a message.
15 16 17 |
# File 'lib/onyxcord/events/handlers/reactions.rb', line 15 def reaction_add(attributes = {}, &block) register_event(ReactionAddEvent, attributes, block) end |
#reaction_remove(attributes = {}) {|event| ... } ⇒ ReactionRemoveEventHandler
This event is raised when somebody removes a reaction from a message.
42 43 44 |
# File 'lib/onyxcord/events/handlers/reactions.rb', line 42 def reaction_remove(attributes = {}, &block) register_event(ReactionRemoveEvent, attributes, block) end |
#reaction_remove_all(attributes = {}) {|event| ... } ⇒ ReactionRemoveAllEventHandler
This event is raised when somebody removes all reactions from a message.
63 64 65 |
# File 'lib/onyxcord/events/handlers/reactions.rb', line 63 def reaction_remove_all(attributes = {}, &block) register_event(ReactionRemoveAllEvent, attributes, block) end |
#reaction_remove_emoji(attributes = {}) {|event| ... } ⇒ ReactionRemoveEmojiEventHandler
This event is raised when somebody removes all instances of a single reaction from a message.
84 85 86 |
# File 'lib/onyxcord/events/handlers/reactions.rb', line 84 def reaction_remove_emoji(attributes = {}, &block) register_event(ReactionRemoveEmojiEvent, attributes, block) end |
#ready(attributes = {}) {|event| ... } ⇒ ReadyEventHandler
This event is raised when the READY packet is received, i.e. servers and channels have finished initialization. It's the recommended way to do things when the bot has finished starting up.
11 12 13 |
# File 'lib/onyxcord/events/handlers/lifetime.rb', line 11 def ready(attributes = {}, &block) register_event(ReadyEvent, attributes, block) end |
#remove_application_command_handler(name) ⇒ Object
Remove an application command handler
24 25 26 |
# File 'lib/onyxcord/events/handlers/core.rb', line 24 def remove_application_command_handler(name) @application_commands.delete(name) end |
#remove_handler(handler) ⇒ Object
Removes an event handler from this container. If you're looking for a way to do temporary events, I recommend Awaits instead of this.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/onyxcord/events/handlers/core.rb', line 8 def remove_handler(handler) if handler.is_a?(OnyxCord::Events::RawDispatchHandler) @raw_handlers&.delete(handler) return end clazz = EventContainer.event_class(handler.class) @event_handlers ||= {} @event_handlers[clazz].delete(handler) end |
#role_select(attributes = {}) {|event| ... } ⇒ RoleSelectEventHandler
This event is raised whenever an select role interaction is created.
141 142 143 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 141 def role_select(attributes = {}, &block) register_event(RoleSelectEvent, attributes, block) end |
#scheduled_event_create(attributes = {}) {|event| ... } ⇒ ScheduledEventCreateEventHandler
This event is raised when a scheduled event is created.
69 70 71 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 69 def scheduled_event_create(attributes = {}, &block) register_event(ScheduledEventCreateEvent, attributes, block) end |
#scheduled_event_delete(attributes = {}) {|event| ... } ⇒ ScheduledEventDeleteEventHandler
This event is raised when a scheduled event is deleted.
127 128 129 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 127 def scheduled_event_delete(attributes = {}, &block) register_event(ScheduledEventDeleteEvent, attributes, block) end |
#scheduled_event_update(attributes = {}) {|event| ... } ⇒ ScheduledEventUpdateEventHandler
This event is raised when a scheduled event is updated.
98 99 100 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 98 def scheduled_event_update(attributes = {}, &block) register_event(ScheduledEventUpdateEvent, attributes, block) end |
#scheduled_event_user_add(attributes = {}) {|event| ... } ⇒ ScheduledEventUserAddEventHandler
This event is raised when a user is added to a scheduled event.
148 149 150 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 148 def scheduled_event_user_add(attributes = {}, &block) register_event(ScheduledEventUserAddEvent, attributes, block) end |
#scheduled_event_user_remove(attributes = {}) {|event| ... } ⇒ ScheduledEventUserRemoveEventHandler
This event is raised when a user is removed from a scheduled event.
169 170 171 |
# File 'lib/onyxcord/events/handlers/scheduled_events.rb', line 169 def scheduled_event_user_remove(attributes = {}, &block) register_event(ScheduledEventUserRemoveEvent, attributes, block) end |
#server_create(attributes = {}) {|event| ... } ⇒ ServerCreateEventHandler
This event is raised when a server is created respective to the bot, i.e. the bot joins a server or creates a new one itself.
129 130 131 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 129 def server_create(attributes = {}, &block) register_event(ServerCreateEvent, attributes, block) end |
#server_delete(attributes = {}) {|event| ... } ⇒ ServerDeleteEventHandler
This event is raised when a server is deleted, or when the bot leaves a server. (These two cases are identical to Discord.)
165 166 167 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 165 def server_delete(attributes = {}, &block) register_event(ServerDeleteEvent, attributes, block) end |
#server_emoji(attributes = {}) {|event| ... } ⇒ ServerEmojiChangeEventHandler
This event is raised when an emoji or collection of emojis is created/deleted/updated.
182 183 184 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 182 def server_emoji(attributes = {}, &block) register_event(ServerEmojiChangeEvent, attributes, block) end |
#server_emoji_create(attributes = {}) {|event| ... } ⇒ ServerEmojiCreateEventHandler
This event is raised when an emoji is created.
203 204 205 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 203 def server_emoji_create(attributes = {}, &block) register_event(ServerEmojiCreateEvent, attributes, block) end |
#server_emoji_delete(attributes = {}) {|event| ... } ⇒ ServerEmojiDeleteEventHandler
This event is raised when an emoji is deleted.
224 225 226 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 224 def server_emoji_delete(attributes = {}, &block) register_event(ServerEmojiDeleteEvent, attributes, block) end |
#server_emoji_update(attributes = {}) {|event| ... } ⇒ ServerEmojiUpdateEventHandler
This event is raised when an emoji is updated.
247 248 249 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 247 def server_emoji_update(attributes = {}, &block) register_event(ServerEmojiUpdateEvent, attributes, block) end |
#server_role_create(attributes = {}) {|event| ... } ⇒ ServerRoleCreateEventHandler
This event is raised when a role is created.
264 265 266 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 264 def server_role_create(attributes = {}, &block) register_event(ServerRoleCreateEvent, attributes, block) end |
#server_role_delete(attributes = {}) {|event| ... } ⇒ ServerRoleDeleteEventHandler
This event is raised when a role is deleted.
281 282 283 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 281 def server_role_delete(attributes = {}, &block) register_event(ServerRoleDeleteEvent, attributes, block) end |
#server_role_update(attributes = {}) {|event| ... } ⇒ ServerRoleUpdateEventHandler
This event is raised when a role is updated.
298 299 300 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 298 def server_role_update(attributes = {}, &block) register_event(ServerRoleUpdateEvent, attributes, block) end |
#server_update(attributes = {}) {|event| ... } ⇒ ServerUpdateEventHandler
This event is raised when a server is updated, for example if the name or region has changed.
146 147 148 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 146 def server_update(attributes = {}, &block) register_event(ServerUpdateEvent, attributes, block) end |
#string_select(attributes = {}) {|event| ... } ⇒ StringSelectEventHandler Also known as:
This event is raised whenever an select string interaction is created.
78 79 80 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 78 def string_select(attributes = {}, &block) register_event(StringSelectEvent, attributes, block) end |
#typing(attributes = {}) {|event| ... } ⇒ TypingEventHandler
This event is raised when somebody starts typing in a channel the bot is also in. The official Discord client would display the typing indicator for five seconds after receiving this event. If the user continues typing after five seconds, the event will be re-raised.
43 44 45 |
# File 'lib/onyxcord/events/handlers/messages.rb', line 43 def typing(attributes = {}, &block) register_event(TypingEvent, attributes, block) end |
#unknown(attributes = {}) {|event| ... } ⇒ UnknownEventHandler
This event is raised for a dispatch received over the gateway that is not currently handled otherwise by onyxcord.
31 32 33 |
# File 'lib/onyxcord/events/handlers/raw.rb', line 31 def unknown(attributes = {}, &block) register_event(UnknownEvent, attributes, block) end |
#user_ban(attributes = {}) {|event| ... } ⇒ UserBanEventHandler
This event is raised when a user is banned from a server.
66 67 68 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 66 def user_ban(attributes = {}, &block) register_event(UserBanEvent, attributes, block) end |
#user_select(attributes = {}) {|event| ... } ⇒ UserSelectEventHandler
This event is raised whenever an select user interaction is created.
122 123 124 |
# File 'lib/onyxcord/events/handlers/interactions.rb', line 122 def user_select(attributes = {}, &block) register_event(UserSelectEvent, attributes, block) end |
#user_unban(attributes = {}) {|event| ... } ⇒ UserUnbanEventHandler
This event is raised when a user is unbanned from a server.
110 111 112 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 110 def user_unban(attributes = {}, &block) register_event(UserUnbanEvent, attributes, block) end |
#voice_server_update(attributes = {}) {|event| ... } ⇒ VoiceServerUpdateEventHandler
This event is raised when first connecting to a server's voice channel.
35 36 37 |
# File 'lib/onyxcord/events/handlers/voice.rb', line 35 def voice_server_update(attributes = {}, &block) register_event(VoiceServerUpdateEvent, attributes, block) end |
#voice_state_update(attributes = {}) {|event| ... } ⇒ VoiceStateUpdateEventHandler
This event is raised when a user's voice state changes. This includes when a user joins, leaves, or moves between voice channels, as well as their mute and deaf status for themselves and on the server.
18 19 20 |
# File 'lib/onyxcord/events/handlers/voice.rb', line 18 def voice_state_update(attributes = {}, &block) register_event(VoiceStateUpdateEvent, attributes, block) end |
#webhook_update(attributes = {}) {|event| ... } ⇒ WebhookUpdateEventHandler
This event is raised when a webhook is updated.
319 320 321 |
# File 'lib/onyxcord/events/handlers/guilds.rb', line 319 def webhook_update(attributes = {}, &block) register_event(WebhookUpdateEvent, attributes, block) end |