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,176 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnyxCord::REST::Channel
4
+ module_function
5
+
6
+ # Start a thread based off a channel message.
7
+ # https://discord.com/developers/docs/resources/channel#start-thread-with-message
8
+ def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
9
+ OnyxCord::REST.request(
10
+ :channels_cid_messages_mid_threads,
11
+ channel_id,
12
+ :post,
13
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
14
+ { name: name, auto_archive_duration: auto_archive_duration }.to_json,
15
+ Authorization: token,
16
+ content_type: :json
17
+ )
18
+ end
19
+
20
+ # Start a thread without an associated message.
21
+ # https://discord.com/developers/docs/resources/channel#start-thread-without-message
22
+ def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
23
+ OnyxCord::REST.request(
24
+ :channels_cid_threads,
25
+ channel_id,
26
+ :post,
27
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads",
28
+ { name: name, auto_archive_duration: auto_archive_duration, type: type },
29
+ Authorization: token,
30
+ content_type: :json
31
+ )
32
+ end
33
+
34
+ # Add the current user to a thread.
35
+ # https://discord.com/developers/docs/resources/channel#join-thread
36
+ def join_thread(token, channel_id)
37
+ OnyxCord::REST.request(
38
+ :channels_cid_thread_members_me,
39
+ channel_id,
40
+ :put,
41
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/@me",
42
+ nil,
43
+ Authorization: token
44
+ )
45
+ end
46
+
47
+ # Add a user to a thread.
48
+ # https://discord.com/developers/docs/resources/channel#add-thread-member
49
+ def add_thread_member(token, channel_id, user_id)
50
+ OnyxCord::REST.request(
51
+ :channels_cid_thread_members_uid,
52
+ channel_id,
53
+ :put,
54
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
55
+ nil,
56
+ Authorization: token
57
+ )
58
+ end
59
+
60
+ # Remove the current user from a thread.
61
+ # https://discord.com/developers/docs/resources/channel#leave-thread
62
+ def leave_thread(token, channel_id)
63
+ OnyxCord::REST.request(
64
+ :channels_cid_thread_members_me,
65
+ channel_id,
66
+ :delete,
67
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
68
+ Authorization: token
69
+ )
70
+ end
71
+
72
+ # Remove a user from a thread.
73
+ # https://discord.com/developers/docs/resources/channel#remove-thread-member
74
+ def remove_thread_member(token, channel_id, user_id)
75
+ OnyxCord::REST.request(
76
+ :channels_cid_thread_members_uid,
77
+ channel_id,
78
+ :delete,
79
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
80
+ Authorization: token
81
+ )
82
+ end
83
+
84
+ # Get the members of a thread.
85
+ # https://discord.com/developers/docs/resources/channel#list-thread-members
86
+ def list_thread_members(token, channel_id, before, limit)
87
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
88
+
89
+ OnyxCord::REST.request(
90
+ :channels_cid_thread_members,
91
+ channel_id,
92
+ :get,
93
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members?#{query}",
94
+ Authorization: token
95
+ )
96
+ end
97
+
98
+ # List active threads
99
+ # https://discord.com/developers/docs/resources/channel#list-active-threads
100
+ def list_active_threads(token, channel_id)
101
+ OnyxCord::REST.request(
102
+ :channels_cid_threads_active,
103
+ channel_id,
104
+ :get,
105
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/active",
106
+ Authorization: token
107
+ )
108
+ end
109
+
110
+ # List public archived threads.
111
+ # https://discord.com/developers/docs/resources/channel#list-public-archived-threads
112
+ def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
113
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
114
+
115
+ OnyxCord::REST.request(
116
+ :channels_cid_threads_archived_public,
117
+ channel_id,
118
+ :get,
119
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
120
+ Authorization: token
121
+ )
122
+ end
123
+
124
+ # List private archived threads.
125
+ # https://discord.com/developers/docs/resources/channel#list-private-archived-threads
126
+ def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
127
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
128
+
129
+ OnyxCord::REST.request(
130
+ :channels_cid_threads_archived_private,
131
+ channel_id,
132
+ :get,
133
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
134
+ Authorization: token
135
+ )
136
+ end
137
+
138
+ # List joined private archived threads.
139
+ # https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads
140
+ def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
141
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
142
+
143
+ OnyxCord::REST.request(
144
+ :channels_cid_users_me_threads_archived_private,
145
+ channel_id,
146
+ :get,
147
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
148
+ Authorization: token
149
+ )
150
+ end
151
+
152
+ # Start a thread in a forum or media channel.
153
+ # https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
154
+ def start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = nil, reason = nil)
155
+ OnyxCord::MessagePayload.validate!(attachments: attachments)
156
+ body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact
157
+
158
+ body = if attachments
159
+ multipart_body(body, attachments)
160
+ else
161
+ body.to_json
162
+ end
163
+
164
+ headers = { Authorization: token, 'X-Audit-Log-Reason': reason }
165
+ headers[:content_type] = :json unless attachments
166
+
167
+ OnyxCord::REST.request(
168
+ :channels_cid_threads,
169
+ channel_id,
170
+ :post,
171
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads",
172
+ body,
173
+ headers
174
+ )
175
+ end
176
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnyxCord::REST::Channel
4
+ module_function
5
+
6
+ # Create a webhook
7
+ # https://discord.com/developers/docs/resources/webhook#create-webhook
8
+ def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
9
+ OnyxCord::REST.request(
10
+ :channels_cid_webhooks,
11
+ channel_id,
12
+ :post,
13
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/webhooks",
14
+ { name: name, avatar: avatar }.to_json,
15
+ Authorization: token,
16
+ content_type: :json,
17
+ 'X-Audit-Log-Reason': reason
18
+ )
19
+ end
20
+
21
+ # Get channel webhooks
22
+ # https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
23
+ def webhooks(token, channel_id)
24
+ OnyxCord::REST.request(
25
+ :channels_cid_webhooks,
26
+ channel_id,
27
+ :get,
28
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/webhooks",
29
+ Authorization: token
30
+ )
31
+ end
32
+
33
+ # Follow an annoucement channel.
34
+ # https://discord.com/developers/docs/resources/channel#follow-announcement-channel
35
+ def follow_channel(token, channel_id, webhook_channel_id, reason = nil)
36
+ OnyxCord::REST.request(
37
+ :channels_cid_followers,
38
+ channel_id,
39
+ :post,
40
+ "#{OnyxCord::REST.api_base}/channels/#{channel_id}/followers",
41
+ { webhook_channel_id: webhook_channel_id }.to_json,
42
+ Authorization: token,
43
+ content_type: :json,
44
+ 'X-Audit-Log-Reason': reason
45
+ )
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/internal/message_payload'
4
+ require 'onyxcord/rest/routes/channel/base'
5
+ require 'onyxcord/rest/routes/channel/messages'
6
+ require 'onyxcord/rest/routes/channel/reactions'
7
+ require 'onyxcord/rest/routes/channel/permissions'
8
+ require 'onyxcord/rest/routes/channel/pins'
9
+ require 'onyxcord/rest/routes/channel/groups'
10
+ require 'onyxcord/rest/routes/channel/webhooks'
11
+ require 'onyxcord/rest/routes/channel/threads'
12
+ require 'onyxcord/rest/routes/channel/polls'
@@ -1,26 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/message_components'
3
+ require 'onyxcord/internal/message_payload'
4
4
 
