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,450 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/interactions/internal/application_command'
4
+ require 'onyxcord/interactions/internal/option_builder'
5
+ require 'onyxcord/interactions/internal/permission_builder'
6
+ require 'onyxcord/interactions/internal/message'
7
+ require 'onyxcord/interactions/internal/metadata'
8
+ require 'onyxcord/webhooks'
9
+ require 'onyxcord/internal/message_payload'
10
+
11
+ module OnyxCord
12
+ # Base class for interaction objects.
13
+ class Interaction
14
+ include IDObject
15
+
16
+ # Interaction types.
17
+ # @see https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype
18
+ TYPES = {
19
+ ping: 1,
20
+ command: 2,
21
+ component: 3,
22
+ autocomplete: 4,
23
+ modal_submit: 5
24
+ }.freeze
25
+
26
+ # Interaction response types.
27
+ # @see https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactioncallbacktype
28
+ CALLBACK_TYPES = {
29
+ pong: 1,
30
+ channel_message: 4,
31
+ deferred_message: 5,
32
+ deferred_update: 6,
33
+ update_message: 7,
34
+ autocomplete: 8,
35
+ modal: 9
36
+ }.freeze
37
+
38
+ # Interaction context types.
39
+ # @see https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types
40
+ CONTEXTS = {
41
+ server: 0,
42
+ bot_dm: 1,
43
+ private_channel: 2
44
+ }.freeze
45
+
46
+ # Application integration types.
47
+ # @see https://discord.com/developers/docs/resources/application#application-object-application-integration-types
48
+ INTEGRATION_TYPES = {
49
+ server: 0,
50
+ user: 1
51
+ }.freeze
52
+
53
+ # Message flags for interaction responses.
54
+ # @see https://discord.com/developers/docs/resources/message#message-object-message-flags
55
+ FLAGS = {
56
+ ephemeral: 1 << 6,
57
+ suppress_embeds: 1 << 2,
58
+ suppress_notifications: 1 << 12
59
+ }.freeze
60
+
61
+ # @return [User, Member] The user that initiated the interaction.
62
+ attr_reader :user
63
+
64
+ # @return [Integer, nil] The ID of the server this interaction originates from.
65
+ attr_reader :server_id
66
+
67
+ # @return [Integer] The ID of the channel this interaction originates from.
68
+ attr_reader :channel_id
69
+
70
+ # @return [Channel] The channel where this interaction originates from.
71
+ attr_reader :channel
72
+
73
+ # @return [Integer] The ID of the application associated with this interaction.
74
+ attr_reader :application_id
75
+
76
+ # @return [String] The interaction token.
77
+ attr_reader :token
78
+
79
+ # @!visibility private
80
+ # @return [Integer] Currently pointless
81
+ attr_reader :version
82
+
83
+ # @return [Integer] The type of this interaction.
84
+ # @see TYPES
85
+ attr_reader :type
86
+
87
+ # @return [Hash] The interaction data.
88
+ attr_reader :data
89
+
90
+ # @return [Interactions::Message, nil] The message associated with this interaction.
91
+ attr_reader :message
92
+
93
+ # @return [Array<ActionRow>] The modal components associated with this interaction.
94
+ attr_reader :components
95
+
96
+ # @return [Permissions] The permissions the application has where this interaction originates from.
97
+ attr_reader :application_permissions
98
+
99
+ # @return [String] The selected language of the user that initiated this interaction.
100
+ attr_reader :user_locale
101
+
102
+ # @return [String, nil] The selected language of the server this interaction originates from.
103
+ attr_reader :server_locale
104
+
105
+ # @return [Integer] The context of where this interaction was initiated from.
106
+ attr_reader :context
107
+
108
+ # @return [Integer] The maximum number of bytes an attachment can have when responding to this interaction.
109
+ attr_reader :max_attachment_size
110
+
111
+ # @return [Array<Symbol>] The features of the server where this interaction was initiated from.
112
+ attr_reader :server_features
113
+
114
+ # @!visibility private
115
+ def initialize(data, bot)
116
+ @bot = bot
117
+
118
+ @id = data['id'].to_i
119
+ @application_id = data['application_id'].to_i
120
+ @type = data['type']
121
+ @message = Interactions::Message.new(data['message'], @bot, self) if data['message']
122
+ @data = data['data']
123
+ @server_id = data['guild_id']&.to_i
124
+ @channel_id = data['channel_id']&.to_i
125
+ @channel = bot.ensure_channel(data['channel']) if data['channel']
126
+ @user = begin
127
+ if data['member'] && data['member']['user']
128
+ data['member']['guild_id'] = @server_id
129
+ server = bot.servers ? bot.servers[@server_id] : nil
130
+ OnyxCord::Member.new(data['member'], server, bot)
131
+ elsif data['user']
132
+ bot.ensure_user(data['user'])
133
+ end
134
+ rescue StandardError => e
135
+ OnyxCord::LOGGER.error("Failed to parse interaction user/member: #{e}")
136
+ nil
137
+ end
138
+ @token = data['token']
139
+ @version = data['version']
140
+ @components = @data['components']&.filter_map { |component| Components.from_data(component, @bot) } || []
141
+ @application_permissions = Permissions.new(data['app_permissions']) if data['app_permissions']
142
+ @user_locale = data['locale']
143
+ @server_locale = data['guild_locale']
144
+ @context = data['context']
145
+ @max_attachment_size = data['attachment_size_limit']
146
+ @integration_owners = data['authorizing_integration_owners']&.to_h { |key, value| [key.to_i, value.to_i] }
147
+ @server_features = data['guild'] ? data['guild']['features']&.map { |feature| feature.downcase.to_sym } : []
148
+ end
149
+
150
+ # Respond to the creation of this interaction. An interaction must be responded to or deferred,
151
+ # The response may be modified with {Interaction#edit_response} or deleted with {Interaction#delete_response}.
152
+ # Further messages can be sent with {Interaction#send_message}.
153
+ # @param content [String] The content of the message.
154
+ # @param tts [true, false]
155
+ # @param embeds [Array<Hash, Webhooks::Embed>] The embeds for the message.
156
+ # @param allowed_mentions [Hash, AllowedMentions] Mentions that can ping on this message.
157
+ # @param flags [Integer] Message flags.
158
+ # @param ephemeral [true, false] Whether this message should only be visible to the interaction initiator.
159
+ # @param wait [true, false] Whether this method should return a Message object of the interaction response.
160
+ # @param components [Array<#to_h>] An array of components.
161
+ # @param attachments [Array<File>] Files that can be referenced in embeds and components via `attachment://file.png`.
162
+ # @param has_components [true, false] Whether this message includes any V2 components. Enabling this disables sending content, polls, and embeds.
163
+ # @param poll [Hash, Poll::Builder, Poll, nil] The poll that should be attached to this message.
164
+ # @yieldparam builder [Webhooks::Builder] An optional message builder. Arguments passed to the method overwrite builder data.
165
+ # @yieldparam view [Webhooks::View] A builder for creating interaction components.
166
+ def respond(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, suppress_embeds: nil, suppress_notifications: nil, wait: false, components: nil, attachments: nil, has_components: false, components_v2: false, poll: nil)
167
+ flags |= FLAGS[:ephemeral] if ephemeral
168
+ flags |= FLAGS[:suppress_embeds] if suppress_embeds
169
+ flags |= FLAGS[:suppress_notifications] if suppress_notifications
170
+
171
+ builder = OnyxCord::Webhooks::Builder.new
172
+ view = OnyxCord::Webhooks::View.new
173
+
174
+ # Set builder defaults from parameters
175
+ prepare_builder(builder, content, embeds, allowed_mentions, poll)
176
+ yield(builder, view) if block_given?
177
+
178
+ components ||= view
179
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
180
+ data = builder.to_json_hash
181
+
182
+ response = OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:channel_message], data[:content], tts, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, nil, wait, data[:poll])
183
+ return unless wait
184
+
185
+ Interactions::Message.new(JSON.parse(response)['resource']['message'], @bot, self)
186
+ end
187
+
188
+ # Defer an interaction, setting a temporary response that can be later overriden by {Interaction#send_message}.
189
+ # This method is used when you want to use a single message for your response but require additional processing time, or to simply ack
190
+ # an interaction so an error is not displayed.
191
+ # @param flags [Integer] Message flags.
192
+ # @param ephemeral [true, false] Whether this message should only be visible to the interaction initiator.
193
+ def defer(flags: 0, ephemeral: true, suppress_embeds: nil, suppress_notifications: nil)
194
+ flags |= FLAGS[:ephemeral] if ephemeral
195
+ flags |= FLAGS[:suppress_embeds] if suppress_embeds
196
+ flags |= FLAGS[:suppress_notifications] if suppress_notifications
197
+
198
+ OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:deferred_message], nil, nil, nil, nil, flags)
199
+ nil
200
+ end
201
+
202
+ # Defer an update to an interaction. This is can only currently used by Button interactions.
203
+ def defer_update
204
+ OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:deferred_update])
205
+ end
206
+
207
+ # Create a modal as a response.
208
+ # @param title [String] The title of the modal being shown.
209
+ # @param custom_id [String] The custom_id used to identify the modal and store data.
210
+ # @param components [Array<Component, Hash>, nil] An array of components. These can be defined through the block as well.
211
+ # @yieldparam [OnyxCord::Webhooks::Modal] A builder for the modal's components.
212
+ def show_modal(title:, custom_id:, components: nil)
213
+ if block_given?
214
+ modal_builder = OnyxCord::Webhooks::Modal.new
215
+ yield modal_builder
216
+
217
+ components = modal_builder.to_a
218
+ end
219
+
220
+ OnyxCord::REST::Interaction.create_interaction_modal_response(@token, @id, custom_id, title, components.to_a) unless type == Interaction::TYPES[:modal_submit]
221
+ nil
222
+ end
223
+
224
+ # Respond to the creation of this interaction. An interaction must be responded to or deferred,
225
+ # The response may be modified with {Interaction#edit_response} or deleted with {Interaction#delete_response}.
226
+ # Further messages can be sent with {Interaction#send_message}.
227
+ # @param content [String] The content of the message.
228
+ # @param tts [true, false]
229
+ # @param embeds [Array<Hash, Webhooks::Embed>] The embeds for the message.
230
+ # @param allowed_mentions [Hash, AllowedMentions] Mentions that can ping on this message.
231
+ # @param flags [Integer] Message flags.
232
+ # @param ephemeral [true, false] Whether this message should only be visible to the interaction initiator.
233
+ # @param wait [true, false] Whether this method should return a Message object of the interaction response.
234
+ # @param components [Array<#to_h>] An array of components.
235
+ # @param attachments [Array<File>] Files that can be referenced in embeds and components via `attachment://file.png`.
236
+ # @param has_components [true, false] Whether this message includes any V2 components. Enabling this disables sending content, polls, and embeds.
237
+ # @param poll [Hash, Poll::Builder, Poll, nil] The poll that should be attached to this message.
238
+ # @yieldparam builder [Webhooks::Builder] An optional message builder. Arguments passed to the method overwrite builder data.
239
+ # @yieldparam view [Webhooks::View] A builder for creating interaction components.
240
+ def update_message(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, suppress_embeds: nil, suppress_notifications: nil, wait: false, components: nil, attachments: nil, has_components: false, components_v2: false, poll: nil)
241
+ flags |= FLAGS[:ephemeral] if ephemeral
242
+ flags |= FLAGS[:suppress_embeds] if suppress_embeds
243
+ flags |= FLAGS[:suppress_notifications] if suppress_notifications
244
+
245
+ builder = OnyxCord::Webhooks::Builder.new
246
+ view = OnyxCord::Webhooks::View.new
247
+
248
+ prepare_builder(builder, content, embeds, allowed_mentions, poll)
249
+ yield(builder, view) if block_given?
250
+
251
+ components ||= view
252
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
253
+ data = builder.to_json_hash
254
+
255
+ response = OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:update_message], data[:content], tts, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, nil, wait, data[:poll])
256
+ return unless wait
257
+
258
+ Interactions::Message.new(JSON.parse(response)['resource']['message'], @bot, self)
259
+ end
260
+
261
+ # Edit the original response to this interaction.
262
+ # @param content [String] The content of the message.
263
+ # @param embeds [Array<Hash, Webhooks::Embed>] The embeds for the message.
264
+ # @param allowed_mentions [Hash, AllowedMentions] Mentions that can ping on this message.
265
+ # @param flags [Integer] Message flags.
266
+ # @param components [Array<#to_h>] An array of components.
267
+ # @param attachments [Array<File>] Files that can be referenced in embeds and components via `attachment://file.png`.
268
+ # @param has_components [true, false] Whether this message includes any V2 components. Enabling this disables sending content, polls, and embeds.
269
+ # @param poll [Hash, Poll::Builder, Poll, nil] The poll that should be attached to this message.
270
+ # @return [InteractionMessage] The updated response message.
271
+ # @yieldparam builder [Webhooks::Builder] An optional message builder. Arguments passed to the method overwrite builder data.
272
+ def edit_response(content: nil, embeds: nil, allowed_mentions: nil, flags: 0, components: nil, attachments: nil, has_components: false, components_v2: false, poll: nil)
273
+ builder = OnyxCord::Webhooks::Builder.new
274
+ view = OnyxCord::Webhooks::View.new
275
+
276
+ prepare_builder(builder, content, embeds, allowed_mentions, poll)
277
+ yield(builder, view) if block_given?
278
+
279
+ components ||= view
280
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
281
+ data = builder.to_json_hash
282
+ resp = OnyxCord::REST::Interaction.edit_original_interaction_response(@token, @application_id, edit_content(content, data), edit_embeds(embeds, data), data[:allowed_mentions], components.to_a, attachments, flags, data[:poll])
283
+
284
+ Interactions::Message.new(JSON.parse(resp), @bot, self)
285
+ end
286
+
287
+ # Delete the original interaction response.
288
+ def delete_response
289
+ OnyxCord::REST::Interaction.delete_original_interaction_response(@token, @application_id)
290
+ end
291
+
292
+ # @param content [String] The content of the message.
293
+ # @param tts [true, false]
294
+ # @param embeds [Array<Hash, Webhooks::Embed>] The embeds for the message.
295
+ # @param allowed_mentions [Hash, AllowedMentions] Mentions that can ping on this message.
296
+ # @param flags [Integer] Message flags.
297
+ # @param ephemeral [true, false] Whether this message should only be visible to the interaction initiator.
298
+ # @param attachments [Array<File>] Files that can be referenced in embeds and components via `attachment://file.png`.
299
+ # @param has_components [true, false] Whether this message includes any V2 components. Enabling this disables sending content, polls, and embeds.
300
+ # @param poll [Hash, Poll::Builder, Poll, nil] The poll that should be attached to this message.
301
+ # @yieldparam builder [Webhooks::Builder] An optional message builder. Arguments passed to the method overwrite builder data.
302
+ # @yieldparam view [Webhooks::View] A builder for creating interaction components.
303
+ def send_message(content: nil, embeds: nil, tts: false, allowed_mentions: nil, flags: 0, ephemeral: false, suppress_embeds: nil, suppress_notifications: nil, components: nil, attachments: nil, has_components: false, components_v2: false, poll: nil)
304
+ flags |= FLAGS[:ephemeral] if ephemeral
305
+ flags |= FLAGS[:suppress_embeds] if suppress_embeds
306
+ flags |= FLAGS[:suppress_notifications] if suppress_notifications
307
+
308
+ builder = OnyxCord::Webhooks::Builder.new
309
+ view = OnyxCord::Webhooks::View.new
310
+
311
+ prepare_builder(builder, content, embeds, allowed_mentions, poll)
312
+ yield(builder, view) if block_given?
313
+
314
+ components ||= view
315
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
316
+ data = builder.to_json_hash
317
+
318
+ resp = OnyxCord::REST::Webhook.token_execute_webhook(
319
+ @token, @application_id, true, data[:content], nil, nil, tts, nil, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, data[:poll]
320
+ )
321
+ Interactions::Message.new(JSON.parse(resp), @bot, self)
322
+ end
323
+
324
+ alias edit_original edit_response
325
+ alias delete_original delete_response
326
+ alias followup send_message
327
+
328
+ # @param message [String, Integer, InteractionMessage, Message] The message created by this interaction to be edited.
329
+ # @param content [String] The message content.
330
+ # @param embeds [Array<Hash, Webhooks::Embed>] The embeds for the message.
331
+ # @param allowed_mentions [Hash, AllowedMentions] Mentions that can ping on this message.
332
+ # @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`.
333
+ # @param flags [Integer] Message flags.
334
+ # @param has_components [true, false] Whether this message includes any V2 components. Enabling this disables sending content, polls, and embeds.
335
+ # @param poll [Hash, Poll::Builder, Poll, nil] The poll that should be attached to this message.
336
+ # @yieldparam builder [Webhooks::Builder] An optional message builder. Arguments passed to the method overwrite builder data.
337
+ def edit_message(message, content: nil, embeds: nil, allowed_mentions: nil, components: nil, attachments: nil, flags: 0, has_components: false, components_v2: false, poll: nil)
338
+ builder = OnyxCord::Webhooks::Builder.new
339
+ view = OnyxCord::Webhooks::View.new
340
+
341
+ prepare_builder(builder, content, embeds, allowed_mentions, poll)
342
+ yield(builder, view) if block_given?
343
+
344
+ components ||= view
345
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2)
346
+ data = builder.to_json_hash
347
+
348
+ resp = OnyxCord::REST::Webhook.token_edit_message(
349
+ @token, @application_id, message.resolve_id, edit_content(content, data), edit_embeds(embeds, data), data[:allowed_mentions], components.to_a, attachments, flags, data[:poll]
350
+ )
351
+ Interactions::Message.new(JSON.parse(resp), @bot, self)
352
+ end
353
+
354
+ # @param message [Integer, String, InteractionMessage, Message] The message created by this interaction to be deleted.
355
+ def delete_message(message)
356
+ OnyxCord::REST::Webhook.token_delete_message(@token, @application_id, message.resolve_id)
357
+ nil
358
+ end
359
+
360
+ # Show autocomplete choices as a response.
361
+ # @param choices [Array<Hash>, Hash] Array of autocomplete choices to show the user.
362
+ def show_autocomplete_choices(choices)
363
+ choices = choices.map { |name, value| { name: name, value: value } } unless choices.is_a?(Array)
364
+ OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:autocomplete], nil, nil, nil, nil, nil, nil, nil, choices)
365
+ nil
366
+ end
367
+
368
+ # Get the server associated with the interaction.
369
+ # @return [Server, nil] This will be nil for interactions that occur in DM channels or servers where the bot
370
+ # does not have the `bot` scope.
371
+ def server
372
+ @bot.server(@server_id)
373
+ end
374
+
375
+ # Get the button component that triggered the interaction.
376
+ # @return [Components::Button, nil] The button that triggered this interaction if applicable, otherwise `nil`.
377
+ def button
378
+ @type == TYPES[:component] ? get_component(@data['custom_id']) : nil
379
+ end
380
+
381
+ # Get the text input components associated with the interaction.
382
+ # @return [Array<TextInput>] The text input components associated with this interaction.
383
+ def text_inputs
384
+ @components.filter_map do |entity|
385
+ entity.component if entity.is_a?(Components::Label) && entity.component.is_a?(Components::TextInput)
386
+ end
387
+ end
388
+
389
+ # Get a component by its custom ID.
390
+ # @param custom_id [String] the custom ID of the component to find.
391
+ # @return [TextInput, Button, SelectMenu, Checkbox, ModalActionGroup, nil] The component associated with the custom ID, or `nil`.
392
+ def get_component(custom_id)
393
+ components = flatten_components((@message&.components || []) + @components)
394
+ components.find { |component| component.respond_to?(:custom_id) && component.custom_id == custom_id }
395
+ end
396
+
397
+ # @return [true, false] whether the application was installed by the user who initiated this interaction.
398
+ def user_integration?
399
+ @integration_owners[1] == @user.id
400
+ end
401
+
402
+ # @return [true, false] whether the application was installed by the server where this interaction originates from.
403
+ def server_integration?
404
+ @server_id ? @integration_owners[0] == @server_id : false
405
+ end
406
+
407
+ private
408
+
409
+ # Set builder defaults from parameters
410
+ # @param builder [OnyxCord::Webhooks::Builder]
411
+ # @param content [String, nil]
412
+ # @param embeds [Array<Hash, OnyxCord::Webhooks::Embed>, nil]
413
+ # @param allowed_mentions [AllowedMentions, Hash, nil]
414
+ # @param poll [Poll, Poll::Builder, Hash, nil]
415
+ def prepare_builder(builder, content, embeds, allowed_mentions, poll)
416
+ builder.poll = poll
417
+ builder.content = content unless content == OnyxCord::MessagePayload::KEEP
418
+ builder.allowed_mentions = allowed_mentions
419
+ embeds&.each { |embed| builder << embed } unless embeds == OnyxCord::MessagePayload::KEEP
420
+ end
421
+
422
+ def edit_content(content, data)
423
+ content == OnyxCord::MessagePayload::KEEP ? OnyxCord::MessagePayload::KEEP : data[:content]
424
+ end
425
+
426
+ def edit_embeds(embeds, data)
427
+ embeds == OnyxCord::MessagePayload::KEEP ? OnyxCord::MessagePayload::KEEP : data[:embeds]
428
+ end
429
+
430
+ # @!visibility private
431
+ def flatten_components(components)
432
+ components = components.flat_map do |entity|
433
+ case entity
434
+ when Components::ActionRow
435
+ entity.components
436
+ when Components::Label
437
+ entity.component
438
+ when Components::Section
439
+ entity.accessory if entity.accessory.respond_to?(:custom_id)
440
+ when Components::Container
441
+ flatten_components(entity.components)
442
+ else
443
+ entity if entity.respond_to?(:custom_id)
444
+ end
445
+ end
446
+
447
+ components.compact
448
+ end
449
+ end
450
+ end
@@ -119,7 +119,7 @@ module OnyxCord
119
119
  # Deletes this invite
