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
@@ -70,10 +70,10 @@ module OnyxCord
70
70
 
71
71
  # @!visibility private
72
72
  def update_profile_data(new_data)
73
- update_data(JSON.parse(API::User.update_current_user(@bot.token,
74
- new_data[:username] || :undef,
75
- new_data.key?(:avatar) ? new_data[:avatar] : :undef,
76
- new_data.key?(:banner) ? new_data[:banner] : :undef)))
73
+ update_data(JSON.parse(REST::User.update_current_user(@bot.token,
74
+ new_data[:username] || :undef,
75
+ new_data.key?(:avatar) ? new_data[:avatar] : :undef,
76
+ new_data.key?(:banner) ? new_data[:banner] : :undef)))
77
77
  end
78
78
  end
79
79
  end
@@ -227,7 +227,7 @@ module OnyxCord
227
227
  # @param format ['webp', 'png', 'jpeg']
228
228
  # @return [String] URL to the icon on Discord's CDN.
229
229
  def icon_url(format = 'webp')
230
- API.role_icon_url(@id, @icon, format) if @icon
230
+ REST.role_icon_url(@id, @icon, format) if @icon
231
231
  end
232
232
 
233
233
  # Get the icon that a role has displayed.
@@ -288,7 +288,7 @@ module OnyxCord
288
288
  # Deletes this role. This cannot be undone without recreating the role!
289
289
  # @param reason [String] the reason for this role's deletion
290
290
  def delete(reason = nil)
291
- API::Server.delete_role(@bot.token, @server.id, @id, reason)
291
+ REST::Server.delete_role(@bot.token, @server.id, @id, reason)
292
292
  @server.delete_role(@id)
293
293
  end
294
294
 
@@ -308,17 +308,13 @@ module OnyxCord
308
308
  # @param reason [String, nil] The audit log reason to show for moving the role.
309
309
  # @return [Integer] The new position of the role.
310
310
  def move(bottom: nil, above: nil, below: nil, offset: 0, reason: nil)
311
- if [bottom, above, below].count(&:itself) > 1
312
- raise ArgumentError, "'bottom', 'above', and 'below' are mutually exclusive"
313
- end
311
+ raise ArgumentError, "'bottom', 'above', and 'below' are mutually exclusive" if [bottom, above, below].count(&:itself) > 1
314
312
 
315
313
  if (above || below) && !(target = @server.role(above || below))
316
314
  raise ArgumentError, "The given 'above' or 'below' options are not valid"
317
315
  end
318
316
 
319
- if (below && target&.id == @server.id) || (@id == target&.id)
320
- raise ArgumentError, 'The target role that was provded is not valid'
321
- end
317
+ raise ArgumentError, 'The target role that was provded is not valid' if (below && target&.id == @server.id) || (@id == target&.id)
322
318
 
323
319
  roles = @server.roles.sort_by { |role| [role.position, role.id] }
324
320
 
@@ -394,9 +390,7 @@ module OnyxCord
394
390
  permissions: :undef, reason: nil
395
391
  )
396
392
  if display_icon != :undef
397
- if icon != :undef || unicode_emoji != :undef
398
- raise ArgumentError, "'display_icon' is mutually exclusive with 'icon' and 'unicode_emoji'"
399
- end
393
+ raise ArgumentError, "'display_icon' is mutually exclusive with 'icon' and 'unicode_emoji'" if icon != :undef || unicode_emoji != :undef
400
394
 
401
395
  if display_icon.nil?
402
396
  icon = nil
@@ -437,7 +431,7 @@ module OnyxCord
437
431
  }
438
432
  end
439
433
 
440
- update_data(JSON.parse(API::Server.update_role!(@bot.token, @server.id, @id, **data)))
434
+ update_data(JSON.parse(REST::Server.update_role!(@bot.token, @server.id, @id, **data)))
441
435
  nil
442
436
  end
443
437
 
@@ -93,7 +93,7 @@ module OnyxCord
93
93
  # @param size [Integer, nil] The URL will default to `4096`. You can otherwise specify any number that's a power of two to override this.
94
94
  # @return [String, nil] The URL to the scheduled event's cover image, or `nil` if the scheduled event doesn't have a cover image set.
95
95
  def cover_url(format: 'webp', size: 4096)
96
- API.scheduled_event_cover_url(@id, @cover_id, format, size) if @cover_id
96
+ REST.scheduled_event_cover_url(@id, @cover_id, format, size) if @cover_id
97
97
  end
98
98
 
99
99
  # @!method scheduled?
