onyxcord 2.0.13 → 3.2.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.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onyxcord/application_commands/command.rb +4 -97
  3. data/lib/onyxcord/application_commands/context.rb +4 -94
  4. data/lib/onyxcord/application_commands/option.rb +4 -75
  5. data/lib/onyxcord/application_commands/registry.rb +4 -45
  6. data/lib/onyxcord/application_commands.rb +8 -5
  7. data/lib/onyxcord/bot.rb +24 -1759
  8. data/lib/onyxcord/{cache.rb → cache/manager.rb} +16 -14
  9. data/lib/onyxcord/cache/stores/gateway.rb +272 -0
  10. data/lib/onyxcord/commands/bot/channels.rb +48 -0
  11. data/lib/onyxcord/commands/bot/execution.rb +174 -0
  12. data/lib/onyxcord/commands/bot/message_dispatch.rb +58 -0
  13. data/lib/onyxcord/commands/bot/permissions.rb +72 -0
  14. data/lib/onyxcord/commands/bot.rb +209 -0
  15. data/lib/onyxcord/commands/container.rb +21 -2
  16. data/lib/onyxcord/commands/parser.rb +30 -1
  17. data/lib/onyxcord/container.rb +16 -960
  18. data/lib/onyxcord/core/bot/application_commands.rb +210 -0
  19. data/lib/onyxcord/core/bot/awaits.rb +112 -0
  20. data/lib/onyxcord/core/bot/invites.rb +42 -0
  21. data/lib/onyxcord/core/bot/messaging.rb +161 -0
  22. data/lib/onyxcord/core/bot/oauth.rb +27 -0
  23. data/lib/onyxcord/core/bot/presence.rb +103 -0
  24. data/lib/onyxcord/core/bot/runtime.rb +183 -0
  25. data/lib/onyxcord/core/bot/voice.rb +69 -0
  26. data/lib/onyxcord/{errors.rb → core/errors.rb} +18 -3
  27. data/lib/onyxcord/{logger.rb → core/logger.rb} +5 -0
  28. data/lib/onyxcord/core/version.rb +5 -0
  29. data/lib/onyxcord/events/await/base.rb +48 -0
  30. data/lib/onyxcord/events/await.rb +1 -46
  31. data/lib/onyxcord/events/ban/base.rb +54 -0
  32. data/lib/onyxcord/events/ban/remove.rb +11 -0
  33. data/lib/onyxcord/events/bans.rb +2 -58
  34. data/lib/onyxcord/events/channels/base.rb +91 -0
  35. data/lib/onyxcord/events/channels/delete.rb +73 -0
  36. data/lib/onyxcord/events/channels/pins.rb +44 -0
  37. data/lib/onyxcord/events/channels/recipients.rb +77 -0
  38. data/lib/onyxcord/events/channels.rb +4 -239
  39. data/lib/onyxcord/events/guilds/audit_logs.rb +79 -0
  40. data/lib/onyxcord/events/guilds/base.rb +97 -0
  41. data/lib/onyxcord/events/guilds/emoji.rb +147 -0
  42. data/lib/onyxcord/events/guilds.rb +3 -267
  43. data/lib/onyxcord/events/handlers/channels.rb +133 -0
  44. data/lib/onyxcord/events/handlers/core.rb +146 -0
  45. data/lib/onyxcord/events/handlers/guilds.rb +375 -0
  46. data/lib/onyxcord/events/handlers/interactions.rb +238 -0
  47. data/lib/onyxcord/events/handlers/lifetime.rb +71 -0
  48. data/lib/onyxcord/events/handlers/messages.rb +218 -0
  49. data/lib/onyxcord/events/handlers/presence.rb +56 -0
  50. data/lib/onyxcord/events/handlers/raw.rb +39 -0
  51. data/lib/onyxcord/events/handlers/reactions.rb +98 -0
  52. data/lib/onyxcord/events/handlers/scheduled_events.rb +243 -0
  53. data/lib/onyxcord/events/handlers/voice.rb +46 -0
  54. data/lib/onyxcord/events/integration/base.rb +45 -0
  55. data/lib/onyxcord/events/integration/create.rb +11 -0
  56. data/lib/onyxcord/events/integration/delete.rb +48 -0
  57. data/lib/onyxcord/events/integration/update.rb +11 -0
  58. data/lib/onyxcord/events/integrations.rb +4 -98
  59. data/lib/onyxcord/events/interactions/application_commands.rb +185 -0
  60. data/lib/onyxcord/events/interactions/autocomplete.rb +62 -0
  61. data/lib/onyxcord/events/interactions/base.rb +175 -0
  62. data/lib/onyxcord/events/interactions/components.rb +221 -0
  63. data/lib/onyxcord/events/interactions/permissions.rb +53 -0
  64. data/lib/onyxcord/events/interactions.rb +5 -622
  65. data/lib/onyxcord/events/invite/create.rb +79 -0
  66. data/lib/onyxcord/events/invite/delete.rb +55 -0
  67. data/lib/onyxcord/events/invites.rb +2 -125
  68. data/lib/onyxcord/events/lifetime/base.rb +31 -0
  69. data/lib/onyxcord/events/lifetime.rb +1 -29
  70. data/lib/onyxcord/events/member/add.rb +12 -0
  71. data/lib/onyxcord/events/member/base.rb +67 -0
  72. data/lib/onyxcord/events/member/delete.rb +21 -0
  73. data/lib/onyxcord/events/member/update.rb +25 -0
  74. data/lib/onyxcord/events/members.rb +4 -108
  75. data/lib/onyxcord/events/message/base.rb +295 -0
  76. data/lib/onyxcord/events/message/ids.rb +71 -0
  77. data/lib/onyxcord/events/message/mentions.rb +55 -0
  78. data/lib/onyxcord/events/message/updates.rb +27 -0
  79. data/lib/onyxcord/events/message.rb +4 -397
  80. data/lib/onyxcord/events/poll/add.rb +11 -0
  81. data/lib/onyxcord/events/poll/base.rb +106 -0
  82. data/lib/onyxcord/events/poll/remove.rb +11 -0
  83. data/lib/onyxcord/events/polls.rb +3 -116
  84. data/lib/onyxcord/events/presence/playing.rb +77 -0
  85. data/lib/onyxcord/events/presence/status.rb +60 -0
  86. data/lib/onyxcord/events/presence.rb +2 -129
  87. data/lib/onyxcord/events/raw/base.rb +74 -0
  88. data/lib/onyxcord/events/raw.rb +1 -72
  89. data/lib/onyxcord/events/reactions/base.rb +143 -0
  90. data/lib/onyxcord/events/reactions/clear.rb +99 -0
  91. data/lib/onyxcord/events/reactions.rb +2 -216
  92. data/lib/onyxcord/events/role/create.rb +46 -0
  93. data/lib/onyxcord/events/role/delete.rb +40 -0
  94. data/lib/onyxcord/events/role/update.rb +11 -0
  95. data/lib/onyxcord/events/roles.rb +3 -85
  96. data/lib/onyxcord/events/scheduled_events/events.rb +112 -0
  97. data/lib/onyxcord/events/scheduled_events/users.rb +91 -0
  98. data/lib/onyxcord/events/scheduled_events.rb +2 -169
  99. data/lib/onyxcord/events/thread/base.rb +49 -0
  100. data/lib/onyxcord/events/thread/members.rb +44 -0
  101. data/lib/onyxcord/events/thread/update.rb +18 -0
  102. data/lib/onyxcord/events/threads.rb +3 -98
  103. data/lib/onyxcord/events/typing/base.rb +73 -0
  104. data/lib/onyxcord/events/typing.rb +1 -71
  105. data/lib/onyxcord/events/voice/server_update.rb +48 -0
  106. data/lib/onyxcord/events/voice/state_update.rb +137 -0
  107. data/lib/onyxcord/events/voice_server_update.rb +2 -46
  108. data/lib/onyxcord/events/voice_state_update.rb +2 -135
  109. data/lib/onyxcord/events/webhook/update.rb +65 -0
  110. data/lib/onyxcord/events/webhooks.rb +1 -63
  111. data/lib/onyxcord/gateway/client.rb +460 -0
  112. data/lib/onyxcord/interactions/command.rb +120 -0
  113. data/lib/onyxcord/interactions/context.rb +109 -0
  114. data/lib/onyxcord/interactions/internal/application_command.rb +203 -0
  115. data/lib/onyxcord/interactions/internal/message.rb +152 -0
  116. data/lib/onyxcord/interactions/internal/metadata.rb +109 -0
  117. data/lib/onyxcord/interactions/internal/option_builder.rb +230 -0
  118. data/lib/onyxcord/interactions/internal/permission_builder.rb +90 -0
  119. data/lib/onyxcord/interactions/option.rb +88 -0
  120. data/lib/onyxcord/interactions/registry.rb +50 -0
  121. data/lib/onyxcord/interactions.rb +16 -0
  122. data/lib/onyxcord/internal/async_runtime.rb +32 -0
  123. data/lib/onyxcord/internal/event_bus.rb +591 -0
  124. data/lib/onyxcord/internal/event_executor.rb +155 -0
  125. data/lib/onyxcord/internal/gateway/opcodes.rb +22 -0
  126. data/lib/onyxcord/internal/gateway/session.rb +45 -0
  127. data/lib/onyxcord/internal/http.rb +189 -0
  128. data/lib/onyxcord/internal/json.rb +51 -0
  129. data/lib/onyxcord/internal/message_payload.rb +78 -0
  130. data/lib/onyxcord/internal/rate_limiter/async_rest.rb +151 -0
  131. data/lib/onyxcord/internal/rate_limiter/gateway.rb +44 -0
  132. data/lib/onyxcord/internal/rate_limiter/rest.rb +144 -0
  133. data/lib/onyxcord/internal/upload.rb +39 -0
  134. data/lib/onyxcord/internal/websocket.rb +79 -0
  135. data/lib/onyxcord/light/data.rb +1 -1
  136. data/lib/onyxcord/light/integrations.rb +1 -1
  137. data/lib/onyxcord/light/light_bot.rb +7 -7
  138. data/lib/onyxcord/{data → models}/activity.rb +2 -2
  139. data/lib/onyxcord/{data → models}/application.rb +3 -3
  140. data/lib/onyxcord/{data → models}/avatar_decoration.rb +1 -1
  141. data/lib/onyxcord/{data → models}/channel.rb +23 -23
  142. data/lib/onyxcord/{data → models}/collectibles.rb +1 -1
  143. data/lib/onyxcord/{data → models}/emoji.rb +1 -1
  144. data/lib/onyxcord/models/interaction.rb +450 -0
  145. data/lib/onyxcord/{data → models}/invite.rb +1 -1
  146. data/lib/onyxcord/{data → models}/member.rb +11 -11
  147. data/lib/onyxcord/{data → models}/message.rb +22 -14
  148. data/lib/onyxcord/{data → models}/poll.rb +2 -2
  149. data/lib/onyxcord/{data → models}/primary_server.rb +1 -1
  150. data/lib/onyxcord/{data → models}/profile.rb +4 -4
  151. data/lib/onyxcord/{data → models}/role.rb +6 -12
  152. data/lib/onyxcord/{data → models}/scheduled_event.rb +5 -5
  153. data/lib/onyxcord/{data → models}/server.rb +41 -41
  154. data/lib/onyxcord/{data → models}/server_preview.rb +2 -2
  155. data/lib/onyxcord/{data → models}/team.rb +1 -1
  156. data/lib/onyxcord/{data → models}/user.rb +5 -5
  157. data/lib/onyxcord/{data → models}/webhook.rb +13 -11
  158. data/lib/onyxcord/models.rb +57 -0
  159. data/lib/onyxcord/{api.rb → rest/client.rb} +83 -27
  160. data/lib/onyxcord/{api → rest/routes}/application.rb +79 -57
  161. data/lib/onyxcord/rest/routes/channel/base.rb +73 -0
  162. data/lib/onyxcord/rest/routes/channel/groups.rb +78 -0
  163. data/lib/onyxcord/rest/routes/channel/messages.rb +130 -0
  164. data/lib/onyxcord/rest/routes/channel/permissions.rb +73 -0
  165. data/lib/onyxcord/rest/routes/channel/pins.rb +45 -0
  166. data/lib/onyxcord/rest/routes/channel/polls.rb +32 -0
  167. data/lib/onyxcord/rest/routes/channel/reactions.rb +86 -0
  168. data/lib/onyxcord/rest/routes/channel/threads.rb +176 -0
  169. data/lib/onyxcord/rest/routes/channel/webhooks.rb +47 -0
  170. data/lib/onyxcord/rest/routes/channel.rb +12 -0
  171. data/lib/onyxcord/{api/interaction.rb → rest/routes/interaction/base.rb} +10 -33
  172. data/lib/onyxcord/rest/routes/interaction/response.rb +24 -0
  173. data/lib/onyxcord/rest/routes/interaction.rb +4 -0
  174. data/lib/onyxcord/{api → rest/routes}/invite.rb +7 -7
  175. data/lib/onyxcord/rest/routes/server/admin.rb +174 -0
  176. data/lib/onyxcord/rest/routes/server/assets.rb +25 -0
  177. data/lib/onyxcord/rest/routes/server/bans.rb +67 -0
  178. data/lib/onyxcord/rest/routes/server/base.rb +77 -0
  179. data/lib/onyxcord/rest/routes/server/channels.rb +58 -0
  180. data/lib/onyxcord/rest/routes/server/emoji.rb +48 -0
  181. data/lib/onyxcord/rest/routes/server/members.rb +109 -0
  182. data/lib/onyxcord/rest/routes/server/messages.rb +19 -0
  183. data/lib/onyxcord/rest/routes/server/roles.rb +156 -0
  184. data/lib/onyxcord/rest/routes/server/scheduled_events.rb +86 -0
  185. data/lib/onyxcord/rest/routes/server.rb +12 -0
  186. data/lib/onyxcord/{api → rest/routes}/user.rb +23 -23
  187. data/lib/onyxcord/{api → rest/routes}/webhook.rb +30 -32
  188. data/lib/onyxcord/{allowed_mentions.rb → utils/allowed_mentions.rb} +9 -1
  189. data/lib/onyxcord/utils/timestamp.rb +69 -0
  190. data/lib/onyxcord/voice/{voice_bot.rb → client.rb} +4 -4
  191. data/lib/onyxcord/voice/encoder.rb +1 -1
  192. data/lib/onyxcord/voice/network/udp.rb +135 -0
  193. data/lib/onyxcord/voice/network/websocket.rb +225 -0
  194. data/lib/onyxcord/voice/network.rb +5 -357
  195. data/lib/onyxcord/webhooks/builder.rb +1 -1
  196. data/lib/onyxcord/webhooks/client.rb +13 -13
  197. data/lib/onyxcord/webhooks/modal/group_builder.rb +55 -0
  198. data/lib/onyxcord/webhooks/modal/label_builder.rb +183 -0
  199. data/lib/onyxcord/webhooks/modal.rb +2 -239
  200. data/lib/onyxcord/webhooks/version.rb +3 -3
  201. data/lib/onyxcord/webhooks/view/container_builder.rb +80 -0
  202. data/lib/onyxcord/webhooks/view/file_builder.rb +24 -0
  203. data/lib/onyxcord/webhooks/view/media_gallery_builder.rb +50 -0
  204. data/lib/onyxcord/webhooks/view/row_builder.rb +120 -0
  205. data/lib/onyxcord/webhooks/view/section_builder.rb +61 -0
  206. data/lib/onyxcord/webhooks/view/select_menu_builder.rb +77 -0
  207. data/lib/onyxcord/webhooks/view/separator_builder.rb +22 -0
  208. data/lib/onyxcord/webhooks/view/text_display_builder.rb +20 -0
  209. data/lib/onyxcord/webhooks/view.rb +9 -425
  210. data/lib/onyxcord.rb +106 -40
  211. metadata +208 -91
  212. data/.github/CONTRIBUTING.md +0 -13
  213. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  214. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
  215. data/.github/pull_request_template.md +0 -37
  216. data/.github/workflows/ci.yml +0 -78
  217. data/.github/workflows/codeql.yml +0 -65
  218. data/.github/workflows/deploy.yml +0 -54
  219. data/.github/workflows/release.yml +0 -51
  220. data/.gitignore +0 -17
  221. data/.markdownlint.json +0 -4
  222. data/.overcommit.yml +0 -7
  223. data/.rspec +0 -2
  224. data/.rubocop.yml +0 -129
  225. data/.yardopts +0 -1
  226. data/CHANGELOG.md +0 -202
  227. data/Gemfile +0 -6
  228. data/LICENSE.txt +0 -21
  229. data/README.md +0 -448
  230. data/Rakefile +0 -13
  231. data/lib/onyxcord/api/channel.rb +0 -705
  232. data/lib/onyxcord/api/server.rb +0 -775
  233. data/lib/onyxcord/async/runtime.rb +0 -30
  234. data/lib/onyxcord/commands/command_bot.rb +0 -505
  235. data/lib/onyxcord/data/interaction.rb +0 -1143
  236. data/lib/onyxcord/data.rb +0 -57
  237. data/lib/onyxcord/event_executor.rb +0 -153
  238. data/lib/onyxcord/gateway.rb +0 -500
  239. data/lib/onyxcord/http.rb +0 -115
  240. data/lib/onyxcord/json.rb +0 -49
  241. data/lib/onyxcord/rate_limiter/async_rest.rb +0 -149
  242. data/lib/onyxcord/rate_limiter/gateway.rb +0 -42
  243. data/lib/onyxcord/rate_limiter/rest.rb +0 -142
  244. data/lib/onyxcord/version.rb +0 -7
  245. data/lib/onyxcord/websocket.rb +0 -77
  246. data/onyxcord.gemspec +0 -63
  247. /data/lib/onyxcord/{configuration.rb → core/configuration.rb} +0 -0
  248. /data/lib/onyxcord/{data → models}/attachment.rb +0 -0
  249. /data/lib/onyxcord/{data → models}/audit_logs.rb +0 -0
  250. /data/lib/onyxcord/{data → models}/call.rb +0 -0
  251. /data/lib/onyxcord/{data → models}/channel_tag.rb +0 -0
  252. /data/lib/onyxcord/{data → models}/component.rb +0 -0
  253. /data/lib/onyxcord/{data → models}/embed.rb +0 -0
  254. /data/lib/onyxcord/{data → models}/install_params.rb +0 -0
  255. /data/lib/onyxcord/{data → models}/integration.rb +0 -0
  256. /data/lib/onyxcord/{data → models}/message_activity.rb +0 -0
  257. /data/lib/onyxcord/{data → models}/overwrite.rb +0 -0
  258. /data/lib/onyxcord/{data → models}/reaction.rb +0 -0
  259. /data/lib/onyxcord/{data → models}/recipient.rb +0 -0
  260. /data/lib/onyxcord/{data → models}/role_connection_data.rb +0 -0
  261. /data/lib/onyxcord/{data → models}/role_subscription.rb +0 -0
  262. /data/lib/onyxcord/{data → models}/snapshot.rb +0 -0
  263. /data/lib/onyxcord/{data → models}/timestamp.rb +0 -0
  264. /data/lib/onyxcord/{data → models}/voice_region.rb +0 -0
  265. /data/lib/onyxcord/{data → models}/voice_state.rb +0 -0
  266. /data/lib/onyxcord/{colour_rgb.rb → utils/colour_rgb.rb} +0 -0
  267. /data/lib/onyxcord/{id_object.rb → utils/id_object.rb} +0 -0
  268. /data/lib/onyxcord/{message_components.rb → utils/message_components.rb} +0 -0
  269. /data/lib/onyxcord/{paginator.rb → utils/paginator.rb} +0 -0
  270. /data/lib/onyxcord/{permissions.rb → utils/permissions.rb} +0 -0
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OnyxCord::Webhooks::Modal
4
+ class GroupBuilder
5
+ # @!visibility private
6
+ def initialize(type, custom_id, id, options = [], required = nil, min_values = nil, max_values = nil)
7
+ @id = id
8
+ @type = type
9
+ @custom_id = custom_id
10
+ @options = options
11
+ @required = required
12
+ @min_values = min_values
13
+ @max_values = max_values
14
+ end
15
+
16
+ # Add a checkbox component to the group.
17
+ # @param value [String] The value that the checkbox represents.
18
+ # @param label [String] The primary text of the checkbox.
19
+ # @param description [String, nil] The description of the checkbox.
20
+ # @param default [true, false, nil] Whether or not the checkbox should be checked by default.
21
+ def checkbox(value:, label:, description: nil, default: nil)
22
+ raise "Cannot add a checkbox to a #{@type}" unless @type == :checkbox_group
23
+
24
+ @options << { value: value, label: label, description: description, default: default }.compact
25
+ end
26
+
27
+ # Add a radio button component to the group.
28
+ # @param value [String] The value that the radio button represents.
29
+ # @param label [String] The primary text of the radio button.
30
+ # @param description [String, nil] The description of the radio button.
31
+ # @param default [true, false, nil] Whether or not the radio button should be selected by default.
32
+ def radio_button(value:, label:, description: nil, default: nil)
33
+ raise "Cannot add a radio button to a #{@type}" unless @type == :radio_group
34
+
35
+ @options << { value: value, label: label, description: description, default: default }.compact
36
+ end
37
+
38
+ alias_method :button, :radio_button
39
+
40
+ # @!visibility private
41
+ def to_h
42
+ {
43
+ id: @id,
44
+ type: COMPONENT_TYPES[@type],
45
+ custom_id: @custom_id,
46
+ options: @options.map(&:to_h),
47
+ required: @required,
48
+ min_values: @min_values,
49
+ max_values: @max_values
50
+ }.compact
51
+ end
52
+ end
53
+
54
+ # This builder is used when adding a label component to a modal.
55
+ end
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OnyxCord::Webhooks::Modal
4
+ class LabelBuilder
5
+ # A mapping of text input styles to symbol names. `short` is a single line where `paragraph` is a block.
6
+ TEXT_INPUT_STYLES = {
7
+ short: 1,
8
+ paragraph: 2
9
+ }.freeze
10
+
11
+ # Create a label component.
12
+ # @param label [String, nil] The label of the label component. This
13
+ # field should always be passed, and will be required in 4.0.
14
+ # @param id [Integer, nil] The unique 32-bit ID of the label component.
15
+ # @param description [String, nil] The description of the label component.
16
+ # @yieldparam builder [LabelBuilder] Yields the initialized label component.
17
+ def initialize(label: nil, id: nil, description: nil)
18
+ @id = id
19
+ @label = label
20
+ @description = description
21
+
22
+ yield self if block_given?
23
+ end
24
+
25
+ # Add a text input to the label component.
26
+ # @param style [Symbol, Integer] The text input's style type. See {TEXT_INPUT_STYLES}
27
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
28
+ # There is a limit of 100 characters to each custom_id.
29
+ # @param id [Integer] The integer ID for this component. This is not to be confused with custom_id.
30
+ # @param min_length [Integer, nil] The minimum input length for a text input, min 0, max 4000.
31
+ # @param max_length [Integer, nil] The maximum input length for a text input, min 1, max 4000.
32
+ # @param required [true, false, nil] Whether this component is required to be filled, default true.
33
+ # @param value [String, nil] A pre-filled value for this component, max 4000 characters.
34
+ # @param placeholder [String, nil] Custom placeholder text if the input is empty, max 100 characters
35
+ def text_input(style:, custom_id:, id: nil, min_length: nil, max_length: nil, required: nil, value: nil, placeholder: nil)
36
+ @component = {
37
+ id: id,
38
+ style: TEXT_INPUT_STYLES[style] || style,
39
+ custom_id: custom_id,
40
+ type: COMPONENT_TYPES[:text_input],
41
+ min_length: min_length,
42
+ max_length: max_length,
43
+ required: required,
44
+ value: value,
45
+ placeholder: placeholder
46
+ }.compact
47
+ end
48
+
49
+ # Add a string select menu to the label component.
50
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
51
+ # There is a limit of 100 characters to each custom_id.
52
+ # @param id [Integer, nil] The unique 32-bit ID of the string select. This is not to be confused with the `custom_id`.
53
+ # @param options [Array<Hash>] Options that can be selected in this menu. Can also be provided via the yielded builder.
54
+ # @param placeholder [String, nil] Default text to show when no entries are selected.
55
+ # @param min_values [Integer, nil] The minimum amount of values a user must select.
56
+ # @param max_values [Integer, nil] The maximum amount of values a user can select.
57
+ # @param required [true, false, nil] Whether a value must be selected for the component.
58
+ # @yieldparam builder [SelectMenuBuilder] The select menu builder is yielded to allow for the modification of attributes.
59
+ def string_select(custom_id:, id: nil, options: [], placeholder: nil, min_values: nil, max_values: nil, required: nil)
60
+ builder = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, options, placeholder, min_values, max_values, nil, select_type: :string_select, id: id, required: required)
61
+
62
+ yield builder if block_given?
63
+
64
+ @component = builder.to_h
65
+ end
66
+
67
+ alias_method :select_menu, :string_select
68
+
69
+ # Add a user select to the label component.
70
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
71
+ # There is a limit of 100 characters to each custom_id.
72
+ # @param id [Integer, nil] The unique 32-bit ID of the user select. This is not to be confused with the `custom_id`.
73
+ # @param placeholder [String, nil] Default text to show when no entries are selected.
74
+ # @param min_values [Integer, nil] The minimum amount of values a user must select.
75
+ # @param max_values [Integer, nil] The maximum amount of values a user can select.
76
+ # @param required [true, false, nil] Whether a value must be selected for the component.
77
+ # @param default_values [Array<User, Member, Recipient, Integer, String, Hash>, nil] The users to populate in the select menu by default.
78
+ def user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
79
+ @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :user_select, id: id, required: required, default_values: default_values).to_h
80
+ end
81
+
82
+ # Add a role select to the label component.
83
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
84
+ # There is a limit of 100 characters to each custom_id.
85
+ # @param id [Integer, nil] The unique 32-bit ID of the role select. This is not to be confused with the `custom_id`.
86
+ # @param placeholder [String, nil] Default text to show when no entries are selected.
87
+ # @param min_values [Integer, nil] The minimum amount of values a user must select.
88
+ # @param max_values [Integer, nil] The maximum amount of values a user can select.
89
+ # @param required [true, false, nil] Whether a value must be selected for the component.
90
+ # @param default_values [Array<Role, Integer, String, Hash>, nil] The roles to populate in the select menu by default.
91
+ def role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
92
+ @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :role_select, id: id, required: required, default_values: default_values).to_h
93
+ end
94
+
95
+ # Add a mentionable select to the label component.
96
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
97
+ # There is a limit of 100 characters to each custom_id.
98
+ # @param id [Integer, nil] The unique 32-bit ID of the mentionable select. This is not to be confused with the `custom_id`.
99
+ # @param placeholder [String, nil] Default text to show when no entries are selected.
100
+ # @param min_values [Integer, nil] The minimum amount of values a user must select.
101
+ # @param max_values [Integer, nil] The maximum amount of values a user can select.
102
+ # @param required [true, false, nil] Whether a value must be selected for the component.
103
+ # @param default_values [Array<User, Role, Member, Recipient, Hash>, nil] The mentionable entities to populate in the select menu by default.
104
+ def mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
105
+ @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :mentionable_select, id: id, required: required, default_values: default_values).to_h
106
+ end
107
+
108
+ # Add a channel select to the label component.
109
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
110
+ # There is a limit of 100 characters to each custom_id.
111
+ # @param id [Integer, nil] The unique 32-bit ID of the channel select. This is not to be confused with the `custom_id`.
112
+ # @param placeholder [String, nil] Default text to show when no entries are selected.
113
+ # @param min_values [Integer, nil] The minimum amount of values a user must select.
114
+ # @param max_values [Integer, nil] The maximum amount of values a user can select.
115
+ # @param required [true, false, nil] Whether a value must be selected for the component.
116
+ # @param types [Array<Symbol, Integer>, nil] The channel types to include in the select menu.
117
+ # @param default_values [Array<Channel, Integer, String, Hash>, nil] The channels to populate in the select menu by default.
118
+ def channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, types: nil, default_values: nil)
119
+ builder = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :channel_select, id: id, required: required, default_values: default_values).to_h
120
+
121
+ builder[:channel_types] = types.map { |type| OnyxCord::Channel::TYPES[type] || type } if types
122
+
123
+ @component = builder
124
+ end
125
+
126
+ # Add a file upload component to the label component.
127
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
128
+ # There is a limit of 100 characters to each custom_id.
129
+ # @param id [Integer, nil] The unique 32-bit ID of the file upload component. This is not to be confused with the `custom_id`.
130
+ # @param min_values [Integer, nil] The minimum amount of files a user must upload.
131
+ # @param max_values [Integer, nil] The maximum amount of files a user has to upload.
132
+ # @param required [true, false, nil] Whether or not a file must be uploaded to the component.
133
+ def file_upload(custom_id:, id: nil, min_values: nil, max_values: nil, required: nil)
134
+ @component = { type: COMPONENT_TYPES[:file_upload], custom_id: custom_id, id: id, min_values: min_values, max_values: max_values, required: required }.compact
135
+ end
136
+
137
+ # Add a standalone checkbox component to the label component.
138
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
139
+ # There is a limit of 100 characters to each custom_id.
140
+ # @param id [Integer, nil] The unique 32-bit ID of the checkbox component. This is not to be confused with the `custom_id`.
141
+ # @param default [true, false, nil] Whether or not the checkbox is checked by default.
142
+ def checkbox(custom_id:, id: nil, default: false)
143
+ @component = { type: COMPONENT_TYPES[:checkbox], custom_id: custom_id, id: id, default: default }.compact
144
+ end
145
+
146
+ # Add a group of radio buttons to the label component.
147
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
148
+ # There is a limit of 100 characters to each custom_id.
149
+ # @param id [Integer, nil] The unique 32-bit ID of the radio group component. This is not to be confused with the `custom_id`.
150
+ # @param buttons [Array<Hash>] Radio buttons for the group. Can also be provided via the yielded builder.
151
+ # @param required [true, false, nil] Whether or not a radio button in the group must be selected.
152
+ def radio_group(custom_id:, id: nil, buttons: [], required: nil)
153
+ builder = GroupBuilder.new(:radio_group, custom_id, id, buttons, required)
154
+
155
+ yield builder if block_given?
156
+
157
+ @component = builder.to_h
158
+ end
159
+
160
+ # Add a group of checkboxes to the label component.
161
+ # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
162
+ # There is a limit of 100 characters to each custom_id.
163
+ # @param id [Integer, nil] The unique 32-bit ID of the checkbox group component. This is not to be confused with the `custom_id`.
164
+ # @param checkboxes [Array<Hash>] Checkboxes for the group. Can also be provided via the yielded builder.
165
+ # @param min_values [Integer, nil] The minimum number of checkboxes a user must check.
166
+ # @param max_values [Integer, nil] The maximum number of checkboxes a user is allowed to check.
167
+ # @param required [true, false, nil] Whether or not a checkbox must be checked.
168
+ def checkbox_group(custom_id:, id: nil, checkboxes: [], min_values: nil, max_values: nil, required: nil)
169
+ builder = GroupBuilder.new(:checkbox_group, custom_id, id, checkboxes, required, min_values, max_values)
170
+
171
+ yield builder if block_given?
172
+
173
+ @component = builder.to_h
174
+ end
175
+
176
+ # @!visibility private
177
+ def to_h
178
+ { type: COMPONENT_TYPES[:label], id: @id, label: @label, description: @description, component: @component }.compact
179
+ end
180
+ end
181
+
182
+ # @!visibility private
183
+ end
@@ -19,240 +19,9 @@ class OnyxCord::Webhooks::Modal
19
19
  checkbox: 23