120
120
  # @param reason [String] The reason the invite is being deleted.
121
121
  def delete(reason = nil)
122
- API::Invite.delete(@bot.token, @code, reason)
122
+ REST::Invite.delete(@bot.token, @code, reason)
123
123
  end
124
124
 
125
125
  alias_method :revoke, :delete
@@ -62,14 +62,14 @@ module OnyxCord
62
62
  # @param format [String, nil] If `nil`, the URL will default to `webp` for static avatars, and will detect if the member has a `gif` avatar. You can otherwise specify one of `webp`, `jpg`, `png`, or `gif` to override this.
63
63
  # @return [String, nil] the URL to the avatar image, or nil if the member doesn't have one.
64
64
  def server_avatar_url(format = nil)
65
- API::Server.avatar_url(@server_id, @user.id, @server_avatar_id, format) if @server_avatar_id
65
+ REST::Server.avatar_url(@server_id, @user.id, @server_avatar_id, format) if @server_avatar_id
66
66
  end
67
67
 
68
68
  # Utility method to get a member's server banner URL.
69
69
  # @param format [String, nil] If `nil`, the URL will default to `webp` for static banners, and will detect if the member has a `gif` banner. You can otherwise specify one of `webp`, `jpg`, `png`, or `gif` to override this.
70
70
  # @return [String, nil] the URL to the banner image, or nil if the member doesn't have one.