@@ -191,7 +191,7 @@ module OnyxCord
191
191
  builder[:recurrence_rule] = builder.to_h
192
192
  end
193
193
 
194
- update_data(JSON.parse(API::Server.update_scheduled_event(@bot.token, @server_id, @id, **data)))
194
+ update_data(JSON.parse(REST::Server.update_scheduled_event(@bot.token, @server_id, @id, **data)))
195
195
  nil
196
196
  end
197
197
 
@@ -199,7 +199,7 @@ module OnyxCord
199
199
  # @param reason [String, nil] The reason to show in the audit log for deleting the scheduled event.
200
200
  # @return [nil]
201
201
  def delete(reason: nil)
202
- API::Server.delete_scheduled_event(@bot.token, @server_id, @id, reason: reason)
202
+ REST::Server.delete_scheduled_event(@bot.token, @server_id, @id, reason: reason)
203
203
  @server&.delete_scheduled_event(@id)
204
204
  nil
205
205
  end
@@ -207,7 +207,7 @@ module OnyxCord
207
207
  # Get the total amount of users who are subscribed to the scheduled event.
208
208
  # @return [Integer] The total amount of users who are currently subscribed to the scheduled event.
209
209
  def user_count
210
- @user_count ||= JSON.parse(API::Server.get_scheduled_event(@bot.token, @server_id, @id, with_user_count: true))['user_count']
210
+ @user_count ||= JSON.parse(REST::Server.get_scheduled_event(@bot.token, @server_id, @id, with_user_count: true))['user_count']
211
211
  end
212
212
 
213
213
  alias_method :subscriber_count, :user_count
@@ -218,7 +218,7 @@ module OnyxCord
218
218
  # @return [Array<User, Member>] the users or members that have subscribed to the scheduled event.
219
219
  def users(limit: 100, member: false)
220
220
  get_users = proc do |fetch_limit, after = nil|
221
- response = JSON.parse(API::Server.get_scheduled_event_users(@bot.token, @server_id, @id, limit: fetch_limit, with_member: member, after: after))
221
+ response = JSON.parse(REST::Server.get_scheduled_event_users(@bot.token, @server_id, @id, limit: fetch_limit, with_member: member, after: after))
222
222
  response.map { |data| data['member'] ? Member.new(data['member'], server, @bot).tap { |member| server&.cache_member(member) } : User.new(data['user'], @bot) }
223
223
  end
224
224
 
@@ -14,7 +14,7 @@ module OnyxCord
14
14
  # or `png` to override this.
15
15
  # @return [String, nil] The URL to the server's icon, or `nil` if the server hasn't set an icon.
16
16
  def icon_url(format: 'webp')
17
- API.icon_url(@id, @icon_id, format) if @icon_id
17
+ REST.icon_url(@id, @icon_id, format) if @icon_id
18
18
  end
19
19
  end
20
20
 
@@ -172,7 +172,7 @@ module OnyxCord
172
172
  # end
173
173
  # @return [Hash<Integer => Integer>] A hash mapping role IDs to their respective member counts.
174
174
  def role_member_counts
175
- response = JSON.parse(API::Server.role_member_counts(@bot.token, @id))
175
+ response = JSON.parse(REST::Server.role_member_counts(@bot.token, @id))
176
176
  response.transform_keys!(&:to_i)
177
177
  response.tap { |hash| hash[@id] = @member_count }
178
178
  end
@@ -226,7 +226,7 @@ module OnyxCord
226
226
  # @return [Array<Integration>] an array of the integrations in this server.
227
227
  # @note If the server has more than 50 integrations, they cannot be accessed.
228
228
  def integrations
229
- integration = JSON.parse(API::Server.integrations(@bot.token, @id))
229
+ integration = JSON.parse(REST::Server.integrations(@bot.token, @id))
230
230
  integration.map { |element| Integration.new(element, @bot, self) }
231
231
  end
232
232
 
@@ -241,14 +241,14 @@ module OnyxCord
241
241
  action = AuditLogs::ACTIONS.key(action)
242
242
  user = user.resolve_id if user
243
243
  before = before.resolve_id if before
244
- AuditLogs.new(self, @bot, JSON.parse(API::Server.audit_logs(@bot.token, @id, limit, user, action, before)))
244
+ AuditLogs.new(self, @bot, JSON.parse(REST::Server.audit_logs(@bot.token, @id, limit, user, action, before)))
245
245
  end
246
246
 
247
247
  # @note For internal use only
248
248
  # @!visibility private
249
249
  def cache_widget_data(data = nil)