5
- # API calls for interactions.
6
- module OnyxCord::API::Interaction
5
+ # API calls for interactions — base response methods.
6
+ module OnyxCord::REST::Interaction
7
7
  module_function
8
8
 
9
9
  # Build attachment metadata payload for multipart uploads.
10
10
  # Returns an array of { id:, filename: } hashes.
11
11
  def attachment_payload(attachments)
12
- Array(attachments).map.with_index do |attachment, index|
13
- { id: index, filename: File.basename(attachment.path) }
14
- end
12
+ OnyxCord::MessagePayload.attachment_payload(attachments)
15
13
  end
16
14
 
17
15
  # Build multipart body with named file fields and JSON payload.
18
16
  def multipart_body(body, attachments)
19
- files = Array(attachments).map.with_index.to_h do |attachment, index|
20
- ["files[#{index}]", attachment]
21
- end
22
-
23
- { **files, payload_json: body.to_json }
17
+ OnyxCord::MessagePayload.multipart_body(body, attachments)
24
18
  end
25
19
 
26
20
  # Respond to an interaction.
@@ -28,6 +22,7 @@ module OnyxCord::API::Interaction
28
22
  def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, choices = nil, with_response = nil, poll = nil)
29
23
  components = OnyxCord::MessageComponents.payload(components) unless components.nil?