71
71
  def server_banner_url(format = nil)
72
- API::Server.banner_url(@server_id, @user.id, @server_banner_id, format) if @server_banner_id
72
+ REST::Server.banner_url(@server_id, @user.id, @server_banner_id, format) if @server_banner_id
73
73
  end
74
74
 
75
75
  MEMBER_FLAGS.each do |name, value|
@@ -234,7 +234,7 @@ module OnyxCord
234
234
  role_ids = role_id_array(role)
235
235
 
236
236
  if role_ids.one?
237
- API::Server.add_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason)
237
+ REST::Server.add_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason)
238
238
  else
239
239
  old_role_ids = resolve_role_ids
240
240
  new_role_ids = (old_role_ids + role_ids).uniq
@@ -249,7 +249,7 @@ module OnyxCord
249
249
  role_ids = role_id_array(role)
250
250
 
251
251
  if role_ids.one?
252
- API::Server.remove_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason)
252
+ REST::Server.remove_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason)
253
253
  else
254
254
  old_role_ids = resolve_role_ids
255
255
  new_role_ids = old_role_ids.reject { |i| role_ids.include?(i) }
@@ -512,17 +512,17 @@ module OnyxCord
512
512
 
513
513
  # @!visibility private
514
514
  def update_member_data(new_data)