250
250
  data ||= if bot.permission?(:manage_server)
251
- JSON.parse(API::Server.widget(@bot.token, @id))
251
+ JSON.parse(REST::Server.widget(@bot.token, @id))
252
252
  else
253
253
  return update_data(nil)
254
254
  end
@@ -315,7 +315,7 @@ module OnyxCord
315
315
  def modify_widget(enabled, channel, reason = nil)
316
316
  cache_widget_data if @widget_enabled.nil?
317
317
  channel_id = channel ? channel.resolve_id : @widget_channel_id
318
- cache_widget_data(JSON.parse(API::Server.modify_widget(@bot.token, @id, enabled, channel_id, reason)))
318
+ cache_widget_data(JSON.parse(REST::Server.modify_widget(@bot.token, @id, enabled, channel_id, reason)))
319
319
  end
320
320
  alias_method :modify_embed, :modify_widget
321
321
 
@@ -344,7 +344,7 @@ module OnyxCord
344
344
  def add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false)
345
345
  user_id = user.resolve_id
346
346
  roles = roles.is_a?(Array) ? roles.map(&:resolve_id) : [roles.resolve_id]
347
- response = API::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute)
347
+ response = REST::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute)
348
348
  return nil if response.empty?
349
349
 
350
350
  add_member Member.new(JSON.parse(response), self, @bot)
@@ -357,7 +357,7 @@ module OnyxCord
357
357
  def prune_count(days)
358
358
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)
359
359
 
360
- response = JSON.parse API::Server.prune_count(@bot.token, @id, days)
360
+ response = JSON.parse REST::Server.prune_count(@bot.token, @id, days)
361
361
  response['pruned']
362
362
  end
363
363
 
@@ -369,7 +369,7 @@ module OnyxCord
369
369
  def begin_prune(days, reason = nil)
370
370
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)
371
371
 
372
- response = JSON.parse API::Server.begin_prune(@bot.token, @id, days, reason)
372
+ response = JSON.parse REST::Server.begin_prune(@bot.token, @id, days, reason)
373
373
  response['pruned']
374
374
  end
375
375
 
@@ -405,7 +405,7 @@ module OnyxCord
405
405
  def widget_url
406
406
  update_data if @widget_enabled.nil?
407
407
 
408
- API.widget_url(@id) if @widget_enabled
408
+ REST.widget_url(@id) if @widget_enabled
409
409
  end
410
410
 
411
411
  # @param style [Symbol] The style the picture should have. Possible styles are:
@@ -419,7 +419,7 @@ module OnyxCord
419
419
  def widget_banner_url(style)
420
420
  update_data if @widget_enabled.nil?
421
421
 
422
- API.widget_url(@id, style) if @widget_enabled
422
+ REST.widget_url(@id, style) if @widget_enabled
423
423
  end
424
424
 
425
425
  # Utility method to get a server's splash URL.
@@ -427,7 +427,7 @@ module OnyxCord
427
427
  # override this.
428
428
  # @return [String, nil] The URL to the server's splash image, or `nil` if the server doesn't have a splash image.
429
429
  def splash_url(format: 'webp')
430
- API.splash_url(@id, @splash_id, format) if @splash_id
430
+ REST.splash_url(@id, @splash_id, format) if @splash_id
431
431
  end
432
432
 
433
433
  # Utility method to get a server's banner URL.
@@ -435,14 +435,14 @@ module OnyxCord
435
435
  # override this.
436
436
  # @return [String, nil] The URL to the server's banner image, or `nil` if the server doesn't have a banner image.
437
437
  def banner_url(format: 'webp')
438
- API.banner_url(@id, @banner_id, format) if @banner_id
438
+ REST.banner_url(@id, @banner_id, format) if @banner_id
439
439
  end
440
440
 
441
441
  # Utility method to get a server's discovery splash URL.
442
442
  # @param format [String] The URL will default to `webp`. You can otherwise specify one of `jpg` or `png` to override this.
443
443
  # @return [String, nil] The URL to the server's discovery splash image, or `nil` if the server doesn't have a discovery splash image.
444
444
  def discovery_splash_url(format: 'webp')
445
- API.discovery_splash_url(@id, @discovery_splash_id, format) if @discovery_splash_id
445
+ REST.discovery_splash_url(@id, @discovery_splash_id, format) if @discovery_splash_id
446
446
  end
447
447
 
448
448
  # @return [String] a URL that a user can use to navigate to this server in the client
@@ -581,7 +581,7 @@ module OnyxCord
581
581
  total = nil
582
582
 
