discordrb 3.4.3 → 3.6.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/.devcontainer/Dockerfile +13 -0
- data/.devcontainer/devcontainer.json +29 -0
- data/.devcontainer/postcreate.sh +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -1
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -1
- data/.github/workflows/ci.yml +78 -0
- data/.github/workflows/codeql.yml +65 -0
- data/.github/workflows/deploy.yml +54 -0
- data/.github/workflows/release.yml +45 -0
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +58 -2
- data/CHANGELOG.md +485 -225
- data/LICENSE.txt +1 -1
- data/README.md +38 -26
- data/discordrb-webhooks.gemspec +4 -1
- data/discordrb.gemspec +18 -10
- data/lib/discordrb/api/application.rb +278 -0
- data/lib/discordrb/api/channel.rb +222 -18
- data/lib/discordrb/api/interaction.rb +63 -0
- data/lib/discordrb/api/invite.rb +2 -2
- data/lib/discordrb/api/server.rb +123 -66
- data/lib/discordrb/api/user.rb +20 -5
- data/lib/discordrb/api/webhook.rb +72 -0
- data/lib/discordrb/api.rb +35 -25
- data/lib/discordrb/bot.rb +437 -66
- data/lib/discordrb/cache.rb +41 -22
- data/lib/discordrb/commands/command_bot.rb +13 -21
- data/lib/discordrb/commands/container.rb +1 -1
- data/lib/discordrb/commands/parser.rb +7 -7
- data/lib/discordrb/commands/rate_limiter.rb +1 -1
- data/lib/discordrb/container.rb +178 -3
- data/lib/discordrb/data/activity.rb +1 -1
- data/lib/discordrb/data/application.rb +1 -0
- data/lib/discordrb/data/attachment.rb +38 -3
- data/lib/discordrb/data/audit_logs.rb +3 -3
- data/lib/discordrb/data/avatar_decoration.rb +26 -0
- data/lib/discordrb/data/call.rb +22 -0
- data/lib/discordrb/data/channel.rb +299 -30
- data/lib/discordrb/data/collectibles.rb +45 -0
- data/lib/discordrb/data/component.rb +229 -0
- data/lib/discordrb/data/embed.rb +10 -3
- data/lib/discordrb/data/emoji.rb +20 -1
- data/lib/discordrb/data/integration.rb +45 -3
- data/lib/discordrb/data/interaction.rb +937 -0
- data/lib/discordrb/data/invite.rb +1 -1
- data/lib/discordrb/data/member.rb +236 -44
- data/lib/discordrb/data/message.rb +278 -51
- data/lib/discordrb/data/overwrite.rb +15 -7
- data/lib/discordrb/data/primary_server.rb +60 -0
- data/lib/discordrb/data/profile.rb +2 -7
- data/lib/discordrb/data/reaction.rb +2 -1
- data/lib/discordrb/data/recipient.rb +1 -1
- data/lib/discordrb/data/role.rb +204 -18
- data/lib/discordrb/data/server.rb +194 -118
- data/lib/discordrb/data/server_preview.rb +68 -0
- data/lib/discordrb/data/snapshot.rb +110 -0
- data/lib/discordrb/data/user.rb +132 -12
- data/lib/discordrb/data/voice_region.rb +1 -0
- data/lib/discordrb/data/webhook.rb +99 -9
- data/lib/discordrb/data.rb +9 -0
- data/lib/discordrb/errors.rb +47 -3
- data/lib/discordrb/events/await.rb +1 -1
- data/lib/discordrb/events/channels.rb +38 -1
- data/lib/discordrb/events/generic.rb +2 -0
- data/lib/discordrb/events/guilds.rb +6 -1
- data/lib/discordrb/events/interactions.rb +575 -0
- data/lib/discordrb/events/invites.rb +2 -0
- data/lib/discordrb/events/members.rb +19 -2
- data/lib/discordrb/events/message.rb +42 -8
- data/lib/discordrb/events/presence.rb +23 -14
- data/lib/discordrb/events/raw.rb +1 -0
- data/lib/discordrb/events/reactions.rb +2 -1
- data/lib/discordrb/events/roles.rb +2 -0
- data/lib/discordrb/events/threads.rb +100 -0
- data/lib/discordrb/events/typing.rb +1 -0
- data/lib/discordrb/events/voice_server_update.rb +1 -0
- data/lib/discordrb/events/voice_state_update.rb +1 -0
- data/lib/discordrb/events/webhooks.rb +1 -0
- data/lib/discordrb/gateway.rb +57 -28
- data/lib/discordrb/paginator.rb +3 -3
- data/lib/discordrb/permissions.rb +71 -35
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +2 -2
- data/lib/discordrb/voice/network.rb +18 -7
- data/lib/discordrb/voice/sodium.rb +3 -1
- data/lib/discordrb/voice/voice_bot.rb +3 -3
- data/lib/discordrb/webhooks.rb +2 -0
- data/lib/discordrb/websocket.rb +0 -10
- data/lib/discordrb.rb +54 -5
- metadata +87 -25
- data/.circleci/config.yml +0 -126
- data/.codeclimate.yml +0 -16
- data/.travis.yml +0 -32
- data/bin/travis_build_docs.sh +0 -17
data/lib/discordrb/data/role.rb
CHANGED
|
@@ -16,6 +16,7 @@ module Discordrb
|
|
|
16
16
|
|
|
17
17
|
# @return [true, false] whether or not this role should be displayed separately from other users
|
|
18
18
|
attr_reader :hoist
|
|
19
|
+
alias_method :hoist?, :hoist
|
|
19
20
|
|
|
20
21
|
# @return [true, false] whether or not this role is managed by an integration or a bot
|
|
21
22
|
attr_reader :managed
|
|
@@ -25,13 +26,68 @@ module Discordrb
|
|
|
25
26
|
attr_reader :mentionable
|
|
26
27
|
alias_method :mentionable?, :mentionable
|
|
27
28
|
|
|
28
|
-
# @return [ColourRGB] the
|
|
29
|
+
# @return [ColourRGB] the primary colour of this role.
|
|
29
30
|
attr_reader :colour
|
|
30
31
|
alias_method :color, :colour
|
|
31
32
|
|
|
32
33
|
# @return [Integer] the position of this role in the hierarchy
|
|
33
34
|
attr_reader :position
|
|
34
35
|
|
|
36
|
+
# @return [String, nil] The icon hash for this role.
|
|
37
|
+
attr_reader :icon
|
|
38
|
+
|
|
39
|
+
# @return [Tags, nil] The role tags.
|
|
40
|
+
attr_reader :tags
|
|
41
|
+
|
|
42
|
+
# @return [Integer] The flags for this role.
|
|
43
|
+
attr_reader :flags
|
|
44
|
+
|
|
45
|
+
# @return [String, nil] The unicode emoji of this role, or nil.
|
|
46
|
+
attr_reader :unicode_emoji
|
|
47
|
+
|
|
48
|
+
# @return [ColourRGB, nil] the secondary colour of this role.
|
|
49
|
+
attr_reader :secondary_colour
|
|
50
|
+
alias_method :secondary_color, :secondary_colour
|
|
51
|
+
|
|
52
|
+
# @return [ColourRGB, nil] the tertiary colour of this role.
|
|
53
|
+
attr_reader :tertiary_colour
|
|
54
|
+
alias_method :tertiary_color, :tertiary_colour
|
|
55
|
+
|
|
56
|
+
# Wrapper for the role tags
|
|
57
|
+
class Tags
|
|
58
|
+
# @return [Integer, nil] The ID of the bot this role belongs to
|
|
59
|
+
attr_reader :bot_id
|
|
60
|
+
|
|
61
|
+
# @return [Integer, nil] The ID of the integration this role belongs to
|
|
62
|
+
attr_reader :integration_id
|
|
63
|
+
|
|
64
|
+
# @return [true, false] Whether this is the guild's Booster role
|
|
65
|
+
attr_reader :premium_subscriber
|
|
66
|
+
alias_method :premium_subscriber?, :premium_subscriber
|
|
67
|
+
|
|
68
|
+
# @return [Integer, nil] The id of this role's subscription sku and listing
|
|
69
|
+
attr_reader :subscription_listing_id
|
|
70
|
+
|
|
71
|
+
# @return [true, false] Whether this role is available for purchase
|
|
72
|
+
attr_reader :available_for_purchase
|
|
73
|
+
alias_method :available_for_purchase?, :available_for_purchase
|
|
74
|
+
|
|
75
|
+
# @return [true, false] Whether this role is a guild's linked role
|
|
76
|
+
attr_reader :guild_connections
|
|
77
|
+
alias_method :guild_connections?, :guild_connections
|
|
78
|
+
alias_method :server_connections?, :guild_connections
|
|
79
|
+
|
|
80
|
+
# @!visibility private
|
|
81
|
+
def initialize(data)
|
|
82
|
+
@bot_id = data['bot_id']&.resolve_id
|
|
83
|
+
@integration_id = data['integration_id']&.resolve_id
|
|
84
|
+
@premium_subscriber = data.key?('premium_subscriber')
|
|
85
|
+
@subscription_listing_id = data['subscription_listing_id']&.resolve_id
|
|
86
|
+
@available_for_purchase = data.key?('available_for_purchase')
|
|
87
|
+
@guild_connections = data.key?('guild_connections')
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
35
91
|
# This class is used internally as a wrapper to a Role object that allows easy writing of permission data.
|
|
36
92
|
class RoleWriter
|
|
37
93
|
# @!visibility private
|
|
@@ -56,7 +112,7 @@ module Discordrb
|
|
|
56
112
|
def initialize(data, bot, server = nil)
|
|
57
113
|
@bot = bot
|
|
58
114
|
@server = server
|
|
59
|
-
@permissions = Permissions.new(data['permissions'], RoleWriter.new(self, @bot.token))
|
|
115
|
+
@permissions = Permissions.new(data['permissions'].to_i, RoleWriter.new(self, @bot.token))
|
|
60
116
|
@name = data['name']
|
|
61
117
|
@id = data['id'].to_i
|
|
62
118
|
|
|
@@ -66,7 +122,19 @@ module Discordrb
|
|
|
66
122
|
@mentionable = data['mentionable']
|
|
67
123
|
@managed = data['managed']
|
|
68
124
|
|
|
69
|
-
|
|
125
|
+
colours = data['colors']
|
|
126
|
+
@colour = ColourRGB.new(colours['primary_color'])
|
|
127
|
+
|
|
128
|
+
@icon = data['icon']
|
|
129
|
+
|
|
130
|
+
@tags = Tags.new(data['tags']) if data['tags']
|
|
131
|
+
|
|
132
|
+
@flags = data['flags']
|
|
133
|
+
|
|
134
|
+
@unicode_emoji = data['unicode_emoji']
|
|
135
|
+
|
|
136
|
+
@tertiary_colour = ColourRGB.new(colours['tertiary_color']) if colours['tertiary_color']
|
|
137
|
+
@secondary_colour = ColourRGB.new(colours['secondary_color']) if colours['secondary_color']
|
|
70
138
|
end
|
|
71
139
|
|
|
72
140
|
# @return [String] a string that will mention this role, if it is mentionable.
|
|
@@ -92,16 +160,29 @@ module Discordrb
|
|
|
92
160
|
@colour = other.colour
|
|
93
161
|
@position = other.position
|
|
94
162
|
@managed = other.managed
|
|
163
|
+
@icon = other.icon
|
|
164
|
+
@flags = other.flags
|
|
165
|
+
@unicode_emoji = other.unicode_emoji
|
|
166
|
+
@secondary_colour = other.secondary_colour
|
|
167
|
+
@tertiary_colour = other.tertiary_colour
|
|
95
168
|
end
|
|
96
169
|
|
|
97
170
|
# Updates the data cache from a hash containing data
|
|
98
171
|
# @note For internal use only
|
|
99
172
|
# @!visibility private
|
|
100
173
|
def update_data(new_data)
|
|
101
|
-
@name = new_data[
|
|
102
|
-
@hoist = new_data['hoist']
|
|
103
|
-
@
|
|
104
|
-
@
|
|
174
|
+
@name = new_data['name']
|
|
175
|
+
@hoist = new_data['hoist']
|
|
176
|
+
@icon = new_data['icon']
|
|
177
|
+
@unicode_emoji = new_data['unicode_emoji']
|
|
178
|
+
@position = new_data['position']
|
|
179
|
+
@mentionable = new_data['mentionable']
|
|
180
|
+
@flags = new_data['flags']
|
|
181
|
+
colours = new_data['colors']
|
|
182
|
+
@permissions.bits = new_data['permissions'].to_i
|
|
183
|
+
@colour = ColourRGB.new(colours['primary_color'])
|
|
184
|
+
@secondary_color = ColourRGB.new(colours['secondary_color']) if colours['secondary_color']
|
|
185
|
+
@tertiary_colour = ColourRGB.new(colours['tertiary_color']) if colours['tertiary_color']
|
|
105
186
|
end
|
|
106
187
|
|
|
107
188
|
# Sets the role name to something new
|
|
@@ -122,13 +203,88 @@ module Discordrb
|
|
|
122
203
|
update_role_data(mentionable: mentionable)
|
|
123
204
|
end
|
|
124
205
|
|
|
125
|
-
# Sets the role colour to something new
|
|
126
|
-
# @param colour [ColourRGB] The new colour
|
|
206
|
+
# Sets the primary role colour to something new.
|
|
207
|
+
# @param colour [ColourRGB, Integer, nil] The new colour.
|
|
127
208
|
def colour=(colour)
|
|
128
|
-
|
|
209
|
+
update_colors(primary: colour)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Sets the secondary role colour to something new.
|
|
213
|
+
# @param colour [ColourRGB, Integer, nil] The new secondary colour.
|
|
214
|
+
def secondary_colour=(colour)
|
|
215
|
+
update_colours(secondary: colour)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Sets the tertiary role colour to something new.
|
|
219
|
+
# @param colour [ColourRGB, Integer, nil] The new tertiary colour.
|
|
220
|
+
def tertiary_colour=(colour)
|
|
221
|
+
update_colours(tertiary: colour)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Sets whether the role colour should be a holographic style.
|
|
225
|
+
# @param holographic [true, false] whether the role colour should be a holographic style.
|
|
226
|
+
def holographic=(holographic)
|
|
227
|
+
update_colours(holographic: holographic)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Upload a role icon for servers with the ROLE_ICONS feature.
|
|
231
|
+
# @param file [File, nil] File like object that responds to #read, or nil.
|
|
232
|
+
def icon=(file)
|
|
233
|
+
update_role_data(icon: file)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# Set a role icon to a unicode emoji for servers with the ROLE_ICONS feature.
|
|
237
|
+
# @param emoji [String, nil] The new unicode emoji for this role, or nil.
|
|
238
|
+
def unicode_emoji=(emoji)
|
|
239
|
+
update_role_data(unicode_emoji: emoji)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# @param format ['webp', 'png', 'jpeg']
|
|
243
|
+
# @return [String] URL to the icon on Discord's CDN.
|
|
244
|
+
def icon_url(format = 'webp')
|
|
245
|
+
return nil unless @icon
|
|
246
|
+
|
|
247
|
+
Discordrb::API.role_icon_url(@id, @icon, format)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Get the icon that a role has displayed.
|
|
251
|
+
# @return [String, nil] Icon URL, the unicode emoji, or nil if this role doesn't have any icon.
|
|
252
|
+
# @note A role can have a unicode emoji, and an icon, but only the icon will be shown in the UI.
|
|
253
|
+
def display_icon
|
|
254
|
+
icon_url || unicode_emoji
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Set the icon this role is displaying.
|
|
258
|
+
# @param icon [File, String, nil] File like object that responds to #read, unicode emoji, or nil.
|
|
259
|
+
# @note Setting the icon to nil will remove the unicode emoji **and** the custom icon.
|
|
260
|
+
def display_icon=(icon)
|
|
261
|
+
if icon.nil?
|
|
262
|
+
update_role_data(unicode_emoji: nil, icon: nil)
|
|
263
|
+
return
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
if icon.respond_to?(:read)
|
|
267
|
+
update_role_data(unicode_emoji: nil, icon: icon)
|
|
268
|
+
else
|
|
269
|
+
update_role_data(unicode_emoji: icon, icon: nil)
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Whether or not the role is of the holographic style.
|
|
274
|
+
# @return [true, false]
|
|
275
|
+
def holographic?
|
|
276
|
+
!@tertiary_colour.nil?
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Whether or not the role has a two-point gradient.
|
|
280
|
+
# @return [true, false]
|
|
281
|
+
def gradient?
|
|
282
|
+
!@secondary_colour.nil? && @tertiary_colour.nil?
|
|
129
283
|
end
|
|
130
284
|
|
|
131
285
|
alias_method :color=, :colour=
|
|
286
|
+
alias_method :secondary_color=, :secondary_colour=
|
|
287
|
+
alias_method :tertiary_color=, :tertiary_colour=
|
|
132
288
|
|
|
133
289
|
# Changes this role's permissions to a fixed bitfield. This allows setting multiple permissions at once with just
|
|
134
290
|
# one API call.
|
|
@@ -171,21 +327,51 @@ module Discordrb
|
|
|
171
327
|
@server.delete_role(@id)
|
|
172
328
|
end
|
|
173
329
|
|
|
330
|
+
# A rich interface designed to make working with role colours simple.
|
|
331
|
+
# @param primary [ColourRGB, Integer, nil] The new primary/base colour of this role, or nil to clear the primary colour.
|
|
332
|
+
# @param secondary [ColourRGB, Integer, nil] The new secondary colour of this role, or nil to clear the secondary colour.
|
|
333
|
+
# @param tertiary [ColourRGB, Integer,nil] The new tertiary colour of this role, or nil to clear the tertiary colour.
|
|
334
|
+
# @param holographic [true, false] Whether to apply or remove the holographic style to the role colour, overriding any other
|
|
335
|
+
# arguments that were passed. Using this argument is recommended over passing individual colours.
|
|
336
|
+
def update_colours(primary: :undef, secondary: :undef, tertiary: :undef, holographic: :undef)
|
|
337
|
+
colours = {
|
|
338
|
+
primary_color: (primary == :undef ? @colour : primary)&.to_i,
|
|
339
|
+
tertiary_color: (tertiary == :undef ? @tertiary_colour : tertiary)&.to_i,
|
|
340
|
+
secondary_color: (secondary == :undef ? @secondary_colour : secondary)&.to_i
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
holographic_colours = {
|
|
344
|
+
primary_color: 11_127_295,
|
|
345
|
+
tertiary_color: 16_761_760,
|
|
346
|
+
secondary_color: 16_759_788
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
# Only set the tertiary_color to `nil` if holographic is explicitly set to false.
|
|
350
|
+
colours[:tertiary_color] = nil if holographic.is_a?(FalseClass) && holographic?
|
|
351
|
+
|
|
352
|
+
update_role_data(colours: holographic == true ? holographic_colours : colours)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
alias_method :update_colors, :update_colours
|
|
356
|
+
|
|
174
357
|
# The inspect method is overwritten to give more useful output
|
|
175
358
|
def inspect
|
|
176
|
-
"<Role name=#{@name} permissions=#{@permissions.inspect} hoist=#{@hoist} colour=#{@colour.inspect} server=#{@server.inspect} position=#{@position} mentionable=#{@mentionable}>"
|
|
359
|
+
"<Role name=#{@name} permissions=#{@permissions.inspect} hoist=#{@hoist} colour=#{@colour.inspect} server=#{@server.inspect} position=#{@position} mentionable=#{@mentionable} unicode_emoji=#{@unicode_emoji} flags=#{@flags}>"
|
|
177
360
|
end
|
|
178
361
|
|
|
179
362
|
private
|
|
180
363
|
|
|
181
364
|
def update_role_data(new_data)
|
|
182
|
-
API::Server.update_role(@bot.token, @server.id, @id,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
365
|
+
update_data(JSON.parse(API::Server.update_role(@bot.token, @server.id, @id,
|
|
366
|
+
new_data[:name] || @name,
|
|
367
|
+
:undef,
|
|
368
|
+
new_data.key?(:hoist) ? new_data[:hoist] : :undef,
|
|
369
|
+
new_data.key?(:mentionable) ? new_data[:mentionable] : :undef,
|
|
370
|
+
new_data[:permissions] || @permissions.bits,
|
|
371
|
+
nil,
|
|
372
|
+
new_data.key?(:icon) ? new_data[:icon] : :undef,
|
|
373
|
+
new_data.key?(:unicode_emoji) ? new_data[:unicode_emoji] : :undef,
|
|
374
|
+
new_data.key?(:colours) ? new_data[:colours] : :undef)))
|
|
189
375
|
end
|
|
190
376
|
end
|
|
191
377
|
end
|