discordrb 3.7.2 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/discordrb.gemspec +1 -1
- data/lib/discordrb/allowed_mentions.rb +9 -2
- data/lib/discordrb/api/channel.rb +15 -0
- data/lib/discordrb/api/interaction.rb +2 -2
- data/lib/discordrb/api/webhook.rb +2 -2
- data/lib/discordrb/bot.rb +45 -7
- data/lib/discordrb/container.rb +38 -1
- data/lib/discordrb/data/activity.rb +1 -1
- data/lib/discordrb/data/audit_logs.rb +1 -1
- data/lib/discordrb/data/channel.rb +13 -3
- data/lib/discordrb/data/component.rb +422 -73
- data/lib/discordrb/data/emoji.rb +24 -2
- data/lib/discordrb/data/integration.rb +49 -30
- data/lib/discordrb/data/interaction.rb +62 -29
- data/lib/discordrb/data/message.rb +30 -48
- data/lib/discordrb/data/reaction.rb +6 -0
- data/lib/discordrb/data/server.rb +15 -1
- data/lib/discordrb/data/snapshot.rb +6 -4
- data/lib/discordrb/data/webhook.rb +8 -4
- data/lib/discordrb/events/integrations.rb +100 -0
- data/lib/discordrb/events/interactions.rb +71 -37
- data/lib/discordrb/events/message.rb +3 -3
- data/lib/discordrb/version.rb +1 -1
- metadata +7 -6
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'discordrb/data'
|
|
4
|
+
require 'discordrb/events/generic'
|
|
5
|
+
|
|
6
|
+
module Discordrb::Events
|
|
7
|
+
# Generic superclass for integration events.
|
|
8
|
+
class IntegrationEvent < Event
|
|
9
|
+
# @return [Server] the server associated with the event.
|
|
10
|
+
attr_reader :server
|
|
11
|
+
|
|
12
|
+
# @return [Integration] the integration associated with the event.
|
|
13
|
+
attr_reader :integration
|
|
14
|
+
|
|
15
|
+
# @!visibility private
|
|
16
|
+
def initialize(data, bot)
|
|
17
|
+
@bot = bot
|
|
18
|
+
@server = bot.server(data['guild_id'].to_i)
|
|
19
|
+
@integration = Discordrb::Integration.new(data, @bot, @server)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Raised whenever an integration is created.
|
|
24
|
+
class IntegrationCreateEvent < IntegrationEvent; end
|
|
25
|
+
|
|
26
|
+
# Raised whenever an integration is updated.
|
|
27
|
+
class IntegrationUpdateEvent < IntegrationEvent; end
|
|
28
|
+
|
|
29
|
+
# Raised whenever an integration is deleted.
|
|
30
|
+
class IntegrationDeleteEvent < Event
|
|
31
|
+
# @return [Server] the server associated with the event.
|
|
32
|
+
attr_reader :server
|
|
33
|
+
|
|
34
|
+
# @return [Integer] the ID of the integration that was removed.
|
|
35
|
+
attr_reader :integration_id
|
|
36
|
+
|
|
37
|
+
# @return [Integer, nil] the ID of the application that was removed.
|
|
38
|
+
attr_reader :application_id
|
|
39
|
+
|
|
40
|
+
# @!visibility private
|
|
41
|
+
def initialize(data, bot)
|
|
42
|
+
@bot = bot
|
|
43
|
+
@server = bot.server(data['guild_id'].to_i)
|
|
44
|
+
@integration_id = data['id'].to_i
|
|
45
|
+
@application_id = data['application_id']&.to_i
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Generic event handler for integration events.
|
|
50
|
+
class IntegrationEventHandler < EventHandler
|
|
51
|
+
# @!visibility private
|
|
52
|
+
def matches?(event)
|
|
53
|
+
# Check for the proper event type.
|
|
54
|
+
return false unless event.is_a?(IntegrationEvent)
|
|
55
|
+
|
|
56
|
+
[
|
|
57
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
|
58
|
+
a&.resolve_id == e&.resolve_id
|
|
59
|
+
end,
|
|
60
|
+
|
|
61
|
+
matches_all(@attributes[:id], event.integration) do |a, e|
|
|
62
|
+
a&.resolve_id == e&.resolve_id
|
|
63
|
+
end,
|
|
64
|
+
|
|
65
|
+
matches_all(@attributes[:application], event.integration) do |a, e|
|
|
66
|
+
a&.resolve_id == e.application&.resolve_id
|
|
67
|
+
end
|
|
68
|
+
].reduce(true, &:&)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Event handler for INTEGRATION_CREATE events.
|
|
73
|
+
class IntegrationCreateEventHandler < IntegrationEventHandler; end
|
|
74
|
+
|
|
75
|
+
# Event handler for INTEGRATION_UPDATE events.
|
|
76
|
+
class IntegrationUpdateEventHandler < IntegrationEventHandler; end
|
|
77
|
+
|
|
78
|
+
# Event handler for INTEGRATION_DELETE events.
|
|
79
|
+
class IntegrationDeleteEventHandler < EventHandler
|
|
80
|
+
# @!visibility private
|
|
81
|
+
def matches?(event)
|
|
82
|
+
# Check for the proper event type.
|
|
83
|
+
return false unless event.is_a?(IntegrationDeleteEvent)
|
|
84
|
+
|
|
85
|
+
[
|
|
86
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
|
87
|
+
a&.resolve_id == e&.resolve_id
|
|
88
|
+
end,
|
|
89
|
+
|
|
90
|
+
matches_all(@attributes[:id], event.integration_id) do |a, e|
|
|
91
|
+
a&.resolve_id == e&.resolve_id
|
|
92
|
+
end,
|
|
93
|
+
|
|
94
|
+
matches_all(@attributes[:application], event.application_id) do |a, e|
|
|
95
|
+
a&.resolve_id == e&.resolve_id
|
|
96
|
+
end
|
|
97
|
+
].reduce(true, &:&)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -6,6 +6,9 @@ require 'discordrb/data'
|
|
|
6
6
|
module Discordrb::Events
|
|
7
7
|
# Generic subclass for interaction events
|
|
8
8
|
class InteractionCreateEvent < Event
|
|
9
|
+
# Struct to allow accessing data via [] or methods.
|
|
10
|
+
Resolved = Struct.new('Resolved', :channels, :members, :messages, :roles, :users, :attachments) # rubocop:disable Lint/StructNewOverride
|
|
11
|
+
|
|
9
12
|
# @return [Interaction] The interaction for this event.
|
|
10
13
|
attr_reader :interaction
|
|
11
14
|
|
|
@@ -33,7 +36,13 @@ module Discordrb::Events
|
|
|
33
36
|
# @!attribute [r] context
|
|
34
37
|
# @return [Integer]
|
|
35
38
|
# @see Interaction#context
|
|
36
|
-
|
|
39
|
+
# @!attribute [r] user_integration?
|
|
40
|
+
# @return [true, false]
|
|
41
|
+
# @see Interaction#user_integration?
|
|
42
|
+
# @!attribute [r] server_integration?
|
|
43
|
+
# @return [true, false]
|
|
44
|
+
# @see Interaction#server_integration?
|
|
45
|
+
delegate :type, :server, :server_id, :channel, :channel_id, :user, :user_locale, :context, :user_integration?, :server_integration?, to: :interaction
|
|
37
46
|
|
|
38
47
|
# @!visibility private
|
|
39
48
|
def initialize(data, bot)
|
|
@@ -95,6 +104,38 @@ module Discordrb::Events
|
|
|
95
104
|
def get_component(...)
|
|
96
105
|
@interaction.get_component(...)
|
|
97
106
|
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
# @!visibility private
|
|
111
|
+
def process_resolved(resolved_data)
|
|
112
|
+
resolved_data['users']&.each do |id, data|
|
|
113
|
+
@resolved[:users][id.to_i] = @bot.ensure_user(data)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
resolved_data['roles']&.each do |id, data|
|
|
117
|
+
@resolved[:roles][id.to_i] = Discordrb::Role.new(data, @bot)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
resolved_data['channels']&.each do |id, data|
|
|
121
|
+
data['guild_id'] = @interaction.server_id
|
|
122
|
+
@resolved[:channels][id.to_i] = Discordrb::Channel.new(data, @bot)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
resolved_data['members']&.each do |id, data|
|
|
126
|
+
data['user'] = resolved_data['users'][id]
|
|
127
|
+
data['guild_id'] = @interaction.server_id
|
|
128
|
+
@resolved[:members][id.to_i] = Discordrb::Member.new(data, nil, @bot)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
resolved_data['messages']&.each do |id, data|
|
|
132
|
+
@resolved[:messages][id.to_i] = Discordrb::Message.new(data, @bot)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
resolved_data['attachments']&.each do |id, data|
|
|
136
|
+
@resolved[:attachments][id.to_i] = Discordrb::Attachment.new(data, nil, @bot)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
98
139
|
end
|
|
99
140
|
|
|
100
141
|
# Event handler for INTERACTION_CREATE events.
|
|
@@ -130,9 +171,6 @@ module Discordrb::Events
|
|
|
130
171
|
|
|
131
172
|
# Event for ApplicationCommand interactions.
|
|
132
173
|
class ApplicationCommandEvent < InteractionCreateEvent
|
|
133
|
-
# Struct to allow accessing data via [] or methods.
|
|
134
|
-
Resolved = Struct.new('Resolved', :channels, :members, :messages, :roles, :users, :attachments) # rubocop:disable Lint/StructNewOverride
|
|
135
|
-
|
|
136
174
|
# @return [Symbol] The name of the command.
|
|
137
175
|
attr_reader :command_name
|
|
138
176
|
|
|
@@ -145,7 +183,7 @@ module Discordrb::Events
|
|
|
145
183
|
# @return [Symbol, nil] The name of the subcommand relevant to this event.
|
|
146
184
|
attr_reader :subcommand
|
|
147
185
|
|
|
148
|
-
# @return [Resolved]
|
|
186
|
+
# @return [Resolved] The resolved channels, roles, users, members, and attachments for this event.
|
|
149
187
|
attr_reader :resolved
|
|
150
188
|
|
|
151
189
|
# @return [Hash<Symbol, Object>] Arguments provided to the command, mapped as `Name => Value`.
|
|
@@ -198,35 +236,6 @@ module Discordrb::Events
|
|
|
198
236
|
|
|
199
237
|
private
|
|
200
238
|
|
|
201
|
-
def process_resolved(resolved_data)
|
|
202
|
-
resolved_data['users']&.each do |id, data|
|
|
203
|
-
@resolved[:users][id.to_i] = @bot.ensure_user(data)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
resolved_data['roles']&.each do |id, data|
|
|
207
|
-
@resolved[:roles][id.to_i] = Discordrb::Role.new(data, @bot)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
resolved_data['channels']&.each do |id, data|
|
|
211
|
-
data['guild_id'] = @interaction.server_id
|
|
212
|
-
@resolved[:channels][id.to_i] = Discordrb::Channel.new(data, @bot)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
resolved_data['members']&.each do |id, data|
|
|
216
|
-
data['user'] = resolved_data['users'][id]
|
|
217
|
-
data['guild_id'] = @interaction.server_id
|
|
218
|
-
@resolved[:members][id.to_i] = Discordrb::Member.new(data, nil, @bot)
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
resolved_data['messages']&.each do |id, data|
|
|
222
|
-
@resolved[:messages][id.to_i] = Discordrb::Message.new(data, @bot)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
resolved_data['attachments']&.each do |id, data|
|
|
226
|
-
@resolved[:attachments][id.to_i] = Discordrb::Attachment.new(data, nil, @bot)
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
239
|
def transform_options_hash(hash)
|
|
231
240
|
hash.to_h { |opt| [opt['name'], opt['options'] || opt['value']] }
|
|
232
241
|
end
|
|
@@ -397,15 +406,40 @@ module Discordrb::Events
|
|
|
397
406
|
|
|
398
407
|
# An event for when a user submits a modal.
|
|
399
408
|
class ModalSubmitEvent < ComponentEvent
|
|
400
|
-
# @return [Array<
|
|
409
|
+
# @return [Array<Component>] an array of partial component objects that were in the modal.
|
|
401
410
|
attr_reader :components
|
|
402
411
|
|
|
412
|
+
# @return [Resolved] The resolved channels, roles, users, members, and attachments for the modal.
|
|
413
|
+
attr_reader :resolved
|
|
414
|
+
|
|
415
|
+
# @!visibility private
|
|
416
|
+
def initialize(data, bot)
|
|
417
|
+
super
|
|
418
|
+
|
|
419
|
+
@resolved = Resolved.new({}, {}, {}, {}, {}, {})
|
|
420
|
+
process_resolved(data['data']['resolved']) if data['data']['resolved']
|
|
421
|
+
end
|
|
422
|
+
|
|
403
423
|
# Get the value of an input passed to the modal.
|
|
404
424
|
# @param custom_id [String] The custom ID of the component to look for.
|
|
405
|
-
# @return [String, nil]
|
|
425
|
+
# @return [String, nil] The selected value for the component.
|
|
406
426
|
def value(custom_id)
|
|
407
427
|
get_component(custom_id)&.value
|
|
408
428
|
end
|
|
429
|
+
|
|
430
|
+
# Get the selected values from a select menu or file upload component.
|
|
431
|
+
# @param custom_id [String] The custom ID of the component to look for.
|
|
432
|
+
# @return [Array<String>, nil] The values that were chosen for the component.
|
|
433
|
+
def values(custom_id)
|
|
434
|
+
get_component(custom_id)&.values
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
# Get the attachments that a user uploaded in this modal.
|
|
438
|
+
# @param custom_id [String] The custom ID of the file upload component to get attachments for.
|
|
439
|
+
# @return [Array<Attachment>] the attachments that were uploaded to the file upload component.
|
|
440
|
+
def attachments(custom_id)
|
|
441
|
+
values(custom_id)&.map { |id| @resolved[:attachments][id.to_i] } || []
|
|
442
|
+
end
|
|
409
443
|
end
|
|
410
444
|
|
|
411
445
|
# Event handler for a modal submission.
|
|
@@ -455,7 +489,7 @@ module Discordrb::Events
|
|
|
455
489
|
def initialize(data, bot)
|
|
456
490
|
super
|
|
457
491
|
|
|
458
|
-
users = data['data']['resolved']['users'].
|
|
492
|
+
users = data['data']['resolved']['users'].map { |_, user| @bot.ensure_user(user) }
|
|
459
493
|
roles = data['data']['resolved']['roles'] ? data['data']['resolved']['roles'].keys.map { |e| bot.server(data['guild_id']).role(e) } : []
|
|
460
494
|
@values = { users: users, roles: roles }
|
|
461
495
|
end
|
|
@@ -18,7 +18,7 @@ module Discordrb::Events
|
|
|
18
18
|
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
|
|
19
19
|
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
|
|
20
20
|
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
|
|
21
|
-
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2)
|
|
21
|
+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
|
|
22
22
|
# @return [Discordrb::Message] the message that was sent
|
|
23
23
|
def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
|
|
24
24
|
channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
|
|
@@ -33,7 +33,7 @@ module Discordrb::Events
|
|
|
33
33
|
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
|
|
34
34
|
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
|
|
35
35
|
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
|
|
36
|
-
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2)
|
|
36
|
+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
|
|
37
37
|
# @yield [embed] Yields the embed to allow for easy building inside a block.
|
|
38
38
|
# @yieldparam embed [Discordrb::Webhooks::Embed] The embed from the parameters, or a new one.
|
|
39
39
|
# @return [Message] The resulting message.
|
|
@@ -49,7 +49,7 @@ module Discordrb::Events
|
|
|
49
49
|
# @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`
|
|
50
50
|
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
|
|
51
51
|
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
|
|
52
|
-
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2)
|
|
52
|
+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
|
|
53
53
|
def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil, flags = 0)
|
|
54
54
|
channel.send_temporary_message(content, timeout, tts, embed, attachments, allowed_mentions, components, flags)
|
|
55
55
|
end
|
data/lib/discordrb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: discordrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- meew0
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 3.
|
|
89
|
+
version: 3.8.0
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 3.
|
|
96
|
+
version: 3.8.0
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: bundler
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -103,7 +103,7 @@ dependencies:
|
|
|
103
103
|
version: '1.10'
|
|
104
104
|
- - "<"
|
|
105
105
|
- !ruby/object:Gem::Version
|
|
106
|
-
version: '
|
|
106
|
+
version: '5'
|
|
107
107
|
type: :development
|
|
108
108
|
prerelease: false
|
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -113,7 +113,7 @@ dependencies:
|
|
|
113
113
|
version: '1.10'
|
|
114
114
|
- - "<"
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: '
|
|
116
|
+
version: '5'
|
|
117
117
|
- !ruby/object:Gem::Dependency
|
|
118
118
|
name: rake
|
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -344,6 +344,7 @@ files:
|
|
|
344
344
|
- lib/discordrb/events/channels.rb
|
|
345
345
|
- lib/discordrb/events/generic.rb
|
|
346
346
|
- lib/discordrb/events/guilds.rb
|
|
347
|
+
- lib/discordrb/events/integrations.rb
|
|
347
348
|
- lib/discordrb/events/interactions.rb
|
|
348
349
|
- lib/discordrb/events/invites.rb
|
|
349
350
|
- lib/discordrb/events/lifetime.rb
|
|
@@ -399,7 +400,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
399
400
|
- !ruby/object:Gem::Version
|
|
400
401
|
version: '0'
|
|
401
402
|
requirements: []
|
|
402
|
-
rubygems_version:
|
|
403
|
+
rubygems_version: 4.0.10
|
|
403
404
|
specification_version: 4
|
|
404
405
|
summary: Discord API for Ruby
|
|
405
406
|
test_files: []
|