583
583
  get_messages = lambda do |query|
584
- data = JSON.parse(API::Server.search_messages(@bot.token, @id, **options, **query.compact))
584
+ data = JSON.parse(REST::Server.search_messages(@bot.token, @id, **options, **query.compact))
585
585
  total ||= data['total_results']
586
586
 
587
587
  data['threads']&.each do |thread|
@@ -636,7 +636,7 @@ module OnyxCord
636
636
  # @note For internal use only
637
637
  # @!visibility private
638
638
  def update_role_positions(role_positions, reason: nil)
639
- response = JSON.parse(API::Server.update_role_positions(@bot.token, @id, role_positions, reason))
639
+ response = JSON.parse(REST::Server.update_role_positions(@bot.token, @id, role_positions, reason))
640
640
  response.each { |data| role(data['id'].to_i)&.update_data(data) }
641
641
  end
642
642
 
@@ -738,7 +738,7 @@ module OnyxCord
738
738
 
739
739
  permission_overwrites.map! { |e| e.is_a?(Overwrite) ? e.to_hash : e } if permission_overwrites.is_a?(Array)
740
740
  parent_id = parent.respond_to?(:resolve_id) ? parent.resolve_id : nil
741
- response = API::Server.create_channel(@bot.token, @id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, position, reason)
741
+ response = REST::Server.create_channel(@bot.token, @id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, position, reason)
742
742
  Channel.new(JSON.parse(response), @bot)
743
743
  end
744
744
 
@@ -782,7 +782,7 @@ module OnyxCord
782
782
  icon = OnyxCord.encode64(display_icon)
783
783
  end
784
784
 
785
- response = API::Server.create_role(@bot.token, @id, name, nil, hoist, mentionable, permissions&.to_s, reason, colours, icon, unicode_emoji)
785
+ response = REST::Server.create_role(@bot.token, @id, name, nil, hoist, mentionable, permissions&.to_s, reason, colours, icon, unicode_emoji)
786
786
 
787
787
  role = Role.new(JSON.parse(response), @bot, self)
788
788
  @roles[role.id] = role
@@ -797,7 +797,7 @@ module OnyxCord
797
797
  def add_emoji(name, image, roles = [], reason: nil)
798
798
  image = image.respond_to?(:read) ? OnyxCord.encode64(image) : image
799
799
 
800
- data = JSON.parse(API::Server.add_emoji(@bot.token, @id, image, name, roles.map(&:resolve_id), reason))
800
+ data = JSON.parse(REST::Server.add_emoji(@bot.token, @id, image, name, roles.map(&:resolve_id), reason))
801
801
  new_emoji = Emoji.new(data, @bot, self)
802
802
  @emoji[new_emoji.id] = new_emoji
803
803
  end
@@ -806,7 +806,7 @@ module OnyxCord
806
806
  # @param emoji [Emoji, String, Integer] The emoji or emoji ID to be deleted.
807
807
  # @param reason [String] The reason the for the deletion of this emoji.
808
808
  def delete_emoji(emoji, reason: nil)
809
- API::Server.delete_emoji(@bot.token, @id, emoji.resolve_id, reason)
809
+ REST::Server.delete_emoji(@bot.token, @id, emoji.resolve_id, reason)
810
810
  end
811
811
 
812
812
  # Changes the name and/or role whitelist of an emoji on this server.
@@ -817,7 +817,7 @@ module OnyxCord
817
817
  # @return [Emoji] The edited emoji.
818
818
  def edit_emoji(emoji, name: nil, roles: nil, reason: nil)
819
819
  emoji = @emoji[emoji.resolve_id]
820
- data = JSON.parse(API::Server.edit_emoji(@bot.token, @id, emoji.resolve_id, name || emoji.name, (roles || emoji.roles).map(&:resolve_id), reason))
820
+ data = JSON.parse(REST::Server.edit_emoji(@bot.token, @id, emoji.resolve_id, name || emoji.name, (roles || emoji.roles).map(&:resolve_id), reason))
821
821
  new_emoji = Emoji.new(data, @bot, self)
822
822
  @emoji[new_emoji.id] = new_emoji
823
823
  end
@@ -842,7 +842,7 @@ module OnyxCord
842
842
  # @param limit [Integer] The maximum number of members between 1-1000 to return. Returns 1 member by default.
843
843
  # @return [Array<Member>, nil] An array of member objects that match the given parameters, or nil for no members.
844
844
  def search_members(name:, limit: nil)
