rubycord 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rubycord/allowed_mentions.rb +34 -0
- data/lib/rubycord/api/application.rb +200 -0
- data/lib/rubycord/api/channel.rb +597 -0
- data/lib/rubycord/api/interaction.rb +52 -0
- data/lib/rubycord/api/invite.rb +42 -0
- data/lib/rubycord/api/server.rb +557 -0
- data/lib/rubycord/api/user.rb +153 -0
- data/lib/rubycord/api/webhook.rb +138 -0
- data/lib/rubycord/api.rb +356 -0
- data/lib/rubycord/await.rb +49 -0
- data/lib/rubycord/bot.rb +1757 -0
- data/lib/rubycord/cache.rb +259 -0
- data/lib/rubycord/colour_rgb.rb +41 -0
- data/lib/rubycord/commands/command_bot.rb +519 -0
- data/lib/rubycord/commands/container.rb +110 -0
- data/lib/rubycord/commands/events.rb +9 -0
- data/lib/rubycord/commands/parser.rb +325 -0
- data/lib/rubycord/commands/rate_limiter.rb +142 -0
- data/lib/rubycord/container.rb +753 -0
- data/lib/rubycord/data/activity.rb +269 -0
- data/lib/rubycord/data/application.rb +48 -0
- data/lib/rubycord/data/attachment.rb +109 -0
- data/lib/rubycord/data/audit_logs.rb +343 -0
- data/lib/rubycord/data/channel.rb +996 -0
- data/lib/rubycord/data/component.rb +227 -0
- data/lib/rubycord/data/embed.rb +249 -0
- data/lib/rubycord/data/emoji.rb +80 -0
- data/lib/rubycord/data/integration.rb +120 -0
- data/lib/rubycord/data/interaction.rb +798 -0
- data/lib/rubycord/data/invite.rb +135 -0
- data/lib/rubycord/data/member.rb +370 -0
- data/lib/rubycord/data/message.rb +412 -0
- data/lib/rubycord/data/overwrite.rb +106 -0
- data/lib/rubycord/data/profile.rb +89 -0
- data/lib/rubycord/data/reaction.rb +31 -0
- data/lib/rubycord/data/recipient.rb +32 -0
- data/lib/rubycord/data/role.rb +246 -0
- data/lib/rubycord/data/server.rb +1002 -0
- data/lib/rubycord/data/user.rb +261 -0
- data/lib/rubycord/data/voice_region.rb +43 -0
- data/lib/rubycord/data/voice_state.rb +39 -0
- data/lib/rubycord/data/webhook.rb +232 -0
- data/lib/rubycord/data.rb +40 -0
- data/lib/rubycord/errors.rb +737 -0
- data/lib/rubycord/events/await.rb +46 -0
- data/lib/rubycord/events/bans.rb +58 -0
- data/lib/rubycord/events/channels.rb +186 -0
- data/lib/rubycord/events/generic.rb +126 -0
- data/lib/rubycord/events/guilds.rb +191 -0
- data/lib/rubycord/events/interactions.rb +480 -0
- data/lib/rubycord/events/invites.rb +123 -0
- data/lib/rubycord/events/lifetime.rb +29 -0
- data/lib/rubycord/events/members.rb +91 -0
- data/lib/rubycord/events/message.rb +337 -0
- data/lib/rubycord/events/presence.rb +127 -0
- data/lib/rubycord/events/raw.rb +45 -0
- data/lib/rubycord/events/reactions.rb +156 -0
- data/lib/rubycord/events/roles.rb +86 -0
- data/lib/rubycord/events/threads.rb +94 -0
- data/lib/rubycord/events/typing.rb +70 -0
- data/lib/rubycord/events/voice_server_update.rb +45 -0
- data/lib/rubycord/events/voice_state_update.rb +103 -0
- data/lib/rubycord/events/webhooks.rb +62 -0
- data/lib/rubycord/gateway.rb +867 -0
- data/lib/rubycord/id_object.rb +37 -0
- data/lib/rubycord/light/data.rb +60 -0
- data/lib/rubycord/light/integrations.rb +71 -0
- data/lib/rubycord/light/light_bot.rb +56 -0
- data/lib/rubycord/light.rb +6 -0
- data/lib/rubycord/logger.rb +118 -0
- data/lib/rubycord/paginator.rb +55 -0
- data/lib/rubycord/permissions.rb +251 -0
- data/lib/rubycord/version.rb +5 -0
- data/lib/rubycord/voice/encoder.rb +113 -0
- data/lib/rubycord/voice/network.rb +366 -0
- data/lib/rubycord/voice/sodium.rb +96 -0
- data/lib/rubycord/voice/voice_bot.rb +408 -0
- data/lib/rubycord/webhooks/builder.rb +100 -0
- data/lib/rubycord/webhooks/client.rb +132 -0
- data/lib/rubycord/webhooks/embeds.rb +248 -0
- data/lib/rubycord/webhooks/modal.rb +78 -0
- data/lib/rubycord/webhooks/version.rb +7 -0
- data/lib/rubycord/webhooks/view.rb +192 -0
- data/lib/rubycord/webhooks.rb +12 -0
- data/lib/rubycord/websocket.rb +70 -0
- data/lib/rubycord.rb +140 -0
- metadata +231 -0
@@ -0,0 +1,753 @@
|
|
1
|
+
require "rubycord/events/message"
|
2
|
+
require "rubycord/events/typing"
|
3
|
+
require "rubycord/events/lifetime"
|
4
|
+
require "rubycord/events/presence"
|
5
|
+
require "rubycord/events/voice_state_update"
|
6
|
+
require "rubycord/events/voice_server_update"
|
7
|
+
require "rubycord/events/channels"
|
8
|
+
require "rubycord/events/members"
|
9
|
+
require "rubycord/events/roles"
|
10
|
+
require "rubycord/events/guilds"
|
11
|
+
require "rubycord/events/await"
|
12
|
+
require "rubycord/events/bans"
|
13
|
+
require "rubycord/events/reactions"
|
14
|
+
require "rubycord/events/interactions"
|
15
|
+
|
16
|
+
require "rubycord/await"
|
17
|
+
|
18
|
+
module Rubycord
|
19
|
+
# This module provides the functionality required for events and awaits. It is separated
|
20
|
+
# from the {Bot} class so users can make their own container modules and include them.
|
21
|
+
module EventContainer
|
22
|
+
# This **event** is raised when a message is sent to a text channel the bot is currently in.
|
23
|
+
# @param attributes [Hash] The event's attributes.
|
24
|
+
# @option attributes [String, Regexp] :start_with Matches the string the message starts with.
|
25
|
+
# @option attributes [String, Regexp] :end_with Matches the string the message ends with.
|
26
|
+
# @option attributes [String, Regexp] :contains Matches a string the message contains.
|
27
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was sent in.
|
28
|
+
# @option attributes [String, Integer, User] :from Matches the user that sent the message.
|
29
|
+
# @option attributes [String] :content Exactly matches the entire content of the message.
|
30
|
+
# @option attributes [Time] :after Matches a time after the time the message was sent at.
|
31
|
+
# @option attributes [Time] :before Matches a time before the time the message was sent at.
|
32
|
+
# @option attributes [Boolean] :private Matches whether or not the channel is private.
|
33
|
+
# @yield The block is executed when the event is raised.
|
34
|
+
# @yieldparam event [MessageEvent] The event that was raised.
|
35
|
+
# @return [MessageEventHandler] the event handler that was registered.
|
36
|
+
def message(attributes = {}, &block)
|
37
|
+
register_event(MessageEvent, attributes, block)
|
38
|
+
end
|
39
|
+
|
40
|
+
# This **event** is raised when the READY packet is received, i.e. servers and channels have finished
|
41
|
+
# initialization. It's the recommended way to do things when the bot has finished starting up.
|
42
|
+
# @param attributes [Hash] Event attributes, none in this particular case
|
43
|
+
# @yield The block is executed when the event is raised.
|
44
|
+
# @yieldparam event [ReadyEvent] The event that was raised.
|
45
|
+
# @return [ReadyEventHandler] the event handler that was registered.
|
46
|
+
def ready(attributes = {}, &block)
|
47
|
+
register_event(ReadyEvent, attributes, block)
|
48
|
+
end
|
49
|
+
|
50
|
+
# This **event** is raised when the bot has disconnected from the WebSocket, due to the {Bot#stop} method or
|
51
|
+
# external causes. It's the recommended way to do clean-up tasks.
|
52
|
+
# @param attributes [Hash] Event attributes, none in this particular case
|
53
|
+
# @yield The block is executed when the event is raised.
|
54
|
+
# @yieldparam event [DisconnectEvent] The event that was raised.
|
55
|
+
# @return [DisconnectEventHandler] the event handler that was registered.
|
56
|
+
def disconnected(attributes = {}, &block)
|
57
|
+
register_event(DisconnectEvent, attributes, block)
|
58
|
+
end
|
59
|
+
|
60
|
+
# This **event** is raised every time the bot sends a heartbeat over the galaxy. This happens roughly every 40
|
61
|
+
# seconds, but may happen at a lower rate should Discord change their interval. It may also happen more quickly for
|
62
|
+
# periods of time, especially for unstable connections, since rubycord rather sends a heartbeat than not if there's
|
63
|
+
# a choice. (You shouldn't rely on all this to be accurately timed.)
|
64
|
+
#
|
65
|
+
# All this makes this event useful to periodically trigger something, like doing some API request every hour,
|
66
|
+
# setting some kind of uptime variable or whatever else. The only limit is yourself.
|
67
|
+
# @param attributes [Hash] Event attributes, none in this particular case
|
68
|
+
# @yield The block is executed when the event is raised.
|
69
|
+
# @yieldparam event [HeartbeatEvent] The event that was raised.
|
70
|
+
# @return [HeartbeatEventHandler] the event handler that was registered.
|
71
|
+
def heartbeat(attributes = {}, &block)
|
72
|
+
register_event(HeartbeatEvent, attributes, block)
|
73
|
+
end
|
74
|
+
|
75
|
+
# This **event** is raised when somebody starts typing in a channel the bot is also in. The official Discord
|
76
|
+
# client would display the typing indicator for five seconds after receiving this event. If the user continues
|
77
|
+
# typing after five seconds, the event will be re-raised.
|
78
|
+
# @param attributes [Hash] The event's attributes.
|
79
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel where typing was started.
|
80
|
+
# @option attributes [String, Integer, User] :from Matches the user that started typing.
|
81
|
+
# @option attributes [Time] :after Matches a time after the time the typing started.
|
82
|
+
# @option attributes [Time] :before Matches a time before the time the typing started.
|
83
|
+
# @yield The block is executed when the event is raised.
|
84
|
+
# @yieldparam event [TypingEvent] The event that was raised.
|
85
|
+
# @return [TypingEventHandler] the event handler that was registered.
|
86
|
+
def typing(attributes = {}, &block)
|
87
|
+
register_event(TypingEvent, attributes, block)
|
88
|
+
end
|
89
|
+
|
90
|
+
# This **event** is raised when a message is edited in a channel.
|
91
|
+
# @param attributes [Hash] The event's attributes.
|
92
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was edited.
|
93
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was edited in.
|
94
|
+
# @yield The block is executed when the event is raised.
|
95
|
+
# @yieldparam event [MessageEditEvent] The event that was raised.
|
96
|
+
# @return [MessageEditEventHandler] the event handler that was registered.
|
97
|
+
def message_edit(attributes = {}, &block)
|
98
|
+
register_event(MessageEditEvent, attributes, block)
|
99
|
+
end
|
100
|
+
|
101
|
+
# This **event** is raised when a message is deleted in a channel.
|
102
|
+
# @param attributes [Hash] The event's attributes.
|
103
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was deleted.
|
104
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was deleted in.
|
105
|
+
# @yield The block is executed when the event is raised.
|
106
|
+
# @yieldparam event [MessageDeleteEvent] The event that was raised.
|
107
|
+
# @return [MessageDeleteEventHandler] the event handler that was registered.
|
108
|
+
def message_delete(attributes = {}, &block)
|
109
|
+
register_event(MessageDeleteEvent, attributes, block)
|
110
|
+
end
|
111
|
+
|
112
|
+
# This **event** is raised whenever a message is updated. Message updates can be triggered from
|
113
|
+
# a user editing their own message, or from Discord automatically attaching embeds to the
|
114
|
+
# user's message for URLs contained in the message's content. If you only want to listen
|
115
|
+
# for users editing their own messages, use the {message_edit} handler instead.
|
116
|
+
# @param attributes [Hash] The event's attributes.
|
117
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was updated.
|
118
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was updated in.
|
119
|
+
# @yield The block is executed when the event is raised.
|
120
|
+
# @yieldparam event [MessageUpdateEvent] The event that was raised.
|
121
|
+
# @return [MessageUpdateEventHandler] the event handler that was registered.
|
122
|
+
def message_update(attributes = {}, &block)
|
123
|
+
register_event(MessageUpdateEvent, attributes, block)
|
124
|
+
end
|
125
|
+
|
126
|
+
# This **event** is raised when somebody reacts to a message.
|
127
|
+
# @param attributes [Hash] The event's attributes.
|
128
|
+
# @option attributes [String, Integer] :emoji Matches the ID of the emoji that was reacted with, or its name.
|
129
|
+
# @option attributes [String, Integer, User] :from Matches the user who added the reaction.
|
130
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reaction was added.
|
131
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reaction was added in.
|
132
|
+
# @yield The block is executed when the event is raised.
|
133
|
+
# @yieldparam event [ReactionAddEvent] The event that was raised.
|
134
|
+
# @return [ReactionAddEventHandler] The event handler that was registered.
|
135
|
+
def reaction_add(attributes = {}, &block)
|
136
|
+
register_event(ReactionAddEvent, attributes, block)
|
137
|
+
end
|
138
|
+
|
139
|
+
# This **event** is raised when somebody removes a reaction from a message.
|
140
|
+
# @param attributes [Hash] The event's attributes.
|
141
|
+
# @option attributes [String, Integer] :emoji Matches the ID of the emoji that was removed from the reactions, or
|
142
|
+
# its name.
|
143
|
+
# @option attributes [String, Integer, User] :from Matches the user who removed the reaction.
|
144
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reaction was removed.
|
145
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reaction was removed in.
|
146
|
+
# @yield The block is executed when the event is raised.
|
147
|
+
# @yieldparam event [ReactionRemoveEvent] The event that was raised.
|
148
|
+
# @return [ReactionRemoveEventHandler] The event handler that was registered.
|
149
|
+
def reaction_remove(attributes = {}, &block)
|
150
|
+
register_event(ReactionRemoveEvent, attributes, block)
|
151
|
+
end
|
152
|
+
|
153
|
+
# This **event** is raised when somebody removes all reactions from a message.
|
154
|
+
# @param attributes [Hash] The event's attributes.
|
155
|
+
# @option attributes [Hash] The event's attributes.
|
156
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reactions were removed.
|
157
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reactions were removed in.
|
158
|
+
# @yield The block is executed when the event is raised.
|
159
|
+
# @yieldparam event [ReactionRemoveAllEvent] The event that was raised.
|
160
|
+
# @return [ReactionRemoveAllEventHandler] The event handler that was registered.
|
161
|
+
def reaction_remove_all(attributes = {}, &block)
|
162
|
+
register_event(ReactionRemoveAllEvent, attributes, block)
|
163
|
+
end
|
164
|
+
|
165
|
+
# This **event** is raised when a user's status (online/offline/idle) changes.
|
166
|
+
# @param attributes [Hash] The event's attributes.
|
167
|
+
# @option attributes [String, Integer, User] :from Matches the user whose status changed.
|
168
|
+
# @option attributes [:offline, :idle, :online] :status Matches the status the user has now.
|
169
|
+
# @option attributes [Hash<Symbol, Symbol>] :client_status Matches the current online status (`:online`, `:idle` or `:dnd`) of the user
|
170
|
+
# on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` when the user is offline or invisible
|
171
|
+
# @yield The block is executed when the event is raised.
|
172
|
+
# @yieldparam event [PresenceEvent] The event that was raised.
|
173
|
+
# @return [PresenceEventHandler] the event handler that was registered.
|
174
|
+
def presence(attributes = {}, &block)
|
175
|
+
register_event(PresenceEvent, attributes, block)
|
176
|
+
end
|
177
|
+
|
178
|
+
# This **event** is raised when the game a user is playing changes.
|
179
|
+
# @param attributes [Hash] The event's attributes.
|
180
|
+
# @option attributes [String, Integer, User] :from Matches the user whose playing game changes.
|
181
|
+
# @option attributes [String] :game Matches the game the user is now playing.
|
182
|
+
# @option attributes [Integer] :type Matches the type of game object (0 game, 1 Twitch stream)
|
183
|
+
# @yield The block is executed when the event is raised.
|
184
|
+
# @yieldparam event [PlayingEvent] The event that was raised.
|
185
|
+
# @return [PlayingEventHandler] the event handler that was registered.
|
186
|
+
def playing(attributes = {}, &block)
|
187
|
+
register_event(PlayingEvent, attributes, block)
|
188
|
+
end
|
189
|
+
|
190
|
+
# This **event** is raised when the bot is mentioned in a message.
|
191
|
+
# @param attributes [Hash] The event's attributes.
|
192
|
+
# @option attributes [String, Regexp] :start_with Matches the string the message starts with.
|
193
|
+
# @option attributes [String, Regexp] :end_with Matches the string the message ends with.
|
194
|
+
# @option attributes [String, Regexp] :contains Matches a string the message contains.
|
195
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was sent in.
|
196
|
+
# @option attributes [String, Integer, User] :from Matches the user that sent the message.
|
197
|
+
# @option attributes [String] :content Exactly matches the entire content of the message.
|
198
|
+
# @option attributes [Time] :after Matches a time after the time the message was sent at.
|
199
|
+
# @option attributes [Time] :before Matches a time before the time the message was sent at.
|
200
|
+
# @option attributes [Boolean] :private Matches whether or not the channel is private.
|
201
|
+
# @yield The block is executed when the event is raised.
|
202
|
+
# @yieldparam event [MentionEvent] The event that was raised.
|
203
|
+
# @return [MentionEventHandler] the event handler that was registered.
|
204
|
+
def mention(attributes = {}, &block)
|
205
|
+
register_event(MentionEvent, attributes, block)
|
206
|
+
end
|
207
|
+
|
208
|
+
# This **event** is raised when a channel is created.
|
209
|
+
# @param attributes [Hash] The event's attributes.
|
210
|
+
# @option attributes [Integer] :type Matches the type of channel that is being created (0: text, 1: private, 2: voice, 3: group)
|
211
|
+
# @option attributes [String] :name Matches the name of the created channel.
|
212
|
+
# @yield The block is executed when the event is raised.
|
213
|
+
# @yieldparam event [ChannelCreateEvent] The event that was raised.
|
214
|
+
# @return [ChannelCreateEventHandler] the event handler that was registered.
|
215
|
+
def channel_create(attributes = {}, &block)
|
216
|
+
register_event(ChannelCreateEvent, attributes, block)
|
217
|
+
end
|
218
|
+
|
219
|
+
# This **event** is raised when a channel is updated.
|
220
|
+
# @param attributes [Hash] The event's attributes.
|
221
|
+
# @option attributes [Integer] :type Matches the type of channel that is being updated (0: text, 1: private, 2: voice, 3: group).
|
222
|
+
# @option attributes [String] :name Matches the new name of the channel.
|
223
|
+
# @yield The block is executed when the event is raised.
|
224
|
+
# @yieldparam event [ChannelUpdateEvent] The event that was raised.
|
225
|
+
# @return [ChannelUpdateEventHandler] the event handler that was registered.
|
226
|
+
def channel_update(attributes = {}, &block)
|
227
|
+
register_event(ChannelUpdateEvent, attributes, block)
|
228
|
+
end
|
229
|
+
|
230
|
+
# This **event** is raised when a channel is deleted.
|
231
|
+
# @param attributes [Hash] The event's attributes.
|
232
|
+
# @option attributes [Integer] :type Matches the type of channel that is being deleted (0: text, 1: private, 2: voice, 3: group).
|
233
|
+
# @option attributes [String] :name Matches the name of the deleted channel.
|
234
|
+
# @yield The block is executed when the event is raised.
|
235
|
+
# @yieldparam event [ChannelDeleteEvent] The event that was raised.
|
236
|
+
# @return [ChannelDeleteEventHandler] the event handler that was registered.
|
237
|
+
def channel_delete(attributes = {}, &block)
|
238
|
+
register_event(ChannelDeleteEvent, attributes, block)
|
239
|
+
end
|
240
|
+
|
241
|
+
# This **event** is raised when a recipient is added to a group channel.
|
242
|
+
# @param attributes [Hash] The event's attributes.
|
243
|
+
# @option attributes [String] :name Matches the name of the group channel that the recipient is added to.
|
244
|
+
# @option attributes [String, Integer] :owner_id Matches the ID of the group channel's owner.
|
245
|
+
# @option attributes [String, Integer] :id Matches the ID of the recipient added to the group channel.
|
246
|
+
# @yield The block is executed when the event is raised.
|
247
|
+
# @yieldparam event [ChannelRecipientAddEvent] The event that was raised.
|
248
|
+
# @return [ChannelRecipientAddHandler] the event handler that was registered.
|
249
|
+
def channel_recipient_add(attributes = {}, &block)
|
250
|
+
register_event(ChannelRecipientAddEvent, attributes, block)
|
251
|
+
end
|
252
|
+
|
253
|
+
# This **event** is raised when a recipient is removed from a group channel.
|
254
|
+
# @param attributes [Hash] The event's attributes.
|
255
|
+
# @option attributes [String] :name Matches the name of the group channel that the recipient is added to.
|
256
|
+
# @option attributes [String, Integer] :owner_id Matches the ID of the group channel's owner.
|
257
|
+
# @option attributes [String, Integer] :id Matches the ID of the recipient removed from the group channel.
|
258
|
+
# @yield The block is executed when the event is raised.
|
259
|
+
# @yieldparam event [ChannelRecipientRemoveEvent] The event that was raised.
|
260
|
+
# @return [ChannelRecipientRemoveHandler] the event handler that was registered.
|
261
|
+
def channel_recipient_remove(attributes = {}, &block)
|
262
|
+
register_event(ChannelRecipientRemoveEvent, attributes, block)
|
263
|
+
end
|
264
|
+
|
265
|
+
# This **event** is raised when a user's voice state changes. This includes when a user joins, leaves, or
|
266
|
+
# moves between voice channels, as well as their mute and deaf status for themselves and on the server.
|
267
|
+
# @param attributes [Hash] The event's attributes.
|
268
|
+
# @option attributes [String, Integer, User] :from Matches the user that sent the message.
|
269
|
+
# @option attributes [String, Integer, Channel] :channel Matches the voice channel the user has joined.
|
270
|
+
# @option attributes [String, Integer, Channel] :old_channel Matches the voice channel the user was in previously.
|
271
|
+
# @option attributes [true, false] :mute Matches whether or not the user is muted server-wide.
|
272
|
+
# @option attributes [true, false] :deaf Matches whether or not the user is deafened server-wide.
|
273
|
+
# @option attributes [true, false] :self_mute Matches whether or not the user is muted by the bot.
|
274
|
+
# @option attributes [true, false] :self_deaf Matches whether or not the user is deafened by the bot.
|
275
|
+
# @yield The block is executed when the event is raised.
|
276
|
+
# @yieldparam event [VoiceStateUpdateEvent] The event that was raised.
|
277
|
+
# @return [VoiceStateUpdateEventHandler] the event handler that was registered.
|
278
|
+
def voice_state_update(attributes = {}, &block)
|
279
|
+
register_event(VoiceStateUpdateEvent, attributes, block)
|
280
|
+
end
|
281
|
+
|
282
|
+
# This **event** is raised when first connecting to a server's voice channel.
|
283
|
+
# @param attributes [Hash] The event's attributes.
|
284
|
+
# @option attributes [String, Integer, User] :from Matches the server that the update is for.
|
285
|
+
# @yield The block is executed when the event is raised.
|
286
|
+
# @yieldparam event [VoiceServerUpdateEvent] The event that was raised.
|
287
|
+
# @return [VoiceServerUpdateEventHandler] The event handler that was registered.
|
288
|
+
def voice_server_update(attributes = {}, &block)
|
289
|
+
register_event(VoiceServerUpdateEvent, attributes, block)
|
290
|
+
end
|
291
|
+
|
292
|
+
# This **event** is raised when a new user joins a server.
|
293
|
+
# @param attributes [Hash] The event's attributes.
|
294
|
+
# @option attributes [String] :username Matches the username of the joined user.
|
295
|
+
# @yield The block is executed when the event is raised.
|
296
|
+
# @yieldparam event [ServerMemberAddEvent] The event that was raised.
|
297
|
+
# @return [ServerMemberAddEventHandler] the event handler that was registered.
|
298
|
+
def member_join(attributes = {}, &block)
|
299
|
+
register_event(ServerMemberAddEvent, attributes, block)
|
300
|
+
end
|
301
|
+
|
302
|
+
# This **event** is raised when a member update happens. This includes when a members nickname
|
303
|
+
# or roles are updated.
|
304
|
+
# @param attributes [Hash] The event's attributes.
|
305
|
+
# @option attributes [String] :username Matches the username of the updated user.
|
306
|
+
# @yield The block is executed when the event is raised.
|
307
|
+
# @yieldparam event [ServerMemberUpdateEvent] The event that was raised.
|
308
|
+
# @return [ServerMemberUpdateEventHandler] the event handler that was registered.
|
309
|
+
def member_update(attributes = {}, &block)
|
310
|
+
register_event(ServerMemberUpdateEvent, attributes, block)
|
311
|
+
end
|
312
|
+
|
313
|
+
# This **event** is raised when a member leaves a server.
|
314
|
+
# @param attributes [Hash] The event's attributes.
|
315
|
+
# @option attributes [String] :username Matches the username of the member.
|
316
|
+
# @yield The block is executed when the event is raised.
|
317
|
+
# @yieldparam event [ServerMemberDeleteEvent] The event that was raised.
|
318
|
+
# @return [ServerMemberDeleteEventHandler] the event handler that was registered.
|
319
|
+
def member_leave(attributes = {}, &block)
|
320
|
+
register_event(ServerMemberDeleteEvent, attributes, block)
|
321
|
+
end
|
322
|
+
|
323
|
+
# This **event** is raised when a user is banned from a server.
|
324
|
+
# @param attributes [Hash] The event's attributes.
|
325
|
+
# @option attributes [String, Integer, User] :user Matches the user that was banned.
|
326
|
+
# @option attributes [String, Integer, Server] :server Matches the server from which the user was banned.
|
327
|
+
# @yield The block is executed when the event is raised.
|
328
|
+
# @yieldparam event [UserBanEvent] The event that was raised.
|
329
|
+
# @return [UserBanEventHandler] the event handler that was registered.
|
330
|
+
def user_ban(attributes = {}, &block)
|
331
|
+
register_event(UserBanEvent, attributes, block)
|
332
|
+
end
|
333
|
+
|
334
|
+
# This **event** is raised when a user is unbanned from a server.
|
335
|
+
# @param attributes [Hash] The event's attributes.
|
336
|
+
# @option attributes [String, Integer, User] :user Matches the user that was unbanned.
|
337
|
+
# @option attributes [String, Integer, Server] :server Matches the server from which the user was unbanned.
|
338
|
+
# @yield The block is executed when the event is raised.
|
339
|
+
# @yieldparam event [UserUnbanEvent] The event that was raised.
|
340
|
+
# @return [UserUnbanEventHandler] the event handler that was registered.
|
341
|
+
def user_unban(attributes = {}, &block)
|
342
|
+
register_event(UserUnbanEvent, attributes, block)
|
343
|
+
end
|
344
|
+
|
345
|
+
# This **event** is raised when a server is created respective to the bot, i.e. the bot joins a server or creates
|
346
|
+
# a new one itself.
|
347
|
+
# @param attributes [Hash] The event's attributes.
|
348
|
+
# @option attributes [String, Integer, Server] :server Matches the server that was created.
|
349
|
+
# @yield The block is executed when the event is raised.
|
350
|
+
# @yieldparam event [ServerCreateEvent] The event that was raised.
|
351
|
+
# @return [ServerCreateEventHandler] the event handler that was registered.
|
352
|
+
def server_create(attributes = {}, &block)
|
353
|
+
register_event(ServerCreateEvent, attributes, block)
|
354
|
+
end
|
355
|
+
|
356
|
+
# This **event** is raised when a server is updated, for example if the name or region has changed.
|
357
|
+
# @param attributes [Hash] The event's attributes.
|
358
|
+
# @option attributes [String, Integer, Server] :server Matches the server that was updated.
|
359
|
+
# @yield The block is executed when the event is raised.
|
360
|
+
# @yieldparam event [ServerUpdateEvent] The event that was raised.
|
361
|
+
# @return [ServerUpdateEventHandler] the event handler that was registered.
|
362
|
+
def server_update(attributes = {}, &block)
|
363
|
+
register_event(ServerUpdateEvent, attributes, block)
|
364
|
+
end
|
365
|
+
|
366
|
+
# This **event** is raised when a server is deleted, or when the bot leaves a server. (These two cases are identical
|
367
|
+
# to Discord.)
|
368
|
+
# @param attributes [Hash] The event's attributes.
|
369
|
+
# @option attributes [String, Integer, Server] :server Matches the server that was deleted.
|
370
|
+
# @yield The block is executed when the event is raised.
|
371
|
+
# @yieldparam event [ServerDeleteEvent] The event that was raised.
|
372
|
+
# @return [ServerDeleteEventHandler] the event handler that was registered.
|
373
|
+
def server_delete(attributes = {}, &block)
|
374
|
+
register_event(ServerDeleteEvent, attributes, block)
|
375
|
+
end
|
376
|
+
|
377
|
+
# This **event** is raised when an emoji or collection of emojis is created/deleted/updated.
|
378
|
+
# @param attributes [Hash] The event's attributes.
|
379
|
+
# @option attributes [String, Integer, Server] :server Matches the server.
|
380
|
+
# @yield The block is executed when the event is raised.
|
381
|
+
# @yieldparam event [ServerEmojiChangeEvent] The event that was raised.
|
382
|
+
# @return [ServerEmojiChangeEventHandler] the event handler that was registered.
|
383
|
+
def server_emoji(attributes = {}, &block)
|
384
|
+
register_event(ServerEmojiChangeEvent, attributes, block)
|
385
|
+
end
|
386
|
+
|
387
|
+
# This **event** is raised when an emoji is created.
|
388
|
+
# @param attributes [Hash] The event's attributes.
|
389
|
+
# @option attributes [String, Integer, Server] :server Matches the server.
|
390
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
391
|
+
# @option attributes [String] :name Matches the name of the emoji.
|
392
|
+
# @yield The block is executed when the event is raised.
|
393
|
+
# @yieldparam event [ServerEmojiCreateEvent] The event that was raised.
|
394
|
+
# @return [ServerEmojiCreateEventHandler] the event handler that was registered.
|
395
|
+
def server_emoji_create(attributes = {}, &block)
|
396
|
+
register_event(ServerEmojiCreateEvent, attributes, block)
|
397
|
+
end
|
398
|
+
|
399
|
+
# This **event** is raised when an emoji is deleted.
|
400
|
+
# @param attributes [Hash] The event's attributes.
|
401
|
+
# @option attributes [String, Integer, Server] :server Matches the server.
|
402
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
403
|
+
# @option attributes [String] :name Matches the name of the emoji.
|
404
|
+
# @yield The block is executed when the event is raised.
|
405
|
+
# @yieldparam event [ServerEmojiDeleteEvent] The event that was raised.
|
406
|
+
# @return [ServerEmojiDeleteEventHandler] the event handler that was registered.
|
407
|
+
def server_emoji_delete(attributes = {}, &block)
|
408
|
+
register_event(ServerEmojiDeleteEvent, attributes, block)
|
409
|
+
end
|
410
|
+
|
411
|
+
# This **event** is raised when an emoji is updated.
|
412
|
+
# @param attributes [Hash] The event's attributes.
|
413
|
+
# @option attributes [String, Integer, Server] :server Matches the server.
|
414
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
415
|
+
# @option attributes [String] :name Matches the name of the emoji.
|
416
|
+
# @option attributes [String] :old_name Matches the name of the emoji before the update.
|
417
|
+
# @yield The block is executed when the event is raised.
|
418
|
+
# @yieldparam event [ServerEmojiUpdateEvent] The event that was raised.
|
419
|
+
# @return [ServerEmojiUpdateEventHandler] the event handler that was registered.
|
420
|
+
def server_emoji_update(attributes = {}, &block)
|
421
|
+
register_event(ServerEmojiUpdateEvent, attributes, block)
|
422
|
+
end
|
423
|
+
|
424
|
+
# This **event** is raised when a role is created.
|
425
|
+
# @param attributes [Hash] The event's attributes.
|
426
|
+
# @option attributes [String] :name Matches the role name.
|
427
|
+
# @yield The block is executed when the event is raised.
|
428
|
+
# @yieldparam event [ServerRoleCreateEvent] The event that was raised.
|
429
|
+
# @return [ServerRoleCreateEventHandler] the event handler that was registered.
|
430
|
+
def server_role_create(attributes = {}, &block)
|
431
|
+
register_event(ServerRoleCreateEvent, attributes, block)
|
432
|
+
end
|
433
|
+
|
434
|
+
# This **event** is raised when a role is deleted.
|
435
|
+
# @param attributes [Hash] The event's attributes.
|
436
|
+
# @option attributes [String, Integer] :id Matches the role ID.
|
437
|
+
# @yield The block is executed when the event is raised.
|
438
|
+
# @yieldparam event [ServerRoleDeleteEvent] The event that was raised.
|
439
|
+
# @return [ServerRoleDeleteEventHandler] the event handler that was registered.
|
440
|
+
def server_role_delete(attributes = {}, &block)
|
441
|
+
register_event(ServerRoleDeleteEvent, attributes, block)
|
442
|
+
end
|
443
|
+
|
444
|
+
# This **event** is raised when a role is updated.
|
445
|
+
# @param attributes [Hash] The event's attributes.
|
446
|
+
# @option attributes [String] :name Matches the role name.
|
447
|
+
# @yield The block is executed when the event is raised.
|
448
|
+
# @yieldparam event [ServerRoleUpdateEvent] The event that was raised.
|
449
|
+
# @return [ServerRoleUpdateEventHandler] the event handler that was registered.
|
450
|
+
def server_role_update(attributes = {}, &block)
|
451
|
+
register_event(ServerRoleUpdateEvent, attributes, block)
|
452
|
+
end
|
453
|
+
|
454
|
+
# This **event** is raised when a webhook is updated.
|
455
|
+
# @param attributes [Hash] The event's attributes.
|
456
|
+
# @option attributes [String, Integer, Server] :server Matches the server by name, ID or instance.
|
457
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel by name, ID or instance.
|
458
|
+
# @option attribute [String, Integer, Webhook] :webhook Matches the webhook by name, ID or instance.
|
459
|
+
# @yield The block is executed when the event is raised.
|
460
|
+
# @yieldparam event [WebhookUpdateEvent] The event that was raised.
|
461
|
+
# @return [WebhookUpdateEventHandler] the event handler that was registered.
|
462
|
+
def webhook_update(attributes = {}, &block)
|
463
|
+
register_event(WebhookUpdateEvent, attributes, block)
|
464
|
+
end
|
465
|
+
|
466
|
+
# This **event** is raised when an {Await} is triggered. It provides an easy way to execute code
|
467
|
+
# on an await without having to rely on the await's block.
|
468
|
+
# @param attributes [Hash] The event's attributes.
|
469
|
+
# @option attributes [Symbol] :key Exactly matches the await's key.
|
470
|
+
# @option attributes [Class] :type Exactly matches the event's type.
|
471
|
+
# @yield The block is executed when the event is raised.
|
472
|
+
# @yieldparam event [AwaitEvent] The event that was raised.
|
473
|
+
# @return [AwaitEventHandler] the event handler that was registered.
|
474
|
+
def await(attributes = {}, &block)
|
475
|
+
register_event(AwaitEvent, attributes, block)
|
476
|
+
end
|
477
|
+
|
478
|
+
# This **event** is raised when a private message is sent to the bot.
|
479
|
+
# @param attributes [Hash] The event's attributes.
|
480
|
+
# @option attributes [String, Regexp] :start_with Matches the string the message starts with.
|
481
|
+
# @option attributes [String, Regexp] :end_with Matches the string the message ends with.
|
482
|
+
# @option attributes [String, Regexp] :contains Matches a string the message contains.
|
483
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was sent in.
|
484
|
+
# @option attributes [String, Integer, User] :from Matches the user that sent the message.
|
485
|
+
# @option attributes [String] :content Exactly matches the entire content of the message.
|
486
|
+
# @option attributes [Time] :after Matches a time after the time the message was sent at.
|
487
|
+
# @option attributes [Time] :before Matches a time before the time the message was sent at.
|
488
|
+
# @option attributes [Boolean] :private Matches whether or not the channel is private.
|
489
|
+
# @yield The block is executed when the event is raised.
|
490
|
+
# @yieldparam event [PrivateMessageEvent] The event that was raised.
|
491
|
+
# @return [PrivateMessageEventHandler] the event handler that was registered.
|
492
|
+
def pm(attributes = {}, &block)
|
493
|
+
register_event(PrivateMessageEvent, attributes, block)
|
494
|
+
end
|
495
|
+
|
496
|
+
alias_method :private_message, :pm
|
497
|
+
alias_method :direct_message, :pm
|
498
|
+
alias_method :dm, :pm
|
499
|
+
|
500
|
+
# This **event** is raised when an invite is created.
|
501
|
+
# @param attributes [Hash] The event's attributes.
|
502
|
+
# @option attributes [String, Integer, User] :inviter Matches the user that created the invite.
|
503
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel the invite was created for.
|
504
|
+
# @option attributes [String, Integer, Server] :server Matches the server the invite was created for.
|
505
|
+
# @option attributes [true, false] :temporary Matches whether the invite is temporary or not.
|
506
|
+
# @yield The block is executed when the event is raised.
|
507
|
+
# @yieldparam event [InviteCreateEvent] The event that was raised.
|
508
|
+
# @return [InviteCreateEventHandler] The event handler that was registered.
|
509
|
+
def invite_create(attributes = {}, &block)
|
510
|
+
register_event(InviteCreateEvent, attributes, block)
|
511
|
+
end
|
512
|
+
|
513
|
+
# This **event** is raised when an invite is deleted.
|
514
|
+
# @param attributes [Hash] The event's attributes.
|
515
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel the deleted invite was for.
|
516
|
+
# @option attributes [String, Integer, Server] :server Matches the server the deleted invite was for.
|
517
|
+
# @yield The block is executed when the event is raised
|
518
|
+
# @yieldparam event [InviteDeleteEvent] The event that was raised.
|
519
|
+
# @return [InviteDeleteEventHandler] The event handler that was registered.
|
520
|
+
def invite_delete(attributes = {}, &block)
|
521
|
+
register_event(InviteDeleteEvent, attributes, block)
|
522
|
+
end
|
523
|
+
|
524
|
+
# This **event** is raised whenever an interaction event is received.
|
525
|
+
# @param attributes [Hash] The event's attributes.
|
526
|
+
# @option attributes [Integer, Symbol, String] :type The interaction type, can be the integer value or the name
|
527
|
+
# of the key in {Rubycord::Interaction::TYPES}.
|
528
|
+
# @option attributes [String, Integer, Server, nil] :server The server where this event was created. `nil` for DM channels.
|
529
|
+
# @option attributes [String, Integer, Channel] :channel The channel where this event was created.
|
530
|
+
# @option attributes [String, Integer, User] :user The user that triggered this event.
|
531
|
+
# @yield The block is executed when the event is raised.
|
532
|
+
# @yieldparam event [InteractionCreateEvent] The event that was raised.
|
533
|
+
# @return [InteractionCreateEventHandler] The event handler that was registered.
|
534
|
+
def interaction_create(attributes = {}, &block)
|
535
|
+
register_event(InteractionCreateEvent, attributes, block)
|
536
|
+
end
|
537
|
+
|
538
|
+
# This **event** is raised whenever an application command (slash command) is executed.
|
539
|
+
# @param name [Symbol] The name of the application command this handler is for.
|
540
|
+
# @param attributes [Hash] The event's attributes.
|
541
|
+
# @yield The block is executed when the event is raised.
|
542
|
+
# @yieldparam event [ApplicationCommandEvent] The event that was raised.
|
543
|
+
# @return [ApplicationCommandEventHandler] The event handler that was registered.
|
544
|
+
def application_command(name, attributes = {}, &block)
|
545
|
+
@application_commands ||= {}
|
546
|
+
|
547
|
+
unless block
|
548
|
+
@application_commands[name] ||= ApplicationCommandEventHandler.new(attributes, nil)
|
549
|
+
return @application_commands[name]
|
550
|
+
end
|
551
|
+
|
552
|
+
@application_commands[name] = ApplicationCommandEventHandler.new(attributes, block)
|
553
|
+
end
|
554
|
+
|
555
|
+
# This **event** is raised whenever an button interaction is created.
|
556
|
+
# @param attributes [Hash] The event's attributes.
|
557
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
558
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
559
|
+
# @yield The block is executed when the event is raised.
|
560
|
+
# @yieldparam event [ButtonEvent] The event that was raised.
|
561
|
+
# @return [ButtonEventHandler] The event handler that was registered.
|
562
|
+
def button(attributes = {}, &block)
|
563
|
+
register_event(ButtonEvent, attributes, block)
|
564
|
+
end
|
565
|
+
|
566
|
+
# This **event** is raised whenever an select string interaction is created.
|
567
|
+
# @param attributes [Hash] The event's attributes.
|
568
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
569
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
570
|
+
# @yield The block is executed when the event is raised.
|
571
|
+
# @yieldparam event [StringSelectEvent] The event that was raised.
|
572
|
+
# @return [StringSelectEventHandler] The event handler that was registered.
|
573
|
+
def string_select(attributes = {}, &block)
|
574
|
+
register_event(StringSelectEvent, attributes, block)
|
575
|
+
end
|
576
|
+
|
577
|
+
alias_method :select_menu, :string_select
|
578
|
+
|
579
|
+
# This **event** is raised whenever a modal is submitted.
|
580
|
+
# @param attributes [Hash] The event's attributes.
|
581
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
582
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
583
|
+
# @option attributes [String, Integer, Server, nil] :server The server where this event was created. `nil` for DM channels.
|
584
|
+
# @option attributes [String, Integer, Channel] :channel The channel where this event was created.
|
585
|
+
# @option attributes [String, Integer, User] :user The user that triggered this event. # @yield The block is executed when the event is raised.
|
586
|
+
# @yieldparam event [ModalSubmitEvent] The event that was raised.
|
587
|
+
# @return [ModalSubmitEventHandler] The event handler that was registered.
|
588
|
+
def modal_submit(attributes = {}, &block)
|
589
|
+
register_event(ModalSubmitEvent, attributes, block)
|
590
|
+
end
|
591
|
+
|
592
|
+
# This **event** is raised whenever an select user interaction is created.
|
593
|
+
# @param attributes [Hash] The event's attributes.
|
594
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
595
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
596
|
+
# @yield The block is executed when the event is raised.
|
597
|
+
# @yieldparam event [UserSelectEvent] The event that was raised.
|
598
|
+
# @return [UserSelectEventHandler] The event handler that was registered.
|
599
|
+
def user_select(attributes = {}, &block)
|
600
|
+
register_event(UserSelectEvent, attributes, block)
|
601
|
+
end
|
602
|
+
|
603
|
+
# This **event** is raised whenever an select role interaction is created.
|
604
|
+
# @param attributes [Hash] The event's attributes.
|
605
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
606
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
607
|
+
# @yield The block is executed when the event is raised.
|
608
|
+
# @yieldparam event [RoleSelectEvent] The event that was raised.
|
609
|
+
# @return [RoleSelectEventHandler] The event handler that was registered.
|
610
|
+
def role_select(attributes = {}, &block)
|
611
|
+
register_event(RoleSelectEvent, attributes, block)
|
612
|
+
end
|
613
|
+
|
614
|
+
# This **event** is raised whenever an select mentionable interaction is created.
|
615
|
+
# @param attributes [Hash] The event's attributes.
|
616
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
617
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
618
|
+
# @yield The block is executed when the event is raised.
|
619
|
+
# @yieldparam event [MentionableSelectEvent] The event that was raised.
|
620
|
+
# @return [MentionableSelectEventHandler] The event handler that was registered.
|
621
|
+
def mentionable_select(attributes = {}, &block)
|
622
|
+
register_event(MentionableSelectEvent, attributes, block)
|
623
|
+
end
|
624
|
+
|
625
|
+
# This **event** is raised whenever an select channel interaction is created.
|
626
|
+
# @param attributes [Hash] The event's attributes.
|
627
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
628
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
629
|
+
# @yield The block is executed when the event is raised.
|
630
|
+
# @yieldparam event [ChannelSelectEvent] The event that was raised.
|
631
|
+
# @return [ChannelSelectEventHandler] The event handler that was registered.
|
632
|
+
def channel_select(attributes = {}, &block)
|
633
|
+
register_event(ChannelSelectEvent, attributes, block)
|
634
|
+
end
|
635
|
+
|
636
|
+
# This **event** is raised for every dispatch received over the gateway, whether supported by rubycord or not.
|
637
|
+
# @param attributes [Hash] The event's attributes.
|
638
|
+
# @option attributes [String, Symbol, Regexp] :type Matches the event type of the dispatch.
|
639
|
+
# @yield The block is executed when the event is raised.
|
640
|
+
# @yieldparam event [RawEvent] The event that was raised.
|
641
|
+
# @return [RawEventHandler] The event handler that was registered.
|
642
|
+
def raw(attributes = {}, &block)
|
643
|
+
register_event(RawEvent, attributes, block)
|
644
|
+
end
|
645
|
+
|
646
|
+
# This **event** is raised for a dispatch received over the gateway that is not currently handled otherwise by
|
647
|
+
# rubycord.
|
648
|
+
# @param attributes [Hash] The event's attributes.
|
649
|
+
# @option attributes [String, Symbol, Regexp] :type Matches the event type of the dispatch.
|
650
|
+
# @yield The block is executed when the event is raised.
|
651
|
+
# @yieldparam event [UnknownEvent] The event that was raised.
|
652
|
+
# @return [UnknownEventHandler] The event handler that was registered.
|
653
|
+
def unknown(attributes = {}, &block)
|
654
|
+
register_event(UnknownEvent, attributes, block)
|
655
|
+
end
|
656
|
+
|
657
|
+
# Removes an event handler from this container. If you're looking for a way to do temporary events, I recommend
|
658
|
+
# {Await}s instead of this.
|
659
|
+
# @param handler [Rubycord::Events::EventHandler] The handler to remove.
|
660
|
+
def remove_handler(handler)
|
661
|
+
clazz = EventContainer.event_class(handler.class)
|
662
|
+
@event_handlers ||= {}
|
663
|
+
@event_handlers[clazz].delete(handler)
|
664
|
+
end
|
665
|
+
|
666
|
+
# Remove an application command handler
|
667
|
+
# @param name [String, Symbol] The name of the command handler to remove.
|
668
|
+
def remove_application_command_handler(name)
|
669
|
+
@application_commands.delete(name)
|
670
|
+
end
|
671
|
+
|
672
|
+
# Removes all events from this event handler.
|
673
|
+
def clear!
|
674
|
+
@event_handlers&.clear
|
675
|
+
@application_commands&.clear
|
676
|
+
end
|
677
|
+
|
678
|
+
# Adds an event handler to this container. Usually, it's more expressive to just use one of the shorthand adder
|
679
|
+
# methods like {#message}, but if you want to create one manually you can use this.
|
680
|
+
# @param handler [Rubycord::Events::EventHandler] The handler to add.
|
681
|
+
def add_handler(handler)
|
682
|
+
clazz = EventContainer.event_class(handler.class)
|
683
|
+
@event_handlers ||= {}
|
684
|
+
@event_handlers[clazz] ||= []
|
685
|
+
@event_handlers[clazz] << handler
|
686
|
+
end
|
687
|
+
|
688
|
+
# Adds all event handlers from another container into this one. Existing event handlers will be overwritten.
|
689
|
+
# @param container [Module] A module that `extend`s {EventContainer} from which the handlers will be added.
|
690
|
+
def include_events(container)
|
691
|
+
application_command_handlers = container.instance_variable_get(:@application_commands)
|
692
|
+
handlers = container.instance_variable_get :@event_handlers
|
693
|
+
return unless handlers || application_command_handlers
|
694
|
+
|
695
|
+
@event_handlers ||= {}
|
696
|
+
@event_handlers.merge!(handlers || {}) { |_, old, new| old + new }
|
697
|
+
|
698
|
+
@application_commands ||= {}
|
699
|
+
|
700
|
+
@application_commands.merge!(application_command_handlers || {}) do |_, old, new|
|
701
|
+
old.subcommands.merge!(new.subcommands)
|
702
|
+
old
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
alias_method :include!, :include_events
|
707
|
+
alias_method :<<, :add_handler
|
708
|
+
|
709
|
+
# Returns the handler class for an event class type
|
710
|
+
# @see #event_class
|
711
|
+
# @param event_class [Class] The event type
|
712
|
+
# @return [Class] the handler type
|
713
|
+
def self.handler_class(event_class)
|
714
|
+
class_from_string("#{event_class}Handler")
|
715
|
+
end
|
716
|
+
|
717
|
+
# Returns the event class for a handler class type
|
718
|
+
# @see #handler_class
|
719
|
+
# @param handler_class [Class] The handler type
|
720
|
+
# @return [Class, nil] the event type, or nil if the handler_class isn't a handler class (i.e. ends with Handler)
|
721
|
+
def self.event_class(handler_class)
|
722
|
+
class_name = handler_class.to_s
|
723
|
+
return nil unless class_name.end_with? "Handler"
|
724
|
+
|
725
|
+
EventContainer.class_from_string(class_name[0..-8])
|
726
|
+
end
|
727
|
+
|
728
|
+
# Utility method to return a class object from a string of its name. Mostly useful for internal stuff
|
729
|
+
# @param str [String] The name of the class
|
730
|
+
# @return [Class] the class
|
731
|
+
def self.class_from_string(str)
|
732
|
+
str.split("::").inject(Object) do |mod, class_name|
|
733
|
+
mod.const_get(class_name)
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
private
|
738
|
+
|
739
|
+
include Rubycord::Events
|
740
|
+
|
741
|
+
# @return [EventHandler]
|
742
|
+
def register_event(clazz, attributes, block)
|
743
|
+
handler = EventContainer.handler_class(clazz).new(attributes, block)
|
744
|
+
|
745
|
+
@event_handlers ||= {}
|
746
|
+
@event_handlers[clazz] ||= []
|
747
|
+
@event_handlers[clazz] << handler
|
748
|
+
|
749
|
+
# Return the handler so it can be removed later
|
750
|
+
handler
|
751
|
+
end
|
752
|
+
end
|
753
|
+
end
|