discorb 0.19.0 → 0.20.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/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/embed.rb
CHANGED
@@ -1,398 +1,404 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents an embed of discord.
|
6
|
-
#
|
7
|
-
class Embed
|
8
|
-
# @return [String, nil] The title of embed.
|
9
|
-
attr_accessor :title
|
10
|
-
# @return [String, nil] The description of embed.
|
11
|
-
attr_accessor :description
|
12
|
-
# @return [String, nil] The url of embed.
|
13
|
-
attr_accessor :url
|
14
|
-
# @return [Time, nil] The timestamp of embed.
|
15
|
-
attr_accessor :timestamp
|
16
|
-
# @return [Discorb::Color, nil] The color of embed.
|
17
|
-
attr_accessor :color
|
18
|
-
# @return [Discorb::Embed::Author, nil] The author of embed.
|
19
|
-
attr_accessor :author
|
20
|
-
# @return [Array<Discorb::Embed::Field>] The fields of embed.
|
21
|
-
attr_accessor :fields
|
22
|
-
# @return [Discorb::Embed::Footer, nil] The footer of embed.
|
23
|
-
attr_accessor :footer
|
24
|
-
# @return [Symbol] The type of embed.
|
25
|
-
attr_reader :type
|
26
|
-
attr_reader :image, :thumbnail
|
27
|
-
|
28
|
-
# @!attribute [rw] image
|
29
|
-
# @return [Discorb::Embed::Image] The image of embed.
|
30
|
-
# @!attribute [rw] thumbnail
|
31
|
-
# @return [Discorb::Embed::Thumbnail] The thumbnail of embed.
|
32
|
-
|
33
|
-
#
|
34
|
-
# Initialize a new Embed object.
|
35
|
-
#
|
36
|
-
# @param [String] title The title of embed.
|
37
|
-
# @param [String] description The description of embed.
|
38
|
-
# @param [Discorb::Color, Integer] color The color of embed.
|
39
|
-
# @param [String] url The url of embed.
|
40
|
-
# @param [Time] timestamp The timestamp of embed.
|
41
|
-
# @param [Discorb::Embed::Author] author The author field of embed.
|
42
|
-
# @param [Array<Discorb::Embed::Field>] fields The fields of embed.
|
43
|
-
# @param [Discorb::Embed::Footer] footer The footer of embed.
|
44
|
-
# @param [Discorb::Embed::Image, String] image The image of embed.
|
45
|
-
# @param [Discorb::Embed::Thumbnail, String] thumbnail The thumbnail of embed.
|
46
|
-
#
|
47
|
-
def initialize(
|
48
|
-
title = nil,
|
49
|
-
description = nil,
|
50
|
-
color: nil,
|
51
|
-
url: nil,
|
52
|
-
timestamp: nil,
|
53
|
-
author: nil,
|
54
|
-
fields: nil,
|
55
|
-
footer: nil,
|
56
|
-
image: nil,
|
57
|
-
thumbnail: nil
|
58
|
-
)
|
59
|
-
@title = title
|
60
|
-
@description = description
|
61
|
-
@url = url
|
62
|
-
@timestamp = timestamp
|
63
|
-
@color = color && (color.is_a?(Color) ? color : Color.new(color))
|
64
|
-
@author = author
|
65
|
-
@fields = fields || []
|
66
|
-
@footer = footer
|
67
|
-
@image = image && (image.is_a?(String) ? Image.new(image) : image)
|
68
|
-
@thumbnail =
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# @
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@
|
82
|
-
@
|
83
|
-
@
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
@
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
@
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
#
|
174
|
-
|
175
|
-
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
#
|
195
|
-
#
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
# @
|
211
|
-
#
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
#
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
# @
|
235
|
-
|
236
|
-
# @
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
# @return [
|
271
|
-
|
272
|
-
# @return [
|
273
|
-
# @return [nil] The Image object wasn't created from gateway.
|
274
|
-
attr_reader :
|
275
|
-
|
276
|
-
#
|
277
|
-
|
278
|
-
#
|
279
|
-
# @
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
#
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
# @return [
|
316
|
-
|
317
|
-
# @return [
|
318
|
-
# @return [nil] The Thumbnail object wasn't created from gateway.
|
319
|
-
attr_reader :
|
320
|
-
|
321
|
-
#
|
322
|
-
|
323
|
-
#
|
324
|
-
# @
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
#
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
# @return [
|
361
|
-
attr_reader :
|
362
|
-
|
363
|
-
|
364
|
-
#
|
365
|
-
|
366
|
-
#
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
#
|
388
|
-
|
389
|
-
#
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents an embed of discord.
|
6
|
+
#
|
7
|
+
class Embed
|
8
|
+
# @return [String, nil] The title of embed.
|
9
|
+
attr_accessor :title
|
10
|
+
# @return [String, nil] The description of embed.
|
11
|
+
attr_accessor :description
|
12
|
+
# @return [String, nil] The url of embed.
|
13
|
+
attr_accessor :url
|
14
|
+
# @return [Time, nil] The timestamp of embed.
|
15
|
+
attr_accessor :timestamp
|
16
|
+
# @return [Discorb::Color, nil] The color of embed.
|
17
|
+
attr_accessor :color
|
18
|
+
# @return [Discorb::Embed::Author, nil] The author of embed.
|
19
|
+
attr_accessor :author
|
20
|
+
# @return [Array<Discorb::Embed::Field>] The fields of embed.
|
21
|
+
attr_accessor :fields
|
22
|
+
# @return [Discorb::Embed::Footer, nil] The footer of embed.
|
23
|
+
attr_accessor :footer
|
24
|
+
# @return [Symbol] The type of embed.
|
25
|
+
attr_reader :type
|
26
|
+
attr_reader :image, :thumbnail
|
27
|
+
|
28
|
+
# @!attribute [rw] image
|
29
|
+
# @return [Discorb::Embed::Image] The image of embed.
|
30
|
+
# @!attribute [rw] thumbnail
|
31
|
+
# @return [Discorb::Embed::Thumbnail] The thumbnail of embed.
|
32
|
+
|
33
|
+
#
|
34
|
+
# Initialize a new Embed object.
|
35
|
+
#
|
36
|
+
# @param [String] title The title of embed.
|
37
|
+
# @param [String] description The description of embed.
|
38
|
+
# @param [Discorb::Color, Integer] color The color of embed.
|
39
|
+
# @param [String] url The url of embed.
|
40
|
+
# @param [Time] timestamp The timestamp of embed.
|
41
|
+
# @param [Discorb::Embed::Author] author The author field of embed.
|
42
|
+
# @param [Array<Discorb::Embed::Field>] fields The fields of embed.
|
43
|
+
# @param [Discorb::Embed::Footer] footer The footer of embed.
|
44
|
+
# @param [Discorb::Embed::Image, String] image The image of embed.
|
45
|
+
# @param [Discorb::Embed::Thumbnail, String] thumbnail The thumbnail of embed.
|
46
|
+
#
|
47
|
+
def initialize(
|
48
|
+
title = nil,
|
49
|
+
description = nil,
|
50
|
+
color: nil,
|
51
|
+
url: nil,
|
52
|
+
timestamp: nil,
|
53
|
+
author: nil,
|
54
|
+
fields: nil,
|
55
|
+
footer: nil,
|
56
|
+
image: nil,
|
57
|
+
thumbnail: nil
|
58
|
+
)
|
59
|
+
@title = title
|
60
|
+
@description = description
|
61
|
+
@url = url
|
62
|
+
@timestamp = timestamp
|
63
|
+
@color = color && (color.is_a?(Color) ? color : Color.new(color))
|
64
|
+
@author = author
|
65
|
+
@fields = fields || []
|
66
|
+
@footer = footer
|
67
|
+
@image = image && (image.is_a?(String) ? Image.new(image) : image)
|
68
|
+
@thumbnail =
|
69
|
+
thumbnail &&
|
70
|
+
(thumbnail.is_a?(String) ? Thumbnail.new(thumbnail) : thumbnail)
|
71
|
+
@type = :rich
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Initialize embed from hash.
|
76
|
+
# @private
|
77
|
+
#
|
78
|
+
# @param [Hash] data The hash data to initialize embed.
|
79
|
+
#
|
80
|
+
def initialize_hash(data)
|
81
|
+
@title = data[:title]
|
82
|
+
@description = data[:description]
|
83
|
+
@url = data[:url]
|
84
|
+
@timestamp = data[:timestamp] && Time.iso8601(data[:timestamp])
|
85
|
+
@type = data[:type]
|
86
|
+
@color = data[:color] && Color.new(data[:color])
|
87
|
+
@footer =
|
88
|
+
data[:footer] &&
|
89
|
+
Footer.new(data[:footer][:text], icon: data[:footer][:icon_url])
|
90
|
+
@author =
|
91
|
+
if data[:author]
|
92
|
+
Author.new(
|
93
|
+
data[:author][:name],
|
94
|
+
icon: data[:author][:icon_url],
|
95
|
+
url: data[:author][:url]
|
96
|
+
)
|
97
|
+
end
|
98
|
+
@thumbnail = data[:thumbnail] && Thumbnail.new(data[:thumbnail])
|
99
|
+
@image = data[:image] && Image.new(data[:image])
|
100
|
+
@video = data[:video] && Video.new(data[:video])
|
101
|
+
@provider = data[:provider] && Provider.new(data[:provider])
|
102
|
+
@fields =
|
103
|
+
(
|
104
|
+
if data[:fields]
|
105
|
+
data[:fields].map do |f|
|
106
|
+
Field.new(f[:name], f[:value], inline: f[:inline])
|
107
|
+
end
|
108
|
+
else
|
109
|
+
[]
|
110
|
+
end
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def image=(value)
|
115
|
+
@image = value.is_a?(String) ? Image.new(value) : value
|
116
|
+
end
|
117
|
+
|
118
|
+
def thumbnail=(value)
|
119
|
+
@thumbnail = value.is_a?(String) ? Thumbnail.new(value) : value
|
120
|
+
end
|
121
|
+
|
122
|
+
def inspect
|
123
|
+
"#<#{self.class} \"#{@title}\">"
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Convert embed to hash.
|
128
|
+
#
|
129
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-structure Offical Discord API Docs
|
130
|
+
# @return [Hash] Converted embed.
|
131
|
+
#
|
132
|
+
def to_hash
|
133
|
+
# @type var ret: Hash[untyped, untyped]
|
134
|
+
ret = { type: "rich" }
|
135
|
+
ret[:title] = @title if @title
|
136
|
+
ret[:description] = @description if @description
|
137
|
+
ret[:url] = @url if @url
|
138
|
+
ret[:timestamp] = @timestamp&.iso8601 if @timestamp
|
139
|
+
ret[:color] = @color&.to_i if @color
|
140
|
+
ret[:footer] = @footer&.to_hash if @footer
|
141
|
+
ret[:image] = @image&.to_hash if @image
|
142
|
+
ret[:thumbnail] = @thumbnail&.to_hash if @thumbnail
|
143
|
+
ret[:author] = @author&.to_hash if @author
|
144
|
+
ret[:fields] = @fields&.map(&:to_hash) if @fields.any?
|
145
|
+
ret
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.from_hash(data)
|
149
|
+
inst = allocate
|
150
|
+
inst.initialize_hash(data)
|
151
|
+
inst
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# Represents an entry in embed.
|
156
|
+
# @abstract
|
157
|
+
# @private
|
158
|
+
#
|
159
|
+
class Entry
|
160
|
+
def inspect
|
161
|
+
"#<#{self.class}>"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
#
|
166
|
+
# Represents an author of embed.
|
167
|
+
#
|
168
|
+
class Author < Entry
|
169
|
+
# @return [String] The name of author.
|
170
|
+
attr_accessor :name
|
171
|
+
# @return [String, nil] The url of author.
|
172
|
+
attr_accessor :url
|
173
|
+
# @return [String, nil] The icon url of author.
|
174
|
+
attr_accessor :icon
|
175
|
+
|
176
|
+
#
|
177
|
+
# Initialize a new Author object.
|
178
|
+
#
|
179
|
+
# @param [String] name The name of author.
|
180
|
+
# @param [String] url The url of author.
|
181
|
+
# @param [String] icon The icon url of author.
|
182
|
+
#
|
183
|
+
def initialize(name, url: nil, icon: nil)
|
184
|
+
@name = name
|
185
|
+
@url = url
|
186
|
+
@icon = icon
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Convert author to hash.
|
191
|
+
#
|
192
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
|
193
|
+
# Offical Discord API Docs
|
194
|
+
# @return [Hash] Converted author.
|
195
|
+
#
|
196
|
+
def to_hash
|
197
|
+
{ name: @name, url: @url, icon_url: @icon }
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
#
|
202
|
+
# Represemts a footer of embed.
|
203
|
+
#
|
204
|
+
class Footer < Entry
|
205
|
+
attr_accessor :text, :icon
|
206
|
+
|
207
|
+
#
|
208
|
+
# Initialize a new Footer object.
|
209
|
+
#
|
210
|
+
# @param [String] text The text of footer.
|
211
|
+
# @param [String] icon The icon url of footer.
|
212
|
+
#
|
213
|
+
def initialize(text, icon: nil)
|
214
|
+
@text = text
|
215
|
+
@icon = icon
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# Convert footer to hash.
|
220
|
+
#
|
221
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
|
222
|
+
# Offical Discord API Docs
|
223
|
+
# @return [Hash] Converted footer.
|
224
|
+
#
|
225
|
+
def to_hash
|
226
|
+
{ text: @text, icon_url: @icon }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# Represents a field of embed.
|
232
|
+
#
|
233
|
+
class Field < Entry
|
234
|
+
# @return [String] The name of field.
|
235
|
+
attr_accessor :name
|
236
|
+
# @return [String] The value of field.
|
237
|
+
attr_accessor :value
|
238
|
+
# @return [Boolean] Whether the field is inline.
|
239
|
+
attr_accessor :inline
|
240
|
+
|
241
|
+
#
|
242
|
+
# Initialize a new Field object.
|
243
|
+
#
|
244
|
+
# @param [String] name The name of field.
|
245
|
+
# @param [String] value The value of field.
|
246
|
+
# @param [Boolean] inline Whether the field is inline.
|
247
|
+
#
|
248
|
+
def initialize(name, value, inline: true)
|
249
|
+
@name = name
|
250
|
+
@value = value
|
251
|
+
@inline = inline
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Convert field to hash.
|
256
|
+
#
|
257
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
|
258
|
+
# Offical Discord API Docs
|
259
|
+
# @return [Hash] Converted field.
|
260
|
+
#
|
261
|
+
def to_hash
|
262
|
+
{ name: @name, value: @value, inline: @inline }
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
#
|
267
|
+
# Represents an image of embed.
|
268
|
+
#
|
269
|
+
class Image < Entry
|
270
|
+
# @return [String] The url of image.
|
271
|
+
attr_accessor :url
|
272
|
+
# @return [String] The proxy url of image.
|
273
|
+
# @return [nil] The Image object wasn't created from gateway.
|
274
|
+
attr_reader :proxy_url
|
275
|
+
# @return [Integer] The height of image.
|
276
|
+
# @return [nil] The Image object wasn't created from gateway.
|
277
|
+
attr_reader :height
|
278
|
+
# @return [Integer] The width of image.
|
279
|
+
# @return [nil] The Image object wasn't created from gateway.
|
280
|
+
attr_reader :width
|
281
|
+
|
282
|
+
#
|
283
|
+
# Initialize a new Image object.
|
284
|
+
#
|
285
|
+
# @param [String] url URL of image.
|
286
|
+
#
|
287
|
+
def initialize(url)
|
288
|
+
data = url
|
289
|
+
if data.is_a? String
|
290
|
+
@url = data
|
291
|
+
else
|
292
|
+
@url = data[:url]
|
293
|
+
@proxy_url = data[:proxy_url]
|
294
|
+
@height = data[:height]
|
295
|
+
@width = data[:width]
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
#
|
300
|
+
# Convert image to hash for sending.
|
301
|
+
#
|
302
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
|
303
|
+
# Offical Discord API Docs
|
304
|
+
# @return [Hash] Converted image.
|
305
|
+
#
|
306
|
+
def to_hash
|
307
|
+
{ url: @url }
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
#
|
312
|
+
# Represents a thumbnail of embed.
|
313
|
+
#
|
314
|
+
class Thumbnail < Entry
|
315
|
+
# @return [String] The url of thumbnail.
|
316
|
+
attr_accessor :url
|
317
|
+
# @return [String] The proxy url of thumbnail.
|
318
|
+
# @return [nil] The Thumbnail object wasn't created from gateway.
|
319
|
+
attr_reader :proxy_url
|
320
|
+
# @return [Integer] The height of thumbnail.
|
321
|
+
# @return [nil] The Thumbnail object wasn't created from gateway.
|
322
|
+
attr_reader :height
|
323
|
+
# @return [Integer] The width of thumbnail.
|
324
|
+
# @return [nil] The Thumbnail object wasn't created from gateway.
|
325
|
+
attr_reader :width
|
326
|
+
|
327
|
+
#
|
328
|
+
# Initialize a new Thumbnail object.
|
329
|
+
#
|
330
|
+
# @param [String] url URL of thumbnail.
|
331
|
+
#
|
332
|
+
def initialize(url)
|
333
|
+
data = url
|
334
|
+
if data.is_a? String
|
335
|
+
@url = data
|
336
|
+
else
|
337
|
+
@url = data[:url]
|
338
|
+
@proxy_url = data[:proxy_url]
|
339
|
+
@height = data[:height]
|
340
|
+
@width = data[:width]
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
#
|
345
|
+
# Convert thumbnail to hash for sending.
|
346
|
+
#
|
347
|
+
# @see https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
|
348
|
+
# Offical Discord API Docs
|
349
|
+
# @return [Hash] Converted thumbnail.
|
350
|
+
#
|
351
|
+
def to_hash
|
352
|
+
{ url: @url }
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
#
|
357
|
+
# Represents a video of embed.
|
358
|
+
#
|
359
|
+
class Video < Entry
|
360
|
+
# @return [String] The url of video.
|
361
|
+
attr_reader :url
|
362
|
+
# @return [String] The proxy url of video.
|
363
|
+
attr_reader :proxy_url
|
364
|
+
# @return [Integer] The height of video.
|
365
|
+
attr_reader :height
|
366
|
+
# @return [Integer] The width of video.
|
367
|
+
attr_reader :width
|
368
|
+
|
369
|
+
#
|
370
|
+
# Initialize a new Video object.
|
371
|
+
# @private
|
372
|
+
#
|
373
|
+
# @param [Hash] data The data of video.
|
374
|
+
#
|
375
|
+
def initialize(data)
|
376
|
+
@url = data[:url]
|
377
|
+
@proxy_url = data[:proxy_url]
|
378
|
+
@height = data[:height]
|
379
|
+
@width = data[:width]
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
#
|
384
|
+
# Represents a provider of embed.
|
385
|
+
#
|
386
|
+
class Provider < Entry
|
387
|
+
# @return [String] The name of provider.
|
388
|
+
attr_reader :name
|
389
|
+
# @return [String] The url of provider.
|
390
|
+
attr_reader :url
|
391
|
+
|
392
|
+
#
|
393
|
+
# Initialize a new Provider object.
|
394
|
+
# @private
|
395
|
+
#
|
396
|
+
# @param [Hash] data The data of provider.
|
397
|
+
#
|
398
|
+
def initialize(data)
|
399
|
+
@name = data[:name]
|
400
|
+
@url = data[:url]
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|