845
- response = JSON.parse(API::Server.search_guild_members(@bot.token, @id, name, limit))
845
+ response = JSON.parse(REST::Server.search_guild_members(@bot.token, @id, name, limit))
846
846
  return nil if response.empty?
847
847
 
848
848
  response.map { |mem| Member.new(mem, self, @bot) }
@@ -854,7 +854,7 @@ module OnyxCord
854
854
  # @param after_id [Integer] Consider only users after given user id.
855
855
  # @return [Array<ServerBan>] a list of banned users on this server and the reason they were banned.
856
856
  def bans(limit: nil, before_id: nil, after_id: nil)
857
- response = JSON.parse(API::Server.bans(@bot.token, @id, limit, before_id, after_id))
857
+ response = JSON.parse(REST::Server.bans(@bot.token, @id, limit, before_id, after_id))
858
858
  response.map do |e|
859
859
  ServerBan.new(self, @bot.ensure_user(e['user']), e['reason'])
860
860
  end
@@ -875,7 +875,7 @@ module OnyxCord
875
875
  f_before = before.is_a?(Time) ? IDObject.synthesize(before) : before&.resolve_id
876
876
 
877
877
  get_bans = lambda do |before: nil, after: nil|
878
- data = API::Server.bans(@bot.token, @id, f_limit, before&.id || f_before, after&.id || f_after)
878
+ data = REST::Server.bans(@bot.token, @id, f_limit, before&.id || f_before, after&.id || f_after)
879
879
  JSON.parse(data).map { |ban| ServerBan.new(self, @bot.ensure_user(ban['user']), ban['reason']) }
880
880
  end
881
881
 
@@ -902,14 +902,14 @@ module OnyxCord
902
902
  message_seconds || 0
903
903
  end
904
904
 
905
- API::Server.ban_user!(@bot.token, @id, user.resolve_id, delete_messages, reason)
905
+ REST::Server.ban_user!(@bot.token, @id, user.resolve_id, delete_messages, reason)
906
906
  end
907
907
 
908
908
  # Unbans a previously banned user from this server.
909
909
  # @param user [User, String, Integer] The user to unban.
910
910
  # @param reason [String] The reason the user is being unbanned.
911
911
  def unban(user, reason = nil)
912
- API::Server.unban_user(@bot.token, @id, user.resolve_id, reason)
912
+ REST::Server.unban_user(@bot.token, @id, user.resolve_id, reason)
913
913
  end
914
914
 
915
915
  # Ban up to 200 users from this server in one go.
@@ -922,7 +922,7 @@ module OnyxCord
922
922
 
923
923
  return ban(users.first, 0, message_seconds: message_seconds, reason: reason) if users.size == 1
924
924
 
925
- response = API::Server.bulk_ban(@bot.token, @id, users.map(&:resolve_id), message_seconds, reason)
925
+ response = REST::Server.bulk_ban(@bot.token, @id, users.map(&:resolve_id), message_seconds, reason)
926
926
  BulkBan.new(JSON.parse(response), self, reason)
927
927
  end
928
928
 
@@ -930,7 +930,7 @@ module OnyxCord
930
930
  # @param user [User, String, Integer] The user to kick.
931
931
  # @param reason [String] The reason the user is being kicked.
932
932
  def kick(user, reason = nil)
933
- API::Server.remove_member(@bot.token, @id, user.resolve_id, reason)
933
+ REST::Server.remove_member(@bot.token, @id, user.resolve_id, reason)
934
934
  end
935
935
 
936
936
  # Forcibly moves a user into a different voice channel.
@@ -938,12 +938,12 @@ module OnyxCord
938
938
  # @param user [User, String, Integer] The user to move.
939
939
  # @param channel [Channel, String, Integer, nil] The voice channel to move into. (If nil, the user is disconnected from the voice channel)
940
940
  def move(user, channel)
941
- API::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel&.resolve_id)
941
+ REST::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel&.resolve_id)
942
942
  end
943
943
 
944
944
  # Leave the server.
945
945
  def leave
946
- API::User.leave_server(@bot.token, @id)
946
+ REST::User.leave_server(@bot.token, @id)
947
947
  end
948
948
 
949
949
  # Sets the server's name.
@@ -958,7 +958,7 @@ module OnyxCord
958
958
 
959
959
  @available_voice_regions = {}
960
960
 
961
- data = JSON.parse API::Server.regions(@bot.token, @id)
961
+ data = JSON.parse REST::Server.regions(@bot.token, @id)
962
962
  @available_voice_regions = data.map { |e| VoiceRegion.new e }
963
963
  end
964
964
 