20
20
  }.freeze
21
21
 
22
- # Builder for radio and checkbox groups.
23
- class GroupBuilder
24
- # @!visibility private
25
- def initialize(type, custom_id, id, options = [], required = nil, min_values = nil, max_values = nil)
26
- @id = id
27
- @type = type
28
- @custom_id = custom_id
29
- @options = options
30
- @required = required
31
- @min_values = min_values
32
- @max_values = max_values
33
- end
22
+ require 'onyxcord/webhooks/modal/group_builder'
23
+ require 'onyxcord/webhooks/modal/label_builder'
34
24
 
35
- # Add a checkbox component to the group.
36
- # @param value [String] The value that the checkbox represents.
37
- # @param label [String] The primary text of the checkbox.
38
- # @param description [String, nil] The description of the checkbox.
39
- # @param default [true, false, nil] Whether or not the checkbox should be checked by default.
40
- def checkbox(value:, label:, description: nil, default: nil)
41
- raise "Cannot add a checkbox to a #{@type}" unless @type == :checkbox_group
42
-
43
- @options << { value: value, label: label, description: description, default: default }.compact
44
- end
45
-
46
- # Add a radio button component to the group.
47
- # @param value [String] The value that the radio button represents.
48
- # @param label [String] The primary text of the radio button.
49
- # @param description [String, nil] The description of the radio button.
50
- # @param default [true, false, nil] Whether or not the radio button should be selected by default.
51
- def radio_button(value:, label:, description: nil, default: nil)
52
- raise "Cannot add a radio button to a #{@type}" unless @type == :radio_group
53
-
54
- @options << { value: value, label: label, description: description, default: default }.compact
55
- end
56
-
57
- alias_method :button, :radio_button
58
-
59
- # @!visibility private
60
- def to_h
61
- {
62
- id: @id,
63
- type: COMPONENT_TYPES[@type],
64
- custom_id: @custom_id,
65
- options: @options.map(&:to_h),
66
- required: @required,
67
- min_values: @min_values,
68
- max_values: @max_values
69
- }.compact
70
- end
71
- end
72
-
73
- # This builder is used when adding a label component to a modal.
74
- class LabelBuilder
75
- # A mapping of text input styles to symbol names. `short` is a single line where `paragraph` is a block.
76
- TEXT_INPUT_STYLES = {
77
- short: 1,
78
- paragraph: 2
79
- }.freeze
80
-
81
- # Create a label component.
82
- # @param label [String, nil] The label of the label component. This
83
- # field should always be passed, and will be required in 4.0.
84
- # @param id [Integer, nil] The unique 32-bit ID of the label component.
85
- # @param description [String, nil] The description of the label component.
86
- # @yieldparam builder [LabelBuilder] Yields the initialized label component.
87
- def initialize(label: nil, id: nil, description: nil)
88
- @id = id
89
- @label = label
90
- @description = description
91
-
92
- yield self if block_given?
93
- end
94
-
95
- # Add a text input to the label component.
96
- # @param style [Symbol, Integer] The text input's style type. See {TEXT_INPUT_STYLES}
97
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
98
- # There is a limit of 100 characters to each custom_id.
99
- # @param id [Integer] The integer ID for this component. This is not to be confused with custom_id.
100
- # @param min_length [Integer, nil] The minimum input length for a text input, min 0, max 4000.
101
- # @param max_length [Integer, nil] The maximum input length for a text input, min 1, max 4000.
102
- # @param required [true, false, nil] Whether this component is required to be filled, default true.
103
- # @param value [String, nil] A pre-filled value for this component, max 4000 characters.
104
- # @param placeholder [String, nil] Custom placeholder text if the input is empty, max 100 characters
105
- # @param label [String, nil] This parameter is deprecated and will be removed soon. Please pass this argument to {LabelBuilder#initialize} instead.
106
- def text_input(style:, custom_id:, id: nil, min_length: nil, max_length: nil, required: nil, value: nil, placeholder: nil, label: nil)
107
- @label = label unless label.nil?
108
-
109
- @component = {
110
- id: id,
111
- style: TEXT_INPUT_STYLES[style] || style,
112
- custom_id: custom_id,
113
- type: COMPONENT_TYPES[:text_input],
114
- min_length: min_length,
115
- max_length: max_length,
116
- required: required,
117
- value: value,
118
- placeholder: placeholder
119
- }.compact
120
- end
121
-
122
- # Add a string select menu to the label component.
123
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
124
- # There is a limit of 100 characters to each custom_id.
125
- # @param id [Integer, nil] The unique 32-bit ID of the string select. This is not to be confused with the `custom_id`.
126
- # @param options [Array<Hash>] Options that can be selected in this menu. Can also be provided via the yielded builder.
127
- # @param placeholder [String, nil] Default text to show when no entries are selected.
128
- # @param min_values [Integer, nil] The minimum amount of values a user must select.
129
- # @param max_values [Integer, nil] The maximum amount of values a user can select.
130
- # @param required [true, false, nil] Whether a value must be selected for the component.
131
- # @yieldparam builder [SelectMenuBuilder] The select menu builder is yielded to allow for the modification of attributes.
132
- def string_select(custom_id:, id: nil, options: [], placeholder: nil, min_values: nil, max_values: nil, required: nil)
133
- builder = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, options, placeholder, min_values, max_values, nil, select_type: :string_select, id: id, required: required)
134
-
135
- yield builder if block_given?
136
-
137
- @component = builder.to_h
138
- end
139
-
140
- alias_method :select_menu, :string_select
141
-
142
- # Add a user select to the label component.
143
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
144
- # There is a limit of 100 characters to each custom_id.
145
- # @param id [Integer, nil] The unique 32-bit ID of the user select. This is not to be confused with the `custom_id`.
146
- # @param placeholder [String, nil] Default text to show when no entries are selected.
147
- # @param min_values [Integer, nil] The minimum amount of values a user must select.
148
- # @param max_values [Integer, nil] The maximum amount of values a user can select.
149
- # @param required [true, false, nil] Whether a value must be selected for the component.
150
- # @param default_values [Array<User, Member, Recipient, Integer, String, Hash>, nil] The users to populate in the select menu by default.
151
- def user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
152
- @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :user_select, id: id, required: required, default_values: default_values).to_h
153
- end
154
-
155
- # Add a role select to the label component.
156
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
157
- # There is a limit of 100 characters to each custom_id.
158
- # @param id [Integer, nil] The unique 32-bit ID of the role select. This is not to be confused with the `custom_id`.
159
- # @param placeholder [String, nil] Default text to show when no entries are selected.
160
- # @param min_values [Integer, nil] The minimum amount of values a user must select.
161
- # @param max_values [Integer, nil] The maximum amount of values a user can select.
162
- # @param required [true, false, nil] Whether a value must be selected for the component.
163
- # @param default_values [Array<Role, Integer, String, Hash>, nil] The roles to populate in the select menu by default.
164
- def role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
165
- @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :role_select, id: id, required: required, default_values: default_values).to_h
166
- end
167
-
168
- # Add a mentionable select to the label component.
169
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
170
- # There is a limit of 100 characters to each custom_id.
171
- # @param id [Integer, nil] The unique 32-bit ID of the mentionable select. This is not to be confused with the `custom_id`.
172
- # @param placeholder [String, nil] Default text to show when no entries are selected.
173
- # @param min_values [Integer, nil] The minimum amount of values a user must select.
174
- # @param max_values [Integer, nil] The maximum amount of values a user can select.
175
- # @param required [true, false, nil] Whether a value must be selected for the component.
176
- # @param default_values [Array<User, Role, Member, Recipient, Hash>, nil] The mentionable entities to populate in the select menu by default.
177
- def mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, default_values: nil)
178
- @component = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :mentionable_select, id: id, required: required, default_values: default_values).to_h
179
- end
180
-
181
- # Add a channel select to the label component.
182
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
183
- # There is a limit of 100 characters to each custom_id.
184
- # @param id [Integer, nil] The unique 32-bit ID of the channel select. This is not to be confused with the `custom_id`.
185
- # @param placeholder [String, nil] Default text to show when no entries are selected.
186
- # @param min_values [Integer, nil] The minimum amount of values a user must select.
187
- # @param max_values [Integer, nil] The maximum amount of values a user can select.
188
- # @param required [true, false, nil] Whether a value must be selected for the component.
189
- # @param types [Array<Symbol, Integer>, nil] The channel types to include in the select menu.
190
- # @param default_values [Array<Channel, Integer, String, Hash>, nil] The channels to populate in the select menu by default.
191
- def channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, types: nil, default_values: nil)
192
- builder = OnyxCord::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :channel_select, id: id, required: required, default_values: default_values).to_h
193
-
194
- builder[:channel_types] = types.map { |type| OnyxCord::Channel::TYPES[type] || type } if types
195
-
196
- @component = builder
197
- end
198
-
199
- # Add a file upload component to the label component.
200
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
201
- # There is a limit of 100 characters to each custom_id.
202
- # @param id [Integer, nil] The unique 32-bit ID of the file upload component. This is not to be confused with the `custom_id`.
203
- # @param min_values [Integer, nil] The minimum amount of files a user must upload.
204
- # @param max_values [Integer, nil] The maximum amount of files a user has to upload.
205
- # @param required [true, false, nil] Whether or not a file must be uploaded to the component.
206
- def file_upload(custom_id:, id: nil, min_values: nil, max_values: nil, required: nil)
207
- @component = { type: COMPONENT_TYPES[:file_upload], custom_id: custom_id, id: id, min_values: min_values, max_values: max_values, required: required }.compact
208
- end
209
-
210
- # Add a standalone checkbox component to the label component.
211
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
212
- # There is a limit of 100 characters to each custom_id.
213
- # @param id [Integer, nil] The unique 32-bit ID of the checkbox component. This is not to be confused with the `custom_id`.
214
- # @param default [true, false, nil] Whether or not the checkbox is checked by default.
215
- def checkbox(custom_id:, id: nil, default: false)
216
- @component = { type: COMPONENT_TYPES[:checkbox], custom_id: custom_id, id: id, default: default }.compact
217
- end
218
-
219
- # Add a group of radio buttons to the label component.
220
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
221
- # There is a limit of 100 characters to each custom_id.
222
- # @param id [Integer, nil] The unique 32-bit ID of the radio group component. This is not to be confused with the `custom_id`.
223
- # @param buttons [Array<Hash>] Radio buttons for the group. Can also be provided via the yielded builder.
224
- # @param required [true, false, nil] Whether or not a radio button in the group must be selected.
225
- def radio_group(custom_id:, id: nil, buttons: [], required: nil)
226
- builder = GroupBuilder.new(:radio_group, custom_id, id, buttons, required)
227
-
228
- yield builder if block_given?
229
-
230
- @component = builder.to_h
231
- end
232
-
233
- # Add a group of checkboxes to the label component.
234
- # @param custom_id [String] Custom IDs are used to pass state to the events that are raised from interactions.
235
- # There is a limit of 100 characters to each custom_id.
236
- # @param id [Integer, nil] The unique 32-bit ID of the checkbox group component. This is not to be confused with the `custom_id`.
237
- # @param checkboxes [Array<Hash>] Checkboxes for the group. Can also be provided via the yielded builder.
238
- # @param min_values [Integer, nil] The minimum number of checkboxes a user must check.
239
- # @param max_values [Integer, nil] The maximum number of checkboxes a user is allowed to check.
240
- # @param required [true, false, nil] Whether or not a checkbox must be checked.
241
- def checkbox_group(custom_id:, id: nil, checkboxes: [], min_values: nil, max_values: nil, required: nil)
242
- builder = GroupBuilder.new(:checkbox_group, custom_id, id, checkboxes, required, min_values, max_values)
243
-
244
- yield builder if block_given?
245
-
246
- @component = builder.to_h
247
- end
248
-
249
- # @!visibility private
250
- def to_h
251
- { type: COMPONENT_TYPES[:label], id: @id, label: @label, description: @description, component: @component }.compact
252
- end
253
- end
254
-
255
- # @!visibility private
256
25
  def initialize