515
- update_data(JSON.parse(API::Server.update_member(@bot.token, @server_id, @user.id, **new_data)))
515
+ update_data(JSON.parse(REST::Server.update_member(@bot.token, @server_id, @user.id, **new_data)))
516
516
  end
517
517
 
518
518
  # @!visibility private
519
519
  def update_current_member_data(new_data)
520
- update_data(JSON.parse(API::Server.update_current_member(@bot.token, @server_id,
521
- new_data.key?(:nick) ? new_data[:nick] : :undef,
522
- new_data[:reason],
523
- new_data.key?(:bio) ? new_data[:bio] : :undef,
524
- new_data.key?(:banner) ? new_data[:banner] : :undef,
525
- new_data.key?(:avatar) ? new_data[:avatar] : :undef)))
520
+ update_data(JSON.parse(REST::Server.update_current_member(@bot.token, @server_id,
521
+ new_data.key?(:nick) ? new_data[:nick] : :undef,
522
+ new_data[:reason],
523
+ new_data.key?(:bio) ? new_data[:bio] : :undef,
524
+ new_data.key?(:banner) ? new_data[:banner] : :undef,
525
+ new_data.key?(:avatar) ? new_data[:avatar] : :undef)))
526
526
  end
527
527
  end
528
528
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/message_components'
3
+ require 'onyxcord/internal/message_payload'
4
4
 