@@ -971,7 +971,7 @@ module OnyxCord
971
971
  # Moves the server to another region. This will cause a voice interruption of at most a second.
972
972
  # @param region [String] The new region the server should be in.
973
973
  def region=(region)
974
- update_data(JSON.parse(API::Server.update!(@bot.token, @id, region: region.to_s)))
974
+ update_data(JSON.parse(REST::Server.update!(@bot.token, @id, region: region.to_s)))
975
975
  end
976
976
 
977
977
  # Sets the server's icon.
@@ -1127,14 +1127,14 @@ module OnyxCord
1127
1127
  # Requests a list of Webhooks on the server.
1128
1128
  # @return [Array<Webhook>] webhooks on the server.
1129
1129
  def webhooks
1130
- webhooks = JSON.parse(API::Server.webhooks(@bot.token, @id))
1130
+ webhooks = JSON.parse(REST::Server.webhooks(@bot.token, @id))
1131
1131
  webhooks.map { |webhook| Webhook.new(webhook, @bot) }
1132
1132
  end
1133
1133
 
1134
1134
  # Requests a list of Invites to the server.
1135
1135
  # @return [Array<Invite>] invites to the server.
1136
1136
  def invites
1137
- invites = JSON.parse(API::Server.invites(@bot.token, @id))
1137
+ invites = JSON.parse(REST::Server.invites(@bot.token, @id))
1138
1138
  invites.map { |invite| Invite.new(invite, @bot) }
1139
1139
  end
1140
1140
 
@@ -1143,7 +1143,7 @@ module OnyxCord
1143
1143
  # should be ignored and re-fetched via an HTTP request.
1144
1144
  # @return [Array<ScheduledEvent>] The scheduled events on the server.
1145
1145
  def scheduled_events(bypass_cache: false)
1146
- process_scheduled_events(JSON.parse(API::Server.list_scheduled_events(@bot.token, @id, with_user_count: true))) if bypass_cache
1146
+ process_scheduled_events(JSON.parse(REST::Server.list_scheduled_events(@bot.token, @id, with_user_count: true))) if bypass_cache
1147
1147
 
1148
1148
  @scheduled_events.values
1149
1149
  end
@@ -1157,7 +1157,7 @@ module OnyxCord
1157
1157
  return @scheduled_events[id] if @scheduled_events[id]
1158
1158
  return nil unless request
1159
1159
 
1160
- event = JSON.parse(API::Server.get_scheduled_event(@bot.token, @id, id, with_user_count: true))
1160
+ event = JSON.parse(REST::Server.get_scheduled_event(@bot.token, @id, id, with_user_count: true))
1161
1161
  scheduled_event = ScheduledEvent.new(event, self, @bot)
1162
1162
  @scheduled_events[scheduled_event.id] = scheduled_event
1163
1163
  rescue StandardError
@@ -1193,7 +1193,7 @@ module OnyxCord
1193
1193
  recurrence_rule: block_given? ? builder.to_h : recurrence_rule&.to_h
1194
1194
  }
1195
1195
 
1196
- event = JSON.parse(API::Server.create_scheduled_event(@bot.token, @id, **options, reason: reason))
1196
+ event = JSON.parse(REST::Server.create_scheduled_event(@bot.token, @id, **options, reason: reason))
1197
1197
  scheduled_event = ScheduledEvent.new(event, self, @bot)
1198
1198
  @scheduled_events[scheduled_event.id] = scheduled_event
1199
1199
  end
@@ -1305,7 +1305,7 @@ module OnyxCord
1305
1305
  channel_id: widget_channel == :undef ? widget_channel : widget_channel&.resolve_id
1306
1306
  }
1307
1307
 
1308
- cache_widget_data(JSON.parse(API::Server.update_widget(@bot.token, @id, **widget_data, reason: reason)))
1308
+ cache_widget_data(JSON.parse(REST::Server.update_widget(@bot.token, @id, **widget_data, reason: reason)))
1309
1309
  end
1310
1310
 
1311
1311
  if invites_disabled_until != :undef || dms_disabled_until != :undef
@@ -1314,12 +1314,12 @@ module OnyxCord
1314
1314
  invites_disabled_until: invites_disabled_until == :undef ? @invites_disabled_until&.iso8601 : invites_disabled_until&.iso8601
1315
1315
  }
1316
1316
 
1317
- process_incident_actions(JSON.parse(API::Server.update_incident_actions(@bot.token, @id, **incidents_data, reason: reason)))
1317
+ process_incident_actions(JSON.parse(REST::Server.update_incident_actions(@bot.token, @id, **incidents_data, reason: reason)))
1318
1318
  end
