discorb 0.19.0 → 0.20.0

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