5
5
  module OnyxCord
6
6
  # A message on Discord that was sent to a text channel
@@ -304,25 +304,33 @@ module OnyxCord
304
304
  # @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) can be edited.
305
305
  # @return [Message] the resulting message.
306
306
  def edit(new_content, new_embeds = nil, new_components = nil, flags = 0)
307
- new_embeds = (new_embeds.instance_of?(Array) ? new_embeds.map(&:to_hash) : [new_embeds&.to_hash]).compact
307
+ new_embeds = if new_embeds == OnyxCord::MessagePayload::KEEP
308
+ new_embeds
309
+ else
310
+ (if new_embeds.instance_of?(Array)
311
+ new_embeds.map { |embed| embed.respond_to?(:to_hash) ? embed.to_hash : embed }
312
+ else
313
+ [new_embeds&.to_hash]
314
+ end).compact
315
+ end
308
316
  new_components = new_components.to_a
309
317
  flags = OnyxCord::MessageComponents.apply_v2_flag(flags, new_components)
310
318
 
311
- response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, :undef, new_embeds, new_components, flags)
319
+ response = REST::Channel.edit_message(@bot.token, @channel.id, @id, new_content, :undef, new_embeds, new_components, flags)
312
320
  Message.new(JSON.parse(response), @bot)