1319
1319
 
1320
1320
  return unless data.any? { |_, value| value != :undef }
1321
1321
 
1322
- update_data(JSON.parse(API::Server.update!(@bot.token, @id, **data, reason: reason)))
1322
+ update_data(JSON.parse(REST::Server.update!(@bot.token, @id, **data, reason: reason)))
1323
1323
  nil
1324
1324
  end
1325
1325
 
@@ -1327,7 +1327,7 @@ module OnyxCord
1327
1327
  # @note For internal use only
1328
1328
  # @!visibility private
1329
1329
  def update_data(new_data = nil)
1330
- new_data ||= JSON.parse(API::Server.resolve(@bot.token, @id))
1330
+ new_data ||= JSON.parse(REST::Server.resolve(@bot.token, @id))
1331
1331
  @name = new_data['name']
1332
1332
  @icon_id = new_data['icon']
1333
1333
  @splash_id = new_data['splash']
@@ -55,14 +55,14 @@ module OnyxCord
55
55
  # @param format [String] the URL will default to `webp`. You can otherwise specify one of `jpg` or `png` to override this.
56
56
  # @return [String, nil] the URL to the server's splash image, or `nil` if the server doesn't have a splash image.
57
57
  def splash_url(format = 'webp')
58
- API.splash_url(@id, @splash_id, format) if @splash_id
58
+ REST.splash_url(@id, @splash_id, format) if @splash_id
59
59
  end
60
60
 
61
61
  # Utility method to get a server preview's discovery splash URL.
62
62
  # @param format [String] the URL will default to `webp`. You can otherwise specify one of `jpg` or `png` to override this.
63
63
  # @return [String, nil] the URL to the server's discovery splash image, or `nil` if the server doesn't have a discovery splash image.
64
64
  def discovery_splash_url(format = 'webp')
65
- API.discovery_splash_url(@id, @discovery_splash_id, format) if @discovery_splash_id
65
+ REST.discovery_splash_url(@id, @discovery_splash_id, format) if @discovery_splash_id
66
66
  end
67
67
  end
68
68
  end
@@ -32,7 +32,7 @@ module OnyxCord
32
32
  # @param format [String] The URL will default to `webp`. You can otherwise specify one of `webp`, `jpg`, or `png` to override this.
33
33
  # @return [String, nil] the URL to the icon image (nil if no image is set).
34
34
  def icon_url(format = 'webp')
35
- API.team_icon_url(@id, @icon_id, format) if @icon_id
35
+ REST.team_icon_url(@id, @icon_id, format) if @icon_id
36
36
  end
37
37
 
38
38
  # A member that has been invited to a team.
@@ -92,12 +92,12 @@ module OnyxCord
92
92
  # TODO: Maybe change this method again after discriminator removal ?
93
93
  def avatar_url(format = nil)
94
94
  unless @avatar_id
95
- return API::User.default_avatar(@discriminator, legacy: true) if @discriminator && @discriminator != '0'
95
+ return REST::User.default_avatar(@discriminator, legacy: true) if @discriminator && @discriminator != '0'
96
96
 
97
- return API::User.default_avatar(@id)
97
+ return REST::User.default_avatar(@id)
98
98
  end
99
99
 
100
- API::User.avatar_url(@id, @avatar_id, format)
100
+ REST::User.avatar_url(@id, @avatar_id, format)
101
101
  end
102
102
 
103
103
  # @return [Integer] the public flags on a user's account
@@ -114,7 +114,7 @@ module OnyxCord
114
114
  # You can otherwise specify one of `webp`, `jpg`, `png`, or `gif` to override this.
115
115
  # @return [String, nil] the URL to the banner image or nil if the user doesn't have one.
116
116
  def banner_url(format = nil)
117
- API::User.banner_url(@id, banner_id, format) if banner_id
117
+ REST::User.banner_url(@id, banner_id, format) if banner_id
118
118
  end
119
119
  end
120
120
 
@@ -193,7 +193,7 @@ module OnyxCord
193
193
  # @return [String, nil] the ID of this user's current banner, can be used to generate a banner URL.
194
194
  # @see #banner_url
195
195
  def banner_id
196
- @banner_id ||= JSON.parse(API::User.resolve(@bot.token, @id))['banner']
196
+ @banner_id ||= JSON.parse(REST::User.resolve(@bot.token, @id))['banner']
197
197
  end
198
198
 
199
199
  # Set the user's username
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'onyxcord/webhooks/builder'
4
4
  require 'onyxcord/webhooks/view'
