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,480 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Generic subclass for interaction events
|
6
|
+
class InteractionCreateEvent < Event
|
7
|
+
# @return [Interaction] The interaction for this event.
|
8
|
+
attr_reader :interaction
|
9
|
+
|
10
|
+
# @!attribute [r] type
|
11
|
+
# @return [Integer]
|
12
|
+
# @see Interaction#type
|
13
|
+
# @!attribute [r] server
|
14
|
+
# @return [Server, nil]
|
15
|
+
# @see Interaction#server
|
16
|
+
# @!attribute [r] server_id
|
17
|
+
# @return [Integer]
|
18
|
+
# @see Interaction#server_id
|
19
|
+
# @!attribute [r] channel
|
20
|
+
# @return [Channel]
|
21
|
+
# @see Interaction#channel
|
22
|
+
# @!attribute [r] channel_id
|
23
|
+
# @return [Integer]
|
24
|
+
# @see Interaction#channel_id
|
25
|
+
# @!attribute [r] user
|
26
|
+
# @return [User]
|
27
|
+
# @see Interaction#user
|
28
|
+
delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction
|
29
|
+
|
30
|
+
def initialize(data, bot)
|
31
|
+
@interaction = Rubycord::Interaction.new(data, bot)
|
32
|
+
@bot = bot
|
33
|
+
end
|
34
|
+
|
35
|
+
# (see Interaction#respond)
|
36
|
+
def respond(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, &)
|
37
|
+
@interaction.respond(
|
38
|
+
content: content, tts: tts, embeds: embeds, allowed_mentions: allowed_mentions,
|
39
|
+
flags: flags, ephemeral: ephemeral, wait: wait, components: components, &
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# (see Interaction#defer)
|
44
|
+
def defer(flags: 0, ephemeral: true)
|
45
|
+
@interaction.defer(flags: flags, ephemeral: ephemeral)
|
46
|
+
end
|
47
|
+
|
48
|
+
# (see Interaction#update_message)
|
49
|
+
def update_message(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, &)
|
50
|
+
@interaction.update_message(
|
51
|
+
content: content, tts: tts, embeds: embeds, allowed_mentions: allowed_mentions,
|
52
|
+
flags: flags, ephemeral: ephemeral, wait: wait, components: components, &
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# (see Interaction#show_modal)
|
57
|
+
def show_modal(title:, custom_id:, components: nil, &)
|
58
|
+
@interaction.show_modal(title: title, custom_id: custom_id, components: components, &)
|
59
|
+
end
|
60
|
+
|
61
|
+
# (see Interaction#edit_response)
|
62
|
+
def edit_response(content: nil, embeds: nil, allowed_mentions: nil, components: nil, &)
|
63
|
+
@interaction.edit_response(content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components, &)
|
64
|
+
end
|
65
|
+
|
66
|
+
# (see Interaction#delete_response)
|
67
|
+
def delete_response
|
68
|
+
@interaction.delete_response
|
69
|
+
end
|
70
|
+
|
71
|
+
# (see Interaction#send_message)
|
72
|
+
def send_message(content: nil, embeds: nil, tts: false, allowed_mentions: nil, flags: 0, ephemeral: nil, components: nil, &)
|
73
|
+
@interaction.send_message(content: content, embeds: embeds, tts: tts, allowed_mentions: allowed_mentions, flags: flags, ephemeral: ephemeral, components: components, &)
|
74
|
+
end
|
75
|
+
|
76
|
+
# (see Interaction#edit_message)
|
77
|
+
def edit_message(message, content: nil, embeds: nil, allowed_mentions: nil, &)
|
78
|
+
@interaction.edit_message(message, content: content, embeds: embeds, allowed_mentions: allowed_mentions, &)
|
79
|
+
end
|
80
|
+
|
81
|
+
# (see Interaction#delete_message)
|
82
|
+
def delete_message(message)
|
83
|
+
@interaction.delete_message(message)
|
84
|
+
end
|
85
|
+
|
86
|
+
# (see Interaction#defer_update)
|
87
|
+
def defer_update
|
88
|
+
@interaction.defer_update
|
89
|
+
end
|
90
|
+
|
91
|
+
# (see Interaction#get_component)
|
92
|
+
def get_component(custom_id)
|
93
|
+
@interaction.get_component(custom_id)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Event handler for INTERACTION_CREATE events.
|
98
|
+
class InteractionCreateEventHandler < EventHandler
|
99
|
+
# @!visibility private
|
100
|
+
def matches?(event)
|
101
|
+
return false unless event.is_a? InteractionCreateEvent
|
102
|
+
|
103
|
+
[
|
104
|
+
matches_all(@attributes[:type], event.type) do |a, e|
|
105
|
+
a == case a
|
106
|
+
when String, Symbol
|
107
|
+
Rubycord::Interactions::TYPES[e.to_sym]
|
108
|
+
else
|
109
|
+
e
|
110
|
+
end
|
111
|
+
end,
|
112
|
+
|
113
|
+
matches_all(@attributes[:server], event.interaction) do |a, e|
|
114
|
+
a.resolve_id == e.server_id
|
115
|
+
end,
|
116
|
+
|
117
|
+
matches_all(@attributes[:channel], event.interaction) do |a, e|
|
118
|
+
a.resolve_id == e.channel_id
|
119
|
+
end,
|
120
|
+
|
121
|
+
matches_all(@attributes[:user], event.user) do |a, e|
|
122
|
+
a.resolve_id == e.id
|
123
|
+
end
|
124
|
+
].reduce(true, &:&)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Event for ApplicationCommand interactions.
|
129
|
+
class ApplicationCommandEvent < InteractionCreateEvent
|
130
|
+
# Struct to allow accessing data via [] or methods.
|
131
|
+
Resolved = Struct.new("Resolved", :channels, :members, :messages, :roles, :users, :attachments)
|
132
|
+
|
133
|
+
# @return [String] The name of the command.
|
134
|
+
attr_reader :command_name
|
135
|
+
|
136
|
+
# @return [Integer] The ID of the command.
|
137
|
+
attr_reader :command_id
|
138
|
+
|
139
|
+
# @return [String, nil] The name of the subcommand group relevant to this event.
|
140
|
+
attr_reader :subcommand_group
|
141
|
+
|
142
|
+
# @return [String, nil] The name of the subcommand relevant to this event.
|
143
|
+
attr_reader :subcommand
|
144
|
+
|
145
|
+
# @return [Resolved]
|
146
|
+
attr_reader :resolved
|
147
|
+
|
148
|
+
# @return [Hash<Symbol, Object>] Arguments provided to the command, mapped as `Name => Value`.
|
149
|
+
attr_reader :options
|
150
|
+
|
151
|
+
# @return [Integer, nil] The target of this command when it is a context command.
|
152
|
+
attr_reader :target_id
|
153
|
+
|
154
|
+
def initialize(data, bot)
|
155
|
+
super
|
156
|
+
|
157
|
+
command_data = data["data"]
|
158
|
+
|
159
|
+
@command_id = command_data["id"]
|
160
|
+
@command_name = command_data["name"].to_sym
|
161
|
+
|
162
|
+
@target_id = command_data["target_id"]&.to_i
|
163
|
+
@resolved = Resolved.new({}, {}, {}, {}, {}, {})
|
164
|
+
process_resolved(command_data["resolved"]) if command_data["resolved"]
|
165
|
+
|
166
|
+
options = command_data["options"] || []
|
167
|
+
|
168
|
+
if options.empty?
|
169
|
+
@options = {}
|
170
|
+
return
|
171
|
+
end
|
172
|
+
|
173
|
+
case options[0]["type"]
|
174
|
+
when 2
|
175
|
+
options = options[0]
|
176
|
+
@subcommand_group = options["name"].to_sym
|
177
|
+
@subcommand = options["options"][0]["name"].to_sym
|
178
|
+
options = options["options"][0]["options"]
|
179
|
+
when 1
|
180
|
+
options = options[0]
|
181
|
+
@subcommand = options["name"].to_sym
|
182
|
+
options = options["options"]
|
183
|
+
end
|
184
|
+
|
185
|
+
@options = transform_options_hash(options || {})
|
186
|
+
end
|
187
|
+
|
188
|
+
# @return [Message, User, nil] The target of this command, for context commands.
|
189
|
+
def target
|
190
|
+
return nil unless @target_id
|
191
|
+
|
192
|
+
@resolved.find { |data| data.key?(@target_id) }[@target_id]
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def process_resolved(resolved_data)
|
198
|
+
resolved_data["users"]&.each do |id, data|
|
199
|
+
@resolved[:users][id.to_i] = @bot.ensure_user(data)
|
200
|
+
end
|
201
|
+
|
202
|
+
resolved_data["roles"]&.each do |id, data|
|
203
|
+
@resolved[:roles][id.to_i] = Rubycord::Role.new(data, @bot)
|
204
|
+
end
|
205
|
+
|
206
|
+
resolved_data["channels"]&.each do |id, data|
|
207
|
+
data["guild_id"] = @interaction.server_id
|
208
|
+
@resolved[:channels][id.to_i] = Rubycord::Channel.new(data, @bot)
|
209
|
+
end
|
210
|
+
|
211
|
+
resolved_data["members"]&.each do |id, data|
|
212
|
+
data["user"] = resolved_data["users"][id]
|
213
|
+
data["guild_id"] = @interaction.server_id
|
214
|
+
@resolved[:members][id.to_i] = Rubycord::Member.new(data, nil, @bot)
|
215
|
+
end
|
216
|
+
|
217
|
+
resolved_data["messages"]&.each do |id, data|
|
218
|
+
@resolved[:messages][id.to_i] = Rubycord::Message.new(data, @bot)
|
219
|
+
end
|
220
|
+
|
221
|
+
resolved_data["attachments"]&.each do |id, data|
|
222
|
+
@resolved[:attachments][id.to_i] = Rubycord::Attachment.new(data, nil, @bot)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def transform_options_hash(hash)
|
227
|
+
hash.to_h { |opt| [opt["name"], opt["options"] || opt["value"]] }
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Event handler for ApplicationCommandEvents.
|
232
|
+
class ApplicationCommandEventHandler < EventHandler
|
233
|
+
# @return [Hash]
|
234
|
+
attr_reader :subcommands
|
235
|
+
|
236
|
+
# @!visibility private
|
237
|
+
def initialize(attributes, block)
|
238
|
+
super
|
239
|
+
|
240
|
+
@subcommands = {}
|
241
|
+
end
|
242
|
+
|
243
|
+
# @param name [Symbol, String]
|
244
|
+
# @yieldparam [SubcommandBuilder]
|
245
|
+
# @return [ApplicationCommandEventHandler]
|
246
|
+
def group(name)
|
247
|
+
raise ArgumentError, "Unable to mix subcommands and groups" if @subcommands.any? { |_, v| v.is_a? Proc }
|
248
|
+
|
249
|
+
builder = SubcommandBuilder.new(name)
|
250
|
+
yield builder
|
251
|
+
|
252
|
+
@subcommands.merge!(builder.to_h)
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
256
|
+
# @param name [String, Symbol]
|
257
|
+
# @yieldparam [SubcommandBuilder]
|
258
|
+
# @return [ApplicationCommandEventHandler]
|
259
|
+
def subcommand(name, &block)
|
260
|
+
raise ArgumentError, "Unable to mix subcommands and groups" if @subcommands.any? { |_, v| v.is_a? Hash }
|
261
|
+
|
262
|
+
@subcommands[name.to_sym] = block
|
263
|
+
|
264
|
+
self
|
265
|
+
end
|
266
|
+
|
267
|
+
# @!visibility private
|
268
|
+
# @param event [Event]
|
269
|
+
def call(event)
|
270
|
+
return unless matches?(event)
|
271
|
+
|
272
|
+
if event.subcommand_group
|
273
|
+
unless (cmd = @subcommands.dig(event.subcommand_group, event.subcommand))
|
274
|
+
Rubycord::LOGGER.debug("Received an event for an unhandled subcommand `#{event.command_name} #{event.subcommand_group} #{event.subcommand}'")
|
275
|
+
return
|
276
|
+
end
|
277
|
+
|
278
|
+
cmd.call(event)
|
279
|
+
elsif event.subcommand
|
280
|
+
unless (cmd = @subcommands[event.subcommand])
|
281
|
+
Rubycord::LOGGER.debug("Received an event for an unhandled subcommand `#{event.command_name} #{event.subcommand}'")
|
282
|
+
return
|
283
|
+
end
|
284
|
+
|
285
|
+
cmd.call(event)
|
286
|
+
else
|
287
|
+
@block.call(event)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
# @!visibility private
|
292
|
+
def matches?(event)
|
293
|
+
return false unless event.is_a? ApplicationCommandEvent
|
294
|
+
|
295
|
+
[
|
296
|
+
matches_all(@attributes[:name], event.command_name) do |a, e|
|
297
|
+
a.to_sym == e.to_sym
|
298
|
+
end
|
299
|
+
].reduce(true, &:&)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# Builder for adding subcommands to an ApplicationCommandHandler
|
304
|
+
class SubcommandBuilder
|
305
|
+
# @!visibility private
|
306
|
+
# @param group [String, Symbol, nil]
|
307
|
+
def initialize(group = nil)
|
308
|
+
@group = group&.to_sym
|
309
|
+
@subcommands = {}
|
310
|
+
end
|
311
|
+
|
312
|
+
# @param name [Symbol, String]
|
313
|
+
# @yieldparam [ApplicationCommandEvent]
|
314
|
+
def subcommand(name, &block)
|
315
|
+
@subcommands[name.to_sym] = block
|
316
|
+
end
|
317
|
+
|
318
|
+
# @!visibility private
|
319
|
+
def to_h
|
320
|
+
@group ? {@group => @subcommands} : @subcommands
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
# An event for when a user interacts with a component.
|
325
|
+
class ComponentEvent < InteractionCreateEvent
|
326
|
+
# @return [String] User provided data for this button.
|
327
|
+
attr_reader :custom_id
|
328
|
+
|
329
|
+
# @return [Interactions::Message, nil] The message the button originates from.
|
330
|
+
attr_reader :message
|
331
|
+
|
332
|
+
# @!visibility private
|
333
|
+
def initialize(data, bot)
|
334
|
+
super
|
335
|
+
|
336
|
+
@message = Rubycord::Interactions::Message.new(data["message"], bot, @interaction) if data["message"]
|
337
|
+
@custom_id = data["data"]["custom_id"]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
# Generic handler for component events.
|
342
|
+
class ComponentEventHandler < InteractionCreateEventHandler
|
343
|
+
def matches?(event)
|
344
|
+
return false unless super
|
345
|
+
return false unless event.is_a? ComponentEvent
|
346
|
+
|
347
|
+
[
|
348
|
+
matches_all(@attributes[:custom_id], event.custom_id) do |a, e|
|
349
|
+
# Match regexp and strings
|
350
|
+
case a
|
351
|
+
when Regexp
|
352
|
+
a.match?(e)
|
353
|
+
else
|
354
|
+
a == e
|
355
|
+
end
|
356
|
+
end,
|
357
|
+
matches_all(@attributes[:message], event.message) do |a, e|
|
358
|
+
case a
|
359
|
+
when String, Integer
|
360
|
+
a.resolve_id == e.id
|
361
|
+
else
|
362
|
+
a.id == e.id
|
363
|
+
end
|
364
|
+
end
|
365
|
+
].reduce(&:&)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
# An event for when a user interacts with a button component.
|
370
|
+
class ButtonEvent < ComponentEvent
|
371
|
+
end
|
372
|
+
|
373
|
+
# Event handler for a Button interaction event.
|
374
|
+
class ButtonEventHandler < ComponentEventHandler
|
375
|
+
end
|
376
|
+
|
377
|
+
# Event for when a user interacts with a select string component.
|
378
|
+
class StringSelectEvent < ComponentEvent
|
379
|
+
# @return [Array<String>] Selected values.
|
380
|
+
attr_reader :values
|
381
|
+
|
382
|
+
# @!visibility private
|
383
|
+
def initialize(data, bot)
|
384
|
+
super
|
385
|
+
|
386
|
+
@values = data["data"]["values"]
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
# Event handler for a select string component.
|
391
|
+
class StringSelectEventHandler < ComponentEventHandler
|
392
|
+
end
|
393
|
+
|
394
|
+
# An event for when a user submits a modal.
|
395
|
+
class ModalSubmitEvent < ComponentEvent
|
396
|
+
# @return [Array<TextInputComponent>]
|
397
|
+
attr_reader :components
|
398
|
+
|
399
|
+
# Get the value of an input passed to the modal.
|
400
|
+
# @param custom_id [String] The custom ID of the component to look for.
|
401
|
+
# @return [String, nil]
|
402
|
+
def value(custom_id)
|
403
|
+
get_component(custom_id)&.value
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
# Event handler for a modal submission.
|
408
|
+
class ModalSubmitEventHandler < ComponentEventHandler
|
409
|
+
end
|
410
|
+
|
411
|
+
# Event for when a user interacts with a select user component.
|
412
|
+
class UserSelectEvent < ComponentEvent
|
413
|
+
# @return [Array<User>] Selected values.
|
414
|
+
attr_reader :values
|
415
|
+
|
416
|
+
# @!visibility private
|
417
|
+
def initialize(data, bot)
|
418
|
+
super
|
419
|
+
|
420
|
+
@values = data["data"]["values"].map { |e| bot.user(e) }
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
# Event handler for a select user component.
|
425
|
+
class UserSelectEventHandler < ComponentEventHandler
|
426
|
+
end
|
427
|
+
|
428
|
+
# Event for when a user interacts with a select role component.
|
429
|
+
class RoleSelectEvent < ComponentEvent
|
430
|
+
# @return [Array<Role>] Selected values.
|
431
|
+
attr_reader :values
|
432
|
+
|
433
|
+
# @!visibility private
|
434
|
+
def initialize(data, bot)
|
435
|
+
super
|
436
|
+
|
437
|
+
@values = data["data"]["values"].map { |e| bot.server(data["guild_id"]).role(e) }
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# Event handler for a select role component.
|
442
|
+
class RoleSelectEventHandler < ComponentEventHandler
|
443
|
+
end
|
444
|
+
|
445
|
+
# Event for when a user interacts with a select mentionable component.
|
446
|
+
class MentionableSelectEvent < ComponentEvent
|
447
|
+
# @return [Hash<Symbol => Array<User>, Symbol => Array<Role>>] Selected values.
|
448
|
+
attr_reader :values
|
449
|
+
|
450
|
+
# @!visibility private
|
451
|
+
def initialize(data, bot)
|
452
|
+
super
|
453
|
+
|
454
|
+
users = data["data"]["resolved"]["users"].keys.map { |e| bot.user(e) }
|
455
|
+
roles = data["data"]["resolved"]["roles"] ? data["data"]["resolved"]["roles"].keys.map { |e| bot.server(data["guild_id"]).role(e) } : []
|
456
|
+
@values = {users: users, roles: roles}
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
# Event handler for a select mentionable component.
|
461
|
+
class MentionableSelectEventHandler < ComponentEventHandler
|
462
|
+
end
|
463
|
+
|
464
|
+
# Event for when a user interacts with a select channel component.
|
465
|
+
class ChannelSelectEvent < ComponentEvent
|
466
|
+
# @return [Array<Channel>] Selected values.
|
467
|
+
attr_reader :values
|
468
|
+
|
469
|
+
# @!visibility private
|
470
|
+
def initialize(data, bot)
|
471
|
+
super
|
472
|
+
|
473
|
+
@values = data["data"]["values"].map { |e| bot.channel(e, bot.server(data["guild_id"])) }
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
# Event handler for a select channel component.
|
478
|
+
class ChannelSelectEventHandler < ComponentEventHandler
|
479
|
+
end
|
480
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module Rubycord::Events
|
2
|
+
# Raised when an invite is created.
|
3
|
+
class InviteCreateEvent < Event
|
4
|
+
# @return [Invite] The invite that was created.
|
5
|
+
attr_reader :invite
|
6
|
+
|
7
|
+
# @return [Server, nil] The server the invite was created for.
|
8
|
+
attr_reader :server
|
9
|
+
|
10
|
+
# @return [Channel] The channel the invite was created for.
|
11
|
+
attr_reader :channel
|
12
|
+
|
13
|
+
# @!attribute [r] code
|
14
|
+
# @return [String] The code for the created invite.
|
15
|
+
# @see Invite#code
|
16
|
+
# @!attribute [r] created_at
|
17
|
+
# @return [Time] The time the invite was created at.
|
18
|
+
# @see Invite#created_at
|
19
|
+
# @!attribute [r] max_age
|
20
|
+
# @return [Integer] The maximum age of the created invite.
|
21
|
+
# @see Invite#max_age
|
22
|
+
# @!attribute [r] max_uses
|
23
|
+
# @return [Integer] The maximum number of uses before the invite expires.
|
24
|
+
# @see Invite#max_uses
|
25
|
+
# @!attribute [r] temporary
|
26
|
+
# @return [true, false] Whether or not this invite grants temporary membership.
|
27
|
+
# @see Invite#temporary
|
28
|
+
# @!attribute [r] inviter
|
29
|
+
# @return [User] The user that created the invite.
|
30
|
+
# @see Invite#inviter
|
31
|
+
delegate :code, :created_at, :max_age, :max_uses, :temporary, :inviter, to: :invite
|
32
|
+
|
33
|
+
alias_method :temporary?, :temporary
|
34
|
+
|
35
|
+
def initialize(data, invite, bot)
|
36
|
+
@bot = bot
|
37
|
+
@invite = invite
|
38
|
+
@channel = bot.channel(data["channel_id"])
|
39
|
+
@server = bot.server(data["guild_id"]) if data["guild_id"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Raised when an invite is deleted.
|
44
|
+
class InviteDeleteEvent < Event
|
45
|
+
# @return [Channel] The channel the deleted invite was for.
|
46
|
+
attr_reader :channel
|
47
|
+
|
48
|
+
# @return [Server, nil] The server the deleted invite was for.
|
49
|
+
attr_reader :server
|
50
|
+
|
51
|
+
# @return [String] The code of the deleted invite.
|
52
|
+
attr_reader :code
|
53
|
+
|
54
|
+
def initialize(data, bot)
|
55
|
+
@bot = bot
|
56
|
+
@channel = bot.channel(data["channel_id"])
|
57
|
+
@server = bot.server(data["guild_id"]) if data["guild_id"]
|
58
|
+
@code = data["code"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Event handler for InviteCreateEvent.
|
63
|
+
class InviteCreateEventHandler < EventHandler
|
64
|
+
def matches?(event)
|
65
|
+
return false unless event.is_a? InviteCreateEvent
|
66
|
+
|
67
|
+
[
|
68
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
69
|
+
a == case a
|
70
|
+
when String
|
71
|
+
e.name
|
72
|
+
when Integer
|
73
|
+
e.id
|
74
|
+
else
|
75
|
+
e
|
76
|
+
end
|
77
|
+
end,
|
78
|
+
matches_all(@attributes[:channel], event.channel) do |a, e|
|
79
|
+
a == case a
|
80
|
+
when String
|
81
|
+
e.name
|
82
|
+
when Integer
|
83
|
+
e.id
|
84
|
+
else
|
85
|
+
e
|
86
|
+
end
|
87
|
+
end,
|
88
|
+
matches_all(@attributes[:temporary], event.temporary?, &:==),
|
89
|
+
matches_all(@attributes[:inviter], event.inviter, &:==)
|
90
|
+
].reduce(true, &:&)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Event handler for InviteDeleteEvent
|
95
|
+
class InviteDeleteEventHandler < EventHandler
|
96
|
+
def matches?(event)
|
97
|
+
return false unless event.is_a? InviteDeleteEvent
|
98
|
+
|
99
|
+
[
|
100
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
101
|
+
a == case a
|
102
|
+
when String
|
103
|
+
e.name
|
104
|
+
when Integer
|
105
|
+
e.id
|
106
|
+
else
|
107
|
+
e
|
108
|
+
end
|
109
|
+
end,
|
110
|
+
matches_all(@attributes[:channel], event.channel) do |a, e|
|
111
|
+
a == case a
|
112
|
+
when String
|
113
|
+
e.name
|
114
|
+
when Integer
|
115
|
+
e.id
|
116
|
+
else
|
117
|
+
e
|
118
|
+
end
|
119
|
+
end
|
120
|
+
].reduce(true, &:&)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
|
3
|
+
module Rubycord::Events
|
4
|
+
# Common superclass for all lifetime events
|
5
|
+
class LifetimeEvent < Event
|
6
|
+
# @!visibility private
|
7
|
+
def initialize(bot)
|
8
|
+
@bot = bot
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# @see Rubycord::EventContainer#ready
|
13
|
+
class ReadyEvent < LifetimeEvent; end
|
14
|
+
|
15
|
+
# Event handler for {ReadyEvent}
|
16
|
+
class ReadyEventHandler < TrueEventHandler; end
|
17
|
+
|
18
|
+
# @see Rubycord::EventContainer#disconnected
|
19
|
+
class DisconnectEvent < LifetimeEvent; end
|
20
|
+
|
21
|
+
# Event handler for {DisconnectEvent}
|
22
|
+
class DisconnectEventHandler < TrueEventHandler; end
|
23
|
+
|
24
|
+
# @see Rubycord::EventContainer#heartbeat
|
25
|
+
class HeartbeatEvent < LifetimeEvent; end
|
26
|
+
|
27
|
+
# Event handler for {HeartbeatEvent}
|
28
|
+
class HeartbeatEventHandler < TrueEventHandler; end
|
29
|
+
end
|