313
321
  end
314
322
 
315
323
  # Deletes this message.
316
324
  # @return [nil]
317
325
  def delete(reason = nil)
318
- API::Channel.delete_message(@bot.token, @channel.id, @id, reason)
326
+ REST::Channel.delete_message(@bot.token, @channel.id, @id, reason)
319
327
  nil
320
328
  end
321
329
 
322
330
  # Pins this message
323
331
  # @return [nil]
324
332
  def pin(reason = nil)
325
- API::Channel.pin_message(@bot.token, @channel.id, @id, reason)
333
+ REST::Channel.pin_message(@bot.token, @channel.id, @id, reason)
326
334
  @pinned = true
327
335
  nil
328
336
  end
@@ -330,7 +338,7 @@ module OnyxCord
330
338
  # Unpins this message
331
339
  # @return [nil]
332
340
  def unpin(reason = nil)
333
- API::Channel.unpin_message(@bot.token, @channel.id, @id, reason)
341
+ REST::Channel.unpin_message(@bot.token, @channel.id, @id, reason)
334
342
  @pinned = false
335
343
  nil
336
344
  end
@@ -338,7 +346,7 @@ module OnyxCord
338
346
  # Crossposts a message in a news channel.
339
347
  # @return [Message] the updated message object.
340
348
  def crosspost