5
- require 'onyxcord/message_components'
5
+ require 'onyxcord/internal/message_payload'
6
6
 
7
7
  module OnyxCord
8
8
  # A webhook on a server channel
@@ -95,9 +95,9 @@ module OnyxCord
95
95
  # @param reason [String] The reason the webhook is being deleted.
96
96
  def delete(reason = nil)
97
97
  if token?
98
- API::Webhook.token_delete_webhook(@token, @id, reason)
98
+ REST::Webhook.token_delete_webhook(@token, @id, reason)
99
99
  else
100
- API::Webhook.delete_webhook(@bot.token, @id, reason)
100
+ REST::Webhook.delete_webhook(@bot.token, @id, reason)
101
101
  end
102
102
  end
103
103
 
@@ -151,7 +151,7 @@ module OnyxCord
151
151
  components ||= view
152
152
  flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
153
153
 
154
- resp = API::Webhook.token_execute_webhook(@token, @id, wait, data[:content], data[:username], data[:avatar_url], data[:tts], data[:file], data[:embeds], data[:allowed_mentions], flags, components.to_a)
154
+ resp = REST::Webhook.token_execute_webhook(@token, @id, wait, data[:content], data[:username], data[:avatar_url], data[:tts], data[:file], data[:embeds], data[:allowed_mentions], flags, components.to_a)
155
155
 
156
156
  Message.new(JSON.parse(resp), @bot) if wait
157
157
  end
@@ -161,7 +161,7 @@ module OnyxCord
161
161
  def delete_message(message)
162
162
  raise OnyxCord::Errors::UnauthorizedWebhook unless @token
163
163
 
164
- API::Webhook.token_delete_message(@token, @id, message.resolve_id)
164
+ REST::Webhook.token_delete_message(@token, @id, message.resolve_id)
165
165
  end
166
166
 
167
167
  # Edit a message created by this webhook.
@@ -178,7 +178,7 @@ module OnyxCord
178
178
  def edit_message(message, content: nil, embeds: nil, allowed_mentions: nil, builder: nil, components: nil, flags: 0, has_components: false, components_v2: false)
179
179
  raise OnyxCord::Errors::UnauthorizedWebhook unless @token
180
180
 
181
- params = { content: content, embeds: embeds, allowed_mentions: allowed_mentions }.compact
181
+ params = { allowed_mentions: allowed_mentions }.compact
182
182
 
183
183
  builder ||= Webhooks::Builder.new
184
184
  view ||= Webhooks::View.new
@@ -189,16 +189,18 @@ module OnyxCord
189
189
  components ||= view
190
190
  flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
191
191
 
192
- resp = API::Webhook.token_edit_message(@token, @id, message.resolve_id, data[:content], data[:embeds], data[:allowed_mentions], components.to_a, nil, flags)
192
+ edit_content = content == OnyxCord::MessagePayload::KEEP || !content.nil? ? content : data[:content]
193
+ edit_embeds = embeds == OnyxCord::MessagePayload::KEEP || !embeds.nil? ? embeds : data[:embeds]
194
+ resp = REST::Webhook.token_edit_message(@token, @id, message.resolve_id, edit_content, edit_embeds, data[:allowed_mentions], components.to_a, nil, flags)
193
195
  Message.new(JSON.parse(resp), @bot)
194
196
  end
195
197
 
196
198
  # Utility function to get a webhook's avatar URL.
197
199
  # @return [String] the URL to the avatar image
198
200
  def avatar_url
199
- return API::User.default_avatar(@id) unless @avatar
201
+ return REST::User.default_avatar(@id) unless @avatar
200
202
 
201
- API::User.avatar_url(@id, @avatar)
203
+ REST::User.avatar_url(@id, @avatar)
202
204
  end
203
205
 
204
206
  # The `inspect` method is overwritten to give more useful output.
@@ -227,9 +229,9 @@ module OnyxCord
227
229
  def update_webhook(new_data)
228
230
  reason = new_data.delete(:reason)
229
231
  data = JSON.parse(if token?
230
- API::Webhook.token_update_webhook(@token, @id, new_data, reason)
232
+ REST::Webhook.token_update_webhook(@token, @id, new_data, reason)
231
233
  else
232
- API::Webhook.update_webhook(@bot.token, @id, new_data, reason)
234
+ REST::Webhook.update_webhook(@bot.token, @id, new_data, reason)
233
235
  end)
234
236
  # Only update cache if API call worked
235
237
  update_internal(data) if data['name']