257
26
  @components = []
258
27
 
@@ -275,10 +44,4 @@ class OnyxCord::Webhooks::Modal
275
44
  def text_display(...)
276
45
  @components << OnyxCord::Webhooks::View::TextDisplayBuilder.new(...)
277
46
  end
278
-
279
- # @deprecated Please use {#label} instead.
280
- alias_method :row, :label
281
-
282
- # @deprecated This alias will be removed in future releases.
283
- RowBuilder = LabelBuilder
284
47
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Webhook support bundled in onyxcord.
3
+ require 'onyxcord/core/version'
4
+
4
5
  module OnyxCord
5
6
  module Webhooks
6
- # Kept for compatibility with code that checks the webhooks module version.
7
- VERSION = '2.0.13'
7
+ VERSION = OnyxCord::VERSION
8
8
  end
9
9
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OnyxCord::Webhooks::View
4
+ class ContainerBuilder
5
+ # Create a container component.
6
+ # @param id [Integer, nil] The unique 32-bit ID of the container component.
7
+ # @param colour [Array, Integer, String, ColourRGB, nil] The accent colour of the container
8
+ # component. This argument can be passed via the American spelling (`color:`) as well.
9
+ # @param spoiler [true, false] Whether or not to apply a spoiler label to the container component.
10
+ # @yieldparam builder [ContainerBuilder] Yields the initialized container component.
11
+ def initialize(id: nil, color: nil, colour: nil, spoiler: false)
12
+ @id = id
13
+ @spoiler = spoiler
14
+ @components = []
15
+ self.colour = (colour || color)
16
+
17
+ yield self if block_given?
18
+ end
19
+
20
+ # Add a row component to the container.
21
+ # @see RowBuilder#initialize
22
+ def row(...)
23
+ @components << RowBuilder.new(...)
24
+ end
25
+
26
+ # Add a file component to the container.
27
+ # @see FileBuilder#initialize
28
+ def file(...)
29
+ @components << FileBuilder.new(...)
30
+ end
31
+
32
+ alias_method :file_display, :file
33
+
34
+ # Add a section component to the container.
35
+ # @see SectionBuilder#initialize
36
+ def section(...)
37
+ @components << SectionBuilder.new(...)
38
+ end
39
+
40
+ # Add a separator component to the container.
41
+ # @see SeparatorBuilder#initialize
42
+ def separator(...)
43
+ @components << SeparatorBuilder.new(...)
44
+ end
45
+
46
+ # Add a text display component to the container.
47
+ # @see TextDisplayBuilder#initialize
48
+ def text_display(...)
49
+ @components << TextDisplayBuilder.new(...)
50
+ end
51
+
52
+ # Add a media gallery component to the container.
53
+ # @see MediaGalleryBuilder#initialize
54
+ def media_gallery(*items, id: nil, &block)
55
+ @components << MediaGalleryBuilder.new(*items, id: id, &block)
56
+ end
57
+
58
+ # Set the color of the container.
59
+ # @param colour [Array, Integer, String, ColourRGB, nil] The accent colour of the container component, or `nil` to clear the accent colour.
60
+ def colour=(colour)
61
+ @colour = case colour
62
+ when Array
63
+ (colour[0] << 16) | (colour[1] << 8) | colour[2]
64
+ when String
65
+ colour.delete('#').to_i(16)
66
+ else
67
+ colour&.to_i
68
+ end
69
+ end
70
+
71
+ alias_method :color=, :colour=
72
+
73
+ # @!visibility private
74
+ def to_h
75
+ { type: COMPONENT_TYPES[:container], id: @id, accent_color: @colour, spoiler: @spoiler, components: @components.map(&:to_h) }.compact
76
+ end
77
+ end
78
+
79
+ # @!visibility private
80
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OnyxCord::Webhooks::View
4
+ class FileBuilder
5
+ # Create a file component.
6
+ # @param url [String] An `attachment://<filename>` reference to the attached file.
7
+ # @param id [Integer, nil] The unique 32-bit ID of the file component.
8
+ # @param spoiler [true, false] Whether or not to apply a spoiler label to the file.
9
+ def initialize(url = nil, id: nil, spoiler: false, **kwargs)
10
+ url = kwargs.fetch(:url, url)
11
+
12
+ @id = id
13
+ @file = { url: }
14
+ @spoiler = spoiler
15
+ end
16
+
17
+ # @!visibility private
18
+ def to_h
19
+ { type: COMPONENT_TYPES[:file], id: @id, spoiler: @spoiler, file: @file }.compact
20
+ end
21
+ end
22
+
23
+ # A media gallery component is a gallery grid.
24
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OnyxCord::Webhooks::View
4
+ class MediaGalleryBuilder
5
+ # Create a media gallery component.
6
+ # @param id [Integer, nil] The unique 32-bit ID of the media gallery component.
7
+ # @yieldparam builder [MediaGalleryBuilder] Yields the initialized media gallery component.
8
+ def initialize(*items, id: nil)
9
+ @id = id
10
+ @items = []
11
+
12
+ items.each { |item| self.item(item) }
13
+
14
+ yield self if block_given?
15
+ end
16
+
17
+ # Add a gallery item to the media gallery component.
18
+ # @param url [String] The URL to the gallery item's media.
19
+ # @param description [String, nil] The description of the gallery item.
20
+ # @param spoiler [true, false] Whether or not to apply a spoiler label to the gallery item.
21
+ def item(item = nil, url: nil, description: nil, spoiler: nil)
22
+ url, description, spoiler = normalize_item(item, url, description, spoiler)
23
+ raise ArgumentError, 'media gallery item requires a url' if url.nil? || url.to_s.empty?
24
+
25
+ @items << { media: { url: url }, description: description, spoiler: spoiler }.compact
26
+ end
27
+
28
+ # @!visibility private
29
+ def to_h
30
+ { type: COMPONENT_TYPES[:media_gallery], id: @id, items: @items }.compact
31
+ end
32
+
33
+ private
34
+
35
+ def normalize_item(item, url, description, spoiler)
36
+ if item.is_a?(Hash)
37
+ media = item[:media] || item['media'] || {}
38
+ url ||= item[:url] || item['url'] || media[:url] || media['url']
39
+ description = item[:description] || item['description'] if description.nil?
40
+ spoiler = item[:spoiler] || item['spoiler'] if spoiler.nil?
41
+ else
42
+ url ||= item
43
+ end
44
+
45
+ [url, description, spoiler.nil? ? false : spoiler]
46
+ end
47
+ end
48
+
49
+ # A section allows you to group together an accessory with text display components.
50
+ end