341
- response = API::Channel.crosspost_message(@bot.token, @channel.id, @id)
349
+ response = REST::Channel.crosspost_message(@bot.token, @channel.id, @id)
342
350
  Message.new(JSON.parse(response), @bot)
343
351
  end
344
352
 
@@ -411,7 +419,7 @@ module OnyxCord
411
419
  # @return [Message] the resulting message.
412
420
  def suppress_embeds
413
421
  flags = @flags | (1 << 2)
414
- response = API::Channel.edit_message(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags)
422
+ response = REST::Channel.edit_message(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags)
415
423
  Message.new(JSON.parse(response), @bot)
416
424
  end
417
425
 
@@ -431,7 +439,7 @@ module OnyxCord
431
439
  # @return [nil]
432
440
  def create_reaction(reaction)
433
441
  reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction)
434
- API::Channel.create_reaction(@bot.token, @channel.id, @id, reaction)
442
+ REST::Channel.create_reaction(@bot.token, @channel.id, @id, reaction)
435
443
  nil
436
444
  end
437
445
 
@@ -450,7 +458,7 @@ module OnyxCord
450
458
  type = Reaction::TYPES[type] || type
451
459
 
452
460
  get_reactions = proc do |fetch_limit, after_id = nil|
453
- resp = API::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, fetch_limit, type)
461
+ resp = REST::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, fetch_limit, type)
454
462
  JSON.parse(resp).map { |d| User.new(d, @bot) }
