onyxcord-webhooks 1.1.3 → 1.1.4
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/lib/onyxcord/webhooks/version.rb +1 -1
- data/lib/onyxcord/webhooks/view.rb +30 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e982f78ebf7f9a4d5d617e1cbe254864ff1917315ad1cd276b19c0b984ba3970
|
|
4
|
+
data.tar.gz: b1d2f272611a9b979ebb11449a3c3933ae93cf8f4ffa9ced85e0f876664e61b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 144cff3d1f4f0a8905e52c4d4fbe1355a0c7a2414075e922ee7b21661b75a908ff10e711259def51512e3121b6c6080c8d053e119021f3d3ced93233c706dea8
|
|
7
|
+
data.tar.gz: 81dc22284b71cc4dea50f7ed99428f0adfc88eee0d3e10c989caa743e28a10d3deb4a7e3f89a65fc61a3707bffae11d5d69885f1c06a86c604bf185fcf571d33
|
|
@@ -279,7 +279,9 @@ class OnyxCord::Webhooks::View
|
|
|
279
279
|
# @param url [String] An `attachment://<filename>` reference to the attached file.
|
|
280
280
|
# @param id [Integer, nil] The unique 32-bit ID of the file component.
|
|
281
281
|
# @param spoiler [true, false] Whether or not to apply a spoiler label to the file.
|
|
282
|
-
def initialize(url
|
|
282
|
+
def initialize(url = nil, id: nil, spoiler: false, **kwargs)
|
|
283
|
+
url = kwargs.fetch(:url, url)
|
|
284
|
+
|
|
283
285
|
@id = id
|
|
284
286
|
@file = { url: }
|
|
285
287
|
@spoiler = spoiler
|
|
@@ -296,10 +298,12 @@ class OnyxCord::Webhooks::View
|
|
|
296
298
|
# Create a media gallery component.
|
|
297
299
|
# @param id [Integer, nil] The unique 32-bit ID of the media gallery component.
|
|
298
300
|
# @yieldparam builder [MediaGalleryBuilder] Yields the initialized media gallery component.
|
|
299
|
-
def initialize(id: nil)
|
|
301
|
+
def initialize(*items, id: nil)
|
|
300
302
|
@id = id
|
|
301
303
|
@items = []
|
|
302
304
|
|
|
305
|
+
items.each { |item| self.item(item) }
|
|
306
|
+
|
|
303
307
|
yield self if block_given?
|
|
304
308
|
end
|
|
305
309
|
|
|
@@ -307,14 +311,32 @@ class OnyxCord::Webhooks::View
|
|
|
307
311
|
# @param url [String] The URL to the gallery item's media.
|
|
308
312
|
# @param description [String, nil] The description of the gallery item.
|
|
309
313
|
# @param spoiler [true, false] Whether or not to apply a spoiler label to the gallery item.
|
|
310
|
-
def item(url
|
|
311
|
-
|
|
314
|
+
def item(item = nil, url: nil, description: nil, spoiler: nil)
|
|
315
|
+
url, description, spoiler = normalize_item(item, url, description, spoiler)
|
|
316
|
+
raise ArgumentError, 'media gallery item requires a url' if url.nil? || url.to_s.empty?
|
|
317
|
+
|
|
318
|
+
@items << { media: { url: url }, description: description, spoiler: spoiler }.compact
|
|
312
319
|
end
|
|
313
320
|
|
|
314
321
|
# @!visibility private
|
|
315
322
|
def to_h
|
|
316
323
|
{ type: COMPONENT_TYPES[:media_gallery], id: @id, items: @items }.compact
|
|
317
324
|
end
|
|
325
|
+
|
|
326
|
+
private
|
|
327
|
+
|
|
328
|
+
def normalize_item(item, url, description, spoiler)
|
|
329
|
+
if item.is_a?(Hash)
|
|
330
|
+
media = item[:media] || item['media'] || {}
|
|
331
|
+
url ||= item[:url] || item['url'] || media[:url] || media['url']
|
|
332
|
+
description = item[:description] || item['description'] if description.nil?
|
|
333
|
+
spoiler = item[:spoiler] || item['spoiler'] if spoiler.nil?
|
|
334
|
+
else
|
|
335
|
+
url ||= item
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
[url, description, spoiler.nil? ? false : spoiler]
|
|
339
|
+
end
|
|
318
340
|
end
|
|
319
341
|
|
|
320
342
|
# A section allows you to group together an accessory with text display components.
|
|
@@ -425,8 +447,8 @@ class OnyxCord::Webhooks::View
|
|
|
425
447
|
|
|
426
448
|
# Add a media gallery component to the container.
|
|
427
449
|
# @see MediaGalleryBuilder#initialize
|
|
428
|
-
def media_gallery(
|
|
429
|
-
@components << MediaGalleryBuilder.new(
|
|
450
|
+
def media_gallery(*items, id: nil, &block)
|
|
451
|
+
@components << MediaGalleryBuilder.new(*items, id: id, &block)
|
|
430
452
|
end
|
|
431
453
|
|
|
432
454
|
# Set the color of the container.
|
|
@@ -547,8 +569,8 @@ class OnyxCord::Webhooks::View
|
|
|
547
569
|
|
|
548
570
|
# Add a media gallery component to the view.
|
|
549
571
|
# @see MediaGalleryBuilder#initialize
|
|
550
|
-
def media_gallery(id: nil, &block)
|
|
551
|
-
builder = MediaGalleryBuilder.new(id: id)
|
|
572
|
+
def media_gallery(*items, id: nil, &block)
|
|
573
|
+
builder = MediaGalleryBuilder.new(*items, id: id)
|
|
552
574
|
@components << builder
|
|
553
575
|
yield builder if block_given?
|
|
554
576
|
builder
|