30
24
  flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
25
+ OnyxCord::MessagePayload.validate!(content: content, embeds: embeds, components: components, flags: flags, attachments: attachments, poll: poll)
31
26
  data = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components, attachments: attachments ? attachment_payload(attachments) : nil, choices: choices, poll: poll }.compact
32
27
 
33
28
  body = if attachments
@@ -38,11 +33,11 @@ module OnyxCord::API::Interaction
38
33
 
39
34
  headers = { content_type: :json } unless attachments
40
35
 
41
- OnyxCord::API.request(
36
+ OnyxCord::REST.request(
42
37
  :interactions_iid_token_callback,
43
38
  interaction_id,
44
39
  :post,
45
- "#{OnyxCord::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback?with_response=#{with_response ? 'true' : 'false'}",
40
+ "#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback?with_response=#{with_response ? 'true' : 'false'}",
46
41
  body,
47
42
  headers
48
43
  )
@@ -53,31 +48,13 @@ module OnyxCord::API::Interaction
53
48
  def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components)
54
49
  data = { custom_id: custom_id, title: title, components: components.to_a }.compact
55
50
 
56
- OnyxCord::API.request(
51
+ OnyxCord::REST.request(
57
52
  :interactions_iid_token_callback,
58
53
  interaction_id,
59
54
  :post,
60
- "#{OnyxCord::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
55
+ "#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
61
56
  { type: 9, data: data }.to_json,
62
57
  content_type: :json
63
58
  )
64
59
  end
65
-
66
- # Get the original response to an interaction.
67
- # https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
68
- def get_original_interaction_response(interaction_token, application_id)
69
- OnyxCord::API::Webhook.token_get_message(interaction_token, application_id, '@original')
70
- end
71
-
72
- # Edit the original response to an interaction.
73
- # https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
74
- def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil)
75
- OnyxCord::API::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments, flags, poll)
76
- end
77
-
78
- # Delete the original response to an interaction.
79
- # https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
80
- def delete_original_interaction_response(interaction_token, application_id)
81
- OnyxCord::API::Webhook.token_delete_message(interaction_token, application_id, '@original')
82
- end
83
60
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # API calls for interactions — response management.
4
+ module OnyxCord::REST::Interaction
5
+ module_function
6
+
7
+ # Get the original response to an interaction.
8
+ # https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
9
+ def get_original_interaction_response(interaction_token, application_id)
10
+ OnyxCord::REST::Webhook.token_get_message(interaction_token, application_id, '@original')
11
+ end
12
+
13
+ # Edit the original response to an interaction.
14
+ # https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
15
+ def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil)
16
+ OnyxCord::REST::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments, flags, poll)
17
+ end
18
+
19
+ # Delete the original response to an interaction.
20
+ # https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
21
+ def delete_original_interaction_response(interaction_token, application_id)
22
+ OnyxCord::REST::Webhook.token_delete_message(interaction_token, application_id, '@original')
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/rest/routes/interaction/base'
4
+ require 'onyxcord/rest/routes/interaction/response'
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # API calls for Invite object
4
- module OnyxCord::API::Invite
4
+ module OnyxCord::REST::Invite
5
5
  module_function