455
463
  end
456
464
 
@@ -483,26 +491,26 @@ module OnyxCord
483
491
  # @param reaction [String, #to_reaction] the reaction to remove
484
492
  def delete_reaction(user, reaction)
485
493
  reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction)
486
- API::Channel.delete_user_reaction(@bot.token, @channel.id, @id, reaction, user.resolve_id)
494
+ REST::Channel.delete_user_reaction(@bot.token, @channel.id, @id, reaction, user.resolve_id)
487
495
  end
488
496
 
489
497
  # Deletes this client's reaction on this message.
490
498
  # @param reaction [String, #to_reaction] the reaction to remove
491
499
  def delete_own_reaction(reaction)
492
500
  reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction)
493
- API::Channel.delete_own_reaction(@bot.token, @channel.id, @id, reaction)
501
+ REST::Channel.delete_own_reaction(@bot.token, @channel.id, @id, reaction)
494
502
  end
495
503
 
496
504
  # Removes all reactions from this message.
497
505
  def delete_all_reactions
498
- API::Channel.delete_all_reactions(@bot.token, @channel.id, @id)
506
+ REST::Channel.delete_all_reactions(@bot.token, @channel.id, @id)
499
507
  end
500
508
 
501
509
  # Removes all reactions for a single emoji.
502
510
  # @param reaction [String, #to_reaction] the reaction to remove.
503
511
  def delete_all_reactions_for_emoji(reaction)
504
512
  reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction)
505
- API::Channel.delete_all_emoji_reactions(@bot.token, @channel.id, @id, reaction.to_s)
513
+ REST::Channel.delete_all_emoji_reactions(@bot.token, @channel.id, @id, reaction.to_s)
506
514
  end
507
515
 
508
516
  # The inspect method is overwritten to give more useful output
@@ -91,7 +91,7 @@ module OnyxCord
91
91
  def close
92
92
  raise OnyxCord::Errors::NoPermission, 'Cannot close the poll' if !@message.from_bot? || closed?
93
93
 
94
- Message.new(JSON.parse(API::Channel.end_poll(@bot.token, @message.channel.id, @message.id)), @bot)
94
+ Message.new(JSON.parse(REST::Channel.end_poll(@bot.token, @message.channel.id, @message.id)), @bot)
95
95
  end
96
96
 
97
97
  # Check if two poll objects are equivalent.
@@ -187,7 +187,7 @@ module OnyxCord
187
187
  after_time = after.is_a?(Time) ? IDObject.synthesise(after) : after&.resolve_id
188
188
 
189
189
  get_users = lambda do |limit, after|
190
- data = API::Channel.get_poll_voters(@bot.token, channel_id, @message_id, @id, after:, limit:)
190
+ data = REST::Channel.get_poll_voters(@bot.token, channel_id, @message_id, @id, after:, limit:)
191
191
  JSON.parse(data)['users'].collect { |poll_voter_data| @bot.ensure_user(poll_voter_data) }
192
192
  end
193
193
 
@@ -44,7 +44,7 @@ module OnyxCord
44
44
  # @param format [String] the URL will default to `webp`. You can otherwise specify one of `jpg` or `png` to override this.
45
45
  # @return [String] the URL to the server tag's badge image.
46
46
  def badge_url(format = 'webp')
47
- API.server_tag_badge_url(@server_id, @badge_id, format)
47
+ REST.server_tag_badge_url(@server_id, @badge_id, format)
48
48
  end
49
49
 
50
50
  # Comparison based off of server ID.