6
6
 
7
7
  # Resolve an invite
8
8
  # https://discord.com/developers/docs/resources/invite#get-invite
9
9
  def resolve(token, invite_code, counts = true)
10
- OnyxCord::API.request(
10
+ OnyxCord::REST.request(
11
11
  :invite_code,
12
12
  nil,
13
13
  :get,
14
- "#{OnyxCord::API.api_base}/invites/#{invite_code}#{'?with_counts=true' if counts}",
14
+ "#{OnyxCord::REST.api_base}/invites/#{invite_code}#{'?with_counts=true' if counts}",
15
15
  Authorization: token
16
16
  )
17
17
  end
@@ -19,11 +19,11 @@ module OnyxCord::API::Invite
19
19
  # Delete an invite by code
20
20
  # https://discord.com/developers/docs/resources/invite#delete-invite
21
21
  def delete(token, code, reason = nil)
22
- OnyxCord::API.request(
22
+ OnyxCord::REST.request(
23
23
  :invites_code,
24
24
  nil,
25
25
  :delete,
26
- "#{OnyxCord::API.api_base}/invites/#{code}",
26
+ "#{OnyxCord::REST.api_base}/invites/#{code}",
27
27
  Authorization: token,
28
28
  'X-Audit-Log-Reason': reason
29
29
  )
@@ -32,11 +32,11 @@ module OnyxCord::API::Invite
32
32
  # Join a server using an invite
33
33
  # https://discord.com/developers/docs/resources/invite#accept-invite
34
34
  def accept(token, invite_code)
35
- OnyxCord::API.request(
35
+ OnyxCord::REST.request(
36
36
  :invite_code,
37
37
  nil,
38
38
  :post,
39
- "#{OnyxCord::API.api_base}/invites/#{invite_code}",
39
+ "#{OnyxCord::REST.api_base}/invites/#{invite_code}",
40
40
  nil,
41
41
  Authorization: token
42
42
  )
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnyxCord::REST::Server
4
+ module_function
5
+
6
+ # Get server prune count
7
+ # https://discord.com/developers/docs/resources/guild#get-guild-prune-count
8
+ def prune_count(token, server_id, days)
9
+ OnyxCord::REST.request(
10
+ :guilds_sid_prune,
11
+ server_id,
12
+ :get,
13
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/prune?days=#{days}",
14
+ Authorization: token
15
+ )
16
+ end
17
+
18
+ # Begin server prune
19
+ # https://discord.com/developers/docs/resources/guild#begin-guild-prune
20
+ def begin_prune(token, server_id, days, reason = nil)
21
+ OnyxCord::REST.request(
22
+ :guilds_sid_prune,
23
+ server_id,
24
+ :post,
25
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/prune",
26
+ { days: days },
27
+ Authorization: token,
28
+ 'X-Audit-Log-Reason': reason
29
+ )
30
+ end
31
+
32
+ # Get invites from server
33
+ # https://discord.com/developers/docs/resources/guild#get-guild-invites
34
+ def invites(token, server_id)
35
+ OnyxCord::REST.request(
36
+ :guilds_sid_invites,
37
+ server_id,
38
+ :get,
39
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/invites",
40
+ Authorization: token
41
+ )
42
+ end
43
+
44
+ # Gets a server's audit logs
45
+ # https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
46
+ def audit_logs(token, server_id, limit, user_id = nil, action_type = nil, before = nil)
47
+ OnyxCord::REST.request(
48
+ :guilds_sid_auditlogs,
49
+ server_id,
50
+ :get,
51
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{user_id}" if user_id}#{"&action_type=#{action_type}" if action_type}#{"&before=#{before}" if before}",
52
+ Authorization: token
53
+ )
54
+ end
55
+
56
+ # Get server integrations
57
+ # https://discord.com/developers/docs/resources/guild#get-guild-integrations
58
+ def integrations(token, server_id)
59
+ OnyxCord::REST.request(
60
+ :guilds_sid_integrations,
61
+ server_id,
62
+ :get,
63
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/integrations",
64
+ Authorization: token
65
+ )
66
+ end
67
+
68
+ # Create a server integration
69
+ # https://discord.com/developers/docs/resources/guild#create-guild-integration
70
+ def create_integration(token, server_id, type, id, reason = nil)
71
+ OnyxCord::REST.request(
72
+ :guilds_sid_integrations,
73
+ server_id,
74
+ :post,
75
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/integrations",
76
+ { type: type, id: id },
77
+ Authorization: token,
78
+ 'X-Audit-Log-Reason': reason
79
+ )
80
+ end
81
+
82
+ # Update integration from server
83
+ # https://discord.com/developers/docs/resources/guild#modify-guild-integration
84
+ def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
85
+ OnyxCord::REST.request(
86
+ :guilds_sid_integrations_iid,
87
+ server_id,
88
+ :patch,
89
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
90
+ { expire_behavior: expire_behavior, expire_grace_period: expire_grace_period, enable_emoticons: enable_emoticons }.to_json,
91
+ Authorization: token,
92
+ content_type: :json
93
+ )
94
+ end
95
+
96
+ # Delete a server integration
97
+ # https://discord.com/developers/docs/resources/guild#delete-guild-integration
98
+ def delete_integration(token, server_id, integration_id, reason = nil)
99
+ OnyxCord::REST.request(
100
+ :guilds_sid_integrations_iid,
101
+ server_id,
102
+ :delete,
103
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
104
+ Authorization: token,
105
+ 'X-Audit-Log-Reason': reason
106
+ )
107
+ end
108
+
109
+ # Sync an integration
110
+ # https://discord.com/developers/docs/resources/guild#sync-guild-integration
111
+ def sync_integration(token, server_id, integration_id)
112
+ OnyxCord::REST.request(
113
+ :guilds_sid_integrations_iid_sync,
114
+ server_id,
115
+ :post,
116
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/integrations/#{integration_id}/sync",
117
+ nil,
118
+ Authorization: token
119
+ )
120
+ end
121
+
122
+ # Retrieves a server's widget information
123
+ # https://discord.com/developers/docs/resources/guild#get-guild-widget
124
+ def widget(token, server_id)
125
+ OnyxCord::REST.request(
126
+ :guilds_sid_embed,
127
+ server_id,
128
+ :get,
129
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/widget",
130
+ Authorization: token
131
+ )
132
+ end
133
+ alias embed widget
134
+
135
+ # Modify a server's widget settings
136
+ # https://discord.com/developers/docs/resources/guild#modify-guild-widget
137
+ def modify_widget(token, server_id, enabled, channel_id, reason = nil)
138
+ OnyxCord::REST.request(
139
+ :guilds_sid_embed,
140
+ server_id,
141
+ :patch,
142
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/widget",
143
+ { enabled: enabled, channel_id: channel_id }.to_json,
144
+ Authorization: token,
145
+ 'X-Audit-Log-Reason': reason,
146
+ content_type: :json
147
+ )
148
+ end
149
+ alias modify_embed modify_widget
150
+
151
+ # Available voice regions for this server
152
+ # https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
153
+ def regions(token, server_id)
154
+ OnyxCord::REST.request(
155
+ :guilds_sid_regions,
156
+ server_id,
157
+ :get,
158
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/regions",
159
+ Authorization: token
160
+ )
161
+ end
162
+
163
+ # Get server webhooks
164
+ # https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
165
+ def webhooks(token, server_id)
166
+ OnyxCord::REST.request(
167
+ :guilds_sid_webhooks,
168
+ server_id,
169
+ :get,
170
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/webhooks",
171
+ Authorization: token
172
+ )
173
+ end
174
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnyxCord::REST::Server
4
+ module_function
5
+
6
+ # Make an member avatar URL from the server, user and avatar IDs
7
+ def avatar_url(server_id, user_id, avatar_id, format = nil)
8
+ format ||= if avatar_id.start_with?('a_')
9
+ 'gif'
10
+ else
11
+ 'webp'
12
+ end
13
+ "#{OnyxCord::REST.cdn_url}/guilds/#{server_id}/users/#{user_id}/avatars/#{avatar_id}.#{format}"
14
+ end
15
+
16
+ # Make a banner URL from the server, user and banner IDs
17
+ def banner_url(server_id, user_id, banner_id, format = nil)
18
+ format ||= if banner_id.start_with?('a_')
19
+ 'gif'
20
+ else
21
+ 'webp'
22
+ end
23
+ "#{OnyxCord::REST.cdn_url}/guilds/#{server_id}/users/#{user_id}/banners/#{banner_id}.#{format}"
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnyxCord::REST::Server
4
+ module_function
5
+
6
+ # Get a server's banned users
7
+ # https://discord.com/developers/docs/resources/guild#get-guild-bans
8
+ def bans(token, server_id, limit = nil, before = nil, after = nil)
9
+ query_string = URI.encode_www_form({ limit: limit, before: before, after: after }.compact)
10
+ OnyxCord::REST.request(
11
+ :guilds_sid_bans,
12
+ server_id,
13
+ :get,
14
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/bans?#{query_string}",
15
+ Authorization: token
16
+ )
17
+ end
18
+
19
+ # @deprecated Please use {ban_user!} instead.
20
+ # https://discord.com/developers/docs/resources/guild#create-guild-ban
21
+ def ban_user(token, server_id, user_id, message_days, reason = nil)
22
+ ban_user!(token, server_id, user_id, message_days * 86_400, reason)
23
+ end
24
+
25
+ # Ban a user from a server and delete their messages up to a given amount of time.
26
+ # https://discord.com/developers/docs/resources/guild#create-guild-ban
27
+ def ban_user!(token, server_id, user_id, message_seconds, reason = nil)
28
+ OnyxCord::REST.request(
29
+ :guilds_sid_bans_uid,
30
+ server_id,
31
+ :put,
32
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/bans/#{user_id}",
33
+ { delete_message_seconds: message_seconds }.to_json,
34
+ Authorization: token,
35
+ content_type: :json,
36
+ 'X-Audit-Log-Reason': reason
37
+ )
38
+ end
39
+
40
+ # Unban a user from a server
41
+ # https://discord.com/developers/docs/resources/guild#remove-guild-ban
42
+ def unban_user(token, server_id, user_id, reason = nil)
43
+ OnyxCord::REST.request(
44
+ :guilds_sid_bans_uid,
45
+ server_id,
46
+ :delete,
47
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/bans/#{user_id}",
48
+ Authorization: token,
49
+ 'X-Audit-Log-Reason': reason
50
+ )
51
+ end
52
+
53
+ # Ban multiple users in one go
54
+ # https://discord.com/developers/docs/resources/guild#bulk-guild-ban
55
+ def bulk_ban(token, server_id, users, message_seconds, reason = nil)
56
+ OnyxCord::REST.request(
57
+ :guilds_sid_bulk_bans,
58
+ server_id,
59
+ :post,
60
+ "#{OnyxCord::REST.api_base}/guilds/#{server_id}/bulk-ban",
61
+ { user_ids: users, delete_message_seconds: message_seconds }.compact.to_json,
62
+ content_type: :json,
63
+ Authorization: token,
64
+ 'X-Audit-Log-Reason': reason
65
+ )
66
+ end
67
+ end