onyxcord 1.1.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 (133) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/Dockerfile +13 -0
  3. data/.devcontainer/devcontainer.json +29 -0
  4. data/.devcontainer/postcreate.sh +4 -0
  5. data/.github/CONTRIBUTING.md +13 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
  8. data/.github/pull_request_template.md +37 -0
  9. data/.github/workflows/ci.yml +78 -0
  10. data/.github/workflows/codeql.yml +65 -0
  11. data/.github/workflows/deploy.yml +54 -0
  12. data/.github/workflows/release.yml +51 -0
  13. data/.gitignore +16 -0
  14. data/.markdownlint.json +4 -0
  15. data/.overcommit.yml +7 -0
  16. data/.rspec +2 -0
  17. data/.rubocop.yml +129 -0
  18. data/.yardopts +1 -0
  19. data/CHANGELOG.md +0 -0
  20. data/Gemfile +7 -0
  21. data/LICENSE.txt +21 -0
  22. data/README.md +305 -0
  23. data/Rakefile +17 -0
  24. data/bin/console +15 -0
  25. data/bin/setup +7 -0
  26. data/lib/onyxcord/allowed_mentions.rb +43 -0
  27. data/lib/onyxcord/api/application.rb +316 -0
  28. data/lib/onyxcord/api/channel.rb +700 -0
  29. data/lib/onyxcord/api/interaction.rb +67 -0
  30. data/lib/onyxcord/api/invite.rb +44 -0
  31. data/lib/onyxcord/api/server.rb +775 -0
  32. data/lib/onyxcord/api/user.rb +158 -0
  33. data/lib/onyxcord/api/webhook.rb +163 -0
  34. data/lib/onyxcord/api.rb +335 -0
  35. data/lib/onyxcord/await.rb +51 -0
  36. data/lib/onyxcord/bot.rb +1971 -0
  37. data/lib/onyxcord/cache.rb +326 -0
  38. data/lib/onyxcord/colour_rgb.rb +43 -0
  39. data/lib/onyxcord/commands/command_bot.rb +511 -0
  40. data/lib/onyxcord/commands/container.rb +112 -0
  41. data/lib/onyxcord/commands/events.rb +11 -0
  42. data/lib/onyxcord/commands/parser.rb +327 -0
  43. data/lib/onyxcord/commands/rate_limiter.rb +144 -0
  44. data/lib/onyxcord/configuration.rb +125 -0
  45. data/lib/onyxcord/container.rb +988 -0
  46. data/lib/onyxcord/data/activity.rb +271 -0
  47. data/lib/onyxcord/data/application.rb +341 -0
  48. data/lib/onyxcord/data/attachment.rb +91 -0
  49. data/lib/onyxcord/data/audit_logs.rb +438 -0
  50. data/lib/onyxcord/data/avatar_decoration.rb +26 -0
  51. data/lib/onyxcord/data/call.rb +22 -0
  52. data/lib/onyxcord/data/channel.rb +1355 -0
  53. data/lib/onyxcord/data/channel_tag.rb +69 -0
  54. data/lib/onyxcord/data/collectibles.rb +47 -0
  55. data/lib/onyxcord/data/component.rb +583 -0
  56. data/lib/onyxcord/data/embed.rb +258 -0
  57. data/lib/onyxcord/data/emoji.rb +123 -0
  58. data/lib/onyxcord/data/install_params.rb +24 -0
  59. data/lib/onyxcord/data/integration.rb +144 -0
  60. data/lib/onyxcord/data/interaction.rb +1141 -0
  61. data/lib/onyxcord/data/invite.rb +137 -0
  62. data/lib/onyxcord/data/member.rb +528 -0
  63. data/lib/onyxcord/data/message.rb +612 -0
  64. data/lib/onyxcord/data/message_activity.rb +41 -0
  65. data/lib/onyxcord/data/overwrite.rb +109 -0
  66. data/lib/onyxcord/data/poll.rb +365 -0
  67. data/lib/onyxcord/data/primary_server.rb +60 -0
  68. data/lib/onyxcord/data/profile.rb +79 -0
  69. data/lib/onyxcord/data/reaction.rb +64 -0
  70. data/lib/onyxcord/data/recipient.rb +34 -0
  71. data/lib/onyxcord/data/role.rb +449 -0
  72. data/lib/onyxcord/data/role_connection_data.rb +69 -0
  73. data/lib/onyxcord/data/role_subscription.rb +41 -0
  74. data/lib/onyxcord/data/scheduled_event.rb +513 -0
  75. data/lib/onyxcord/data/server.rb +1614 -0
  76. data/lib/onyxcord/data/server_preview.rb +68 -0
  77. data/lib/onyxcord/data/snapshot.rb +112 -0
  78. data/lib/onyxcord/data/team.rb +98 -0
  79. data/lib/onyxcord/data/timestamp.rb +69 -0
  80. data/lib/onyxcord/data/user.rb +324 -0
  81. data/lib/onyxcord/data/voice_region.rb +46 -0
  82. data/lib/onyxcord/data/voice_state.rb +41 -0
  83. data/lib/onyxcord/data/webhook.rb +238 -0
  84. data/lib/onyxcord/data.rb +57 -0
  85. data/lib/onyxcord/errors.rb +246 -0
  86. data/lib/onyxcord/event_executor.rb +80 -0
  87. data/lib/onyxcord/events/await.rb +48 -0
  88. data/lib/onyxcord/events/bans.rb +60 -0
  89. data/lib/onyxcord/events/channels.rb +225 -0
  90. data/lib/onyxcord/events/generic.rb +129 -0
  91. data/lib/onyxcord/events/guilds.rb +269 -0
  92. data/lib/onyxcord/events/integrations.rb +100 -0
  93. data/lib/onyxcord/events/interactions.rb +624 -0
  94. data/lib/onyxcord/events/invites.rb +127 -0
  95. data/lib/onyxcord/events/lifetime.rb +31 -0
  96. data/lib/onyxcord/events/members.rb +110 -0
  97. data/lib/onyxcord/events/message.rb +399 -0
  98. data/lib/onyxcord/events/polls.rb +118 -0
  99. data/lib/onyxcord/events/presence.rb +131 -0
  100. data/lib/onyxcord/events/raw.rb +74 -0
  101. data/lib/onyxcord/events/reactions.rb +218 -0
  102. data/lib/onyxcord/events/roles.rb +87 -0
  103. data/lib/onyxcord/events/scheduled_events.rb +171 -0
  104. data/lib/onyxcord/events/threads.rb +100 -0
  105. data/lib/onyxcord/events/typing.rb +73 -0
  106. data/lib/onyxcord/events/voice_server_update.rb +48 -0
  107. data/lib/onyxcord/events/voice_state_update.rb +106 -0
  108. data/lib/onyxcord/events/webhooks.rb +65 -0
  109. data/lib/onyxcord/gateway.rb +890 -0
  110. data/lib/onyxcord/id_object.rb +39 -0
  111. data/lib/onyxcord/light/data.rb +62 -0
  112. data/lib/onyxcord/light/integrations.rb +73 -0
  113. data/lib/onyxcord/light/light_bot.rb +58 -0
  114. data/lib/onyxcord/light.rb +8 -0
  115. data/lib/onyxcord/logger.rb +120 -0
  116. data/lib/onyxcord/message_components.rb +70 -0
  117. data/lib/onyxcord/paginator.rb +60 -0
  118. data/lib/onyxcord/permissions.rb +255 -0
  119. data/lib/onyxcord/rate_limiter/gateway.rb +42 -0
  120. data/lib/onyxcord/rate_limiter/rest.rb +89 -0
  121. data/lib/onyxcord/version.rb +7 -0
  122. data/lib/onyxcord/voice/encoder.rb +115 -0
  123. data/lib/onyxcord/voice/network.rb +380 -0
  124. data/lib/onyxcord/voice/opcodes.rb +29 -0
  125. data/lib/onyxcord/voice/sodium.rb +157 -0
  126. data/lib/onyxcord/voice/timer.rb +19 -0
  127. data/lib/onyxcord/voice/voice_bot.rb +386 -0
  128. data/lib/onyxcord/webhooks.rb +14 -0
  129. data/lib/onyxcord/websocket.rb +62 -0
  130. data/lib/onyxcord.rb +180 -0
  131. data/onyxcord-webhooks.gemspec +30 -0
  132. data/onyxcord.gemspec +50 -0
  133. metadata +421 -0
@@ -0,0 +1,700 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/message_components'
4
+
5
+ # API calls for Channel
6
+ module OnyxCord::API::Channel
7
+ module_function
8
+
9
+ # Get a channel's data
10
+ # https://discord.com/developers/docs/resources/channel#get-channel
11
+ def resolve(token, channel_id)
12
+ OnyxCord::API.request(
13
+ :channels_cid,
14
+ channel_id,
15
+ :get,
16
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}",
17
+ Authorization: token
18
+ )
19
+ end
20
+
21
+ # Update a channel's data
22
+ # https://discord.com/developers/docs/resources/channel#modify-channel
23
+ def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil, archived = nil, auto_archive_duration = nil, locked = nil, invitable = nil, flags = nil, applied_tags = nil)
24
+ data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user, archived: archived, auto_archive_duration: auto_archive_duration, locked: locked, invitable: invitable, flags: flags, applied_tags: applied_tags }
25
+ data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
26
+ OnyxCord::API.request(
27
+ :channels_cid,
28
+ channel_id,
29
+ :patch,
30
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}",
31
+ data.to_json,
32
+ Authorization: token,
33
+ content_type: :json,
34
+ 'X-Audit-Log-Reason': reason
35
+ )
36
+ end
37
+
38
+ # Modify the properties of a channel.
39
+ # https://discord.com/developers/docs/resources/channel#modify-channel
40
+ def update!(token, channel_id, name: :undef, type: :undef, position: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent_id: :undef, rtc_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, available_tags: :undef, default_reaction_emoji: :undef, default_thread_rate_limit_per_user: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, auto_archive_duration: :undef, locked: :undef, invitable: :undef, applied_tags: :undef, reason: nil)
41
+ OnyxCord::API.request(
42
+ :channels_cid,
43
+ channel_id,
44
+ :patch,
45
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}",
46
+ { name:, type:, position:, topic:, nsfw:, rate_limit_per_user:, bitrate:, user_limit:, permission_overwrites:, parent_id:, rtc_region:, video_quality_mode:, default_auto_archive_duration:, flags:, available_tags:, default_reaction_emoji:, default_thread_rate_limit_per_user:, default_sort_order:, default_forum_layout:, archived:, auto_archive_duration:, locked:, invitable:, applied_tags: }.reject { |_, value| value == :undef }.to_json,
47
+ Authorization: token,
48
+ content_type: :json,
49
+ 'X-Audit-Log-Reason': reason
50
+ )
51
+ end
52
+
53
+ # Delete a channel
54
+ # https://discord.com/developers/docs/resources/channel#deleteclose-channel
55
+ def delete(token, channel_id, reason = nil)
56
+ OnyxCord::API.request(
57
+ :channels_cid,
58
+ channel_id,
59
+ :delete,
60
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}",
61
+ Authorization: token,
62
+ 'X-Audit-Log-Reason': reason
63
+ )
64
+ end
65
+
66
+ # Get a list of messages from a channel's history
67
+ # https://discord.com/developers/docs/resources/channel#get-channel-messages
68
+ def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
69
+ query_string = URI.encode_www_form({ limit: amount, before: before, after: after, around: around }.compact)
70
+ OnyxCord::API.request(
71
+ :channels_cid_messages,
72
+ channel_id,
73
+ :get,
74
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages?#{query_string}",
75
+ Authorization: token
76
+ )
77
+ end
78
+
79
+ # Get a single message from a channel's history by id
80
+ # https://discord.com/developers/docs/resources/channel#get-channel-message
81
+ def message(token, channel_id, message_id)
82
+ OnyxCord::API.request(
83
+ :channels_cid_messages_mid,
84
+ channel_id,
85
+ :get,
86
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
87
+ Authorization: token
88
+ )
89
+ end
90
+
91
+ # Send a message to a channel
92
+ # https://discord.com/developers/docs/resources/channel#create-message
93
+ # @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
94
+ # https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
95
+ def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil, enforce_nonce = false, poll = nil)
96
+ components = OnyxCord::MessageComponents.payload(components) unless components.nil?
97
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
98
+ body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components, flags: flags, enforce_nonce: enforce_nonce, poll: poll }
99
+ body = if attachments
100
+ files = [*0...attachments.size].zip(attachments).to_h
101
+ { **files, payload_json: body.to_json }
102
+ else
103
+ body.to_json
104
+ end
105
+
106
+ headers = { Authorization: token }
107
+ headers[:content_type] = :json unless attachments
108
+
109
+ OnyxCord::API.request(
110
+ :channels_cid_messages_mid,
111
+ channel_id,
112
+ :post,
113
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages",
114
+ body,
115
+ **headers
116
+ )
117
+ rescue RestClient::BadRequest => e
118
+ parsed = JSON.parse(e.response.body)
119
+ raise OnyxCord::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.'
120
+
121
+ raise
122
+ end
123
+
124
+ # Send a file as a message to a channel
125
+ # https://discord.com/developers/docs/resources/channel#upload-file
126
+ def upload_file(token, channel_id, file, caption: nil, tts: false)
127
+ OnyxCord::API.request(
128
+ :channels_cid_messages_mid,
129
+ channel_id,
130
+ :post,
131
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages",
132
+ { file: file, content: caption, tts: tts },
133
+ Authorization: token
134
+ )
135
+ end
136
+
137
+ # Edit a message
138
+ # https://discord.com/developers/docs/resources/channel#edit-message
139
+ def edit_message(token, channel_id, message_id, message, mentions = nil, embeds = nil, components = nil, flags = nil)
140
+ components = OnyxCord::MessageComponents.payload(components) unless components.nil? || components == :undef
141
+ flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
142
+ OnyxCord::API.request(
143
+ :channels_cid_messages_mid,
144
+ channel_id,
145
+ :patch,
146
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
147
+ { content: message, allowed_mentions: mentions, embeds: embeds, components: components, flags: flags }.reject { |_, v| v == :undef }.to_json,
148
+ Authorization: token,
149
+ content_type: :json
150
+ )
151
+ end
152
+
153
+ # Delete a message
154
+ # https://discord.com/developers/docs/resources/channel#delete-message
155
+ def delete_message(token, channel_id, message_id, reason = nil)
156
+ OnyxCord::API.request(
157
+ :channels_cid_messages_mid,
158
+ channel_id,
159
+ :delete,
160
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
161
+ Authorization: token,
162
+ 'X-Audit-Log-Reason': reason
163
+ )
164
+ end
165
+
166
+ # Crosspost a message
167
+ # https://discord.com/developers/docs/resources/message#crosspost-message
168
+ def crosspost_message(token, channel_id, message_id)
169
+ OnyxCord::API.request(
170
+ :channels_cid_messages_mid,
171
+ channel_id,
172
+ :post,
173
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/crosspost",
174
+ Authorization: token
175
+ )
176
+ end
177
+
178
+ # Delete messages in bulk
179
+ # https://discord.com/developers/docs/resources/channel#bulk-delete-messages
180
+ def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
181
+ OnyxCord::API.request(
182
+ :channels_cid_messages_bulk_delete,
183
+ channel_id,
184
+ :post,
185
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/bulk-delete",
186
+ { messages: messages }.to_json,
187
+ Authorization: token,
188
+ content_type: :json,
189
+ 'X-Audit-Log-Reason': reason
190
+ )
191
+ end
192
+
193
+ # Create a reaction on a message using this client
194
+ # https://discord.com/developers/docs/resources/channel#create-reaction
195
+ def create_reaction(token, channel_id, message_id, emoji)
196
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
197
+ OnyxCord::API.request(
198
+ :channels_cid_messages_mid_reactions_emoji_me,
199
+ channel_id,
200
+ :put,
201
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
202
+ nil,
203
+ Authorization: token,
204
+ content_type: :json
205
+ )
206
+ end
207
+
208
+ # Delete this client's own reaction on a message
209
+ # https://discord.com/developers/docs/resources/channel#delete-own-reaction
210
+ def delete_own_reaction(token, channel_id, message_id, emoji)
211
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
212
+ OnyxCord::API.request(
213
+ :channels_cid_messages_mid_reactions_emoji_me,
214
+ channel_id,
215
+ :delete,
216
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
217
+ Authorization: token
218
+ )
219
+ end
220
+
221
+ # Delete another client's reaction on a message
222
+ # https://discord.com/developers/docs/resources/channel#delete-user-reaction
223
+ def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
224
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
225
+ OnyxCord::API.request(
226
+ :channels_cid_messages_mid_reactions_emoji_uid,
227
+ channel_id,
228
+ :delete,
229
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}",
230
+ Authorization: token
231
+ )
232
+ end
233
+
234
+ # Get a list of clients who reacted with a specific reaction on a message
235
+ # https://discord.com/developers/docs/resources/channel#get-reactions
236
+ def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100, type = 0)
237
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
238
+ query_string = URI.encode_www_form({ limit: limit || 100, before: before_id, after: after_id, type: type }.compact)
239
+ OnyxCord::API.request(
240
+ :channels_cid_messages_mid_reactions_emoji,
241
+ channel_id,
242
+ :get,
243
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
244
+ Authorization: token
245
+ )
246
+ end
247
+
248
+ # Deletes all reactions on a message from all clients
249
+ # https://discord.com/developers/docs/resources/channel#delete-all-reactions
250
+ def delete_all_reactions(token, channel_id, message_id)
251
+ OnyxCord::API.request(
252
+ :channels_cid_messages_mid_reactions,
253
+ channel_id,
254
+ :delete,
255
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions",
256
+ Authorization: token
257
+ )
258
+ end
259
+
260
+ # Deletes all the reactions for a given emoji on a message
261
+ # https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji
262
+ def delete_all_emoji_reactions(token, channel_id, message_id, emoji)
263
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
264
+
265
+ OnyxCord::API.request(
266
+ :channels_cid_messages_mid_reactions_emoji,
267
+ channel_id,
268
+ :delete,
269
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
270
+ Authorization: token
271
+ )
272
+ end
273
+
274
+ # Update a channels permission for a role or member
275
+ # https://discord.com/developers/docs/resources/channel#edit-channel-permissions
276
+ def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
277
+ OnyxCord::API.request(
278
+ :channels_cid_permissions_oid,
279
+ channel_id,
280
+ :put,
281
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
282
+ { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
283
+ Authorization: token,
284
+ content_type: :json,
285
+ 'X-Audit-Log-Reason': reason
286
+ )
287
+ end
288
+
289
+ # Get a channel's invite list
290
+ # https://discord.com/developers/docs/resources/channel#get-channel-invites
291
+ def invites(token, channel_id)
292
+ OnyxCord::API.request(
293
+ :channels_cid_invites,
294
+ channel_id,
295
+ :get,
296
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/invites",
297
+ Authorization: token
298
+ )
299
+ end
300
+
301
+ # Create an instant invite from a server or a channel id
302
+ # https://discord.com/developers/docs/resources/channel#create-channel-invite
303
+ def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
304
+ OnyxCord::API.request(
305
+ :channels_cid_invites,
306
+ channel_id,
307
+ :post,
308
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/invites",
309
+ { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json,
310
+ Authorization: token,
311
+ content_type: :json,
312
+ 'X-Audit-Log-Reason': reason
313
+ )
314
+ end
315
+
316
+ # Delete channel permission
317
+ # https://discord.com/developers/docs/resources/channel#delete-channel-permission
318
+ def delete_permission(token, channel_id, overwrite_id, reason = nil)
319
+ OnyxCord::API.request(
320
+ :channels_cid_permissions_oid,
321
+ channel_id,
322
+ :delete,
323
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
324
+ Authorization: token,
325
+ 'X-Audit-Log-Reason': reason
326
+ )
327
+ end
328
+
329
+ # Start typing (needs to be resent every 5 seconds to keep up the typing)
330
+ # https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
331
+ def start_typing(token, channel_id)
332
+ OnyxCord::API.request(
333
+ :channels_cid_typing,
334
+ channel_id,
335
+ :post,
336
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/typing",
337
+ nil,
338
+ Authorization: token
339
+ )
340
+ end
341
+
342
+ # Get a list of pinned messages in a channel
343
+ # https://discord.com/developers/docs/resources/message#get-channel-pins
344
+ def pinned_messages(token, channel_id, limit = 50, before = nil)
345
+ query = URI.encode_www_form({ limit: limit, before: before }.compact)
346
+ OnyxCord::API.request(
347
+ :channels_cid_pins,
348
+ channel_id,
349
+ :get,
350
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/pins?#{query}",
351
+ Authorization: token
352
+ )
353
+ end
354
+
355
+ # Pin a message
356
+ # https://discord.com/developers/docs/resources/message#pin-message
357
+ def pin_message(token, channel_id, message_id, reason = nil)
358
+ OnyxCord::API.request(
359
+ :channels_cid_pins_mid,
360
+ channel_id,
361
+ :put,
362
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
363
+ nil,
364
+ Authorization: token,
365
+ 'X-Audit-Log-Reason': reason
366
+ )
367
+ end
368
+
369
+ # Unpin a message
370
+ # https://discord.com/developers/docs/resources/message#unpin-message
371
+ def unpin_message(token, channel_id, message_id, reason = nil)
372
+ OnyxCord::API.request(
373
+ :channels_cid_pins_mid,
374
+ channel_id,
375
+ :delete,
376
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
377
+ Authorization: token,
378
+ 'X-Audit-Log-Reason': reason
379
+ )
380
+ end
381
+
382
+ # Create an empty group channel.
383
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
384
+ # https://discord.com/developers/docs/resources/user#create-group-dm
385
+ def create_empty_group(token, bot_user_id)
386
+ OnyxCord::API.request(
387
+ :users_uid_channels,
388
+ nil,
389
+ :post,
390
+ "#{OnyxCord::API.api_base}/users/#{bot_user_id}/channels",
391
+ {}.to_json,
392
+ Authorization: token,
393
+ content_type: :json
394
+ )
395
+ end
396
+
397
+ # Create a group channel.
398
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
399
+ # https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
400
+ def create_group(token, pm_channel_id, user_id)
401
+ OnyxCord::API.request(
402
+ :channels_cid_recipients_uid,
403
+ nil,
404
+ :put,
405
+ "#{OnyxCord::API.api_base}/channels/#{pm_channel_id}/recipients/#{user_id}",
406
+ {}.to_json,
407
+ Authorization: token,
408
+ content_type: :json
409
+ )
410
+ rescue RestClient::InternalServerError
411
+ raise 'Attempted to add self as a new group channel recipient!'
412
+ rescue RestClient::NoContent
413
+ raise 'Attempted to create a group channel with the PM channel recipient!'
414
+ rescue RestClient::Forbidden
415
+ raise 'Attempted to add a user to group channel without permission!'
416
+ end
417
+
418
+ # Add a user to a group channel.
419
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
420
+ # https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
421
+ def add_group_user(token, group_channel_id, user_id)
422
+ OnyxCord::API.request(
423
+ :channels_cid_recipients_uid,
424
+ nil,
425
+ :put,
426
+ "#{OnyxCord::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
427
+ {}.to_json,
428
+ Authorization: token,
429
+ content_type: :json
430
+ )
431
+ end
432
+
433
+ # Remove a user from a group channel.
434
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
435
+ # https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient
436
+ def remove_group_user(token, group_channel_id, user_id)
437
+ OnyxCord::API.request(
438
+ :channels_cid_recipients_uid,
439
+ nil,
440
+ :delete,
441
+ "#{OnyxCord::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
442
+ Authorization: token,
443
+ content_type: :json
444
+ )
445
+ end
446
+
447
+ # Leave a group channel.
448
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
449
+ # https://discord.com/developers/docs/resources/channel#deleteclose-channel
450
+ def leave_group(token, group_channel_id)
451
+ OnyxCord::API.request(
452
+ :channels_cid,
453
+ nil,
454
+ :delete,
455
+ "#{OnyxCord::API.api_base}/channels/#{group_channel_id}",
456
+ Authorization: token,
457
+ content_type: :json
458
+ )
459
+ end
460
+
461
+ # Create a webhook
462
+ # https://discord.com/developers/docs/resources/webhook#create-webhook
463
+ def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
464
+ OnyxCord::API.request(
465
+ :channels_cid_webhooks,
466
+ channel_id,
467
+ :post,
468
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/webhooks",
469
+ { name: name, avatar: avatar }.to_json,
470
+ Authorization: token,
471
+ content_type: :json,
472
+ 'X-Audit-Log-Reason': reason
473
+ )
474
+ end
475
+
476
+ # Get channel webhooks
477
+ # https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
478
+ def webhooks(token, channel_id)
479
+ OnyxCord::API.request(
480
+ :channels_cid_webhooks,
481
+ channel_id,
482
+ :get,
483
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/webhooks",
484
+ Authorization: token
485
+ )
486
+ end
487
+
488
+ # Follow an annoucement channel.
489
+ # https://discord.com/developers/docs/resources/channel#follow-announcement-channel
490
+ def follow_channel(token, channel_id, webhook_channel_id, reason = nil)
491
+ OnyxCord::API.request(
492
+ :channels_cid_followers,
493
+ channel_id,
494
+ :post,
495
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/followers",
496
+ { webhook_channel_id: webhook_channel_id }.to_json,
497
+ Authorization: token,
498
+ content_type: :json,
499
+ 'X-Audit-Log-Reason': reason
500
+ )
501
+ end
502
+
503
+ # Start a thread based off a channel message.
504
+ # https://discord.com/developers/docs/resources/channel#start-thread-with-message
505
+ def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
506
+ OnyxCord::API.request(
507
+ :channels_cid_messages_mid_threads,
508
+ channel_id,
509
+ :post,
510
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
511
+ { name: name, auto_archive_duration: auto_archive_duration }.to_json,
512
+ Authorization: token,
513
+ content_type: :json
514
+ )
515
+ end
516
+
517
+ # Start a thread without an associated message.
518
+ # https://discord.com/developers/docs/resources/channel#start-thread-without-message
519
+ def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
520
+ OnyxCord::API.request(
521
+ :channels_cid_threads,
522
+ channel_id,
523
+ :post,
524
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/threads",
525
+ { name: name, auto_archive_duration: auto_archive_duration, type: type },
526
+ Authorization: token,
527
+ content_type: :json
528
+ )
529
+ end
530
+
531
+ # Add the current user to a thread.
532
+ # https://discord.com/developers/docs/resources/channel#join-thread
533
+ def join_thread(token, channel_id)
534
+ OnyxCord::API.request(
535
+ :channels_cid_thread_members_me,
536
+ channel_id,
537
+ :put,
538
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/thread-members/@me",
539
+ nil,
540
+ Authorization: token
541
+ )
542
+ end
543
+
544
+ # Add a user to a thread.
545
+ # https://discord.com/developers/docs/resources/channel#add-thread-member
546
+ def add_thread_member(token, channel_id, user_id)
547
+ OnyxCord::API.request(
548
+ :channels_cid_thread_members_uid,
549
+ channel_id,
550
+ :put,
551
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
552
+ nil,
553
+ Authorization: token
554
+ )
555
+ end
556
+
557
+ # Remove the current user from a thread.
558
+ # https://discord.com/developers/docs/resources/channel#leave-thread
559
+ def leave_thread(token, channel_id)
560
+ OnyxCord::API.request(
561
+ :channels_cid_thread_members_me,
562
+ channel_id,
563
+ :delete,
564
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
565
+ Authorization: token
566
+ )
567
+ end
568
+
569
+ # Remove a user from a thread.
570
+ # https://discord.com/developers/docs/resources/channel#remove-thread-member
571
+ def remove_thread_member(token, channel_id, user_id)
572
+ OnyxCord::API.request(
573
+ :channels_cid_thread_members_uid,
574
+ channel_id,
575
+ :delete,
576
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
577
+ Authorization: token
578
+ )
579
+ end
580
+
581
+ # Get the members of a thread.
582
+ # https://discord.com/developers/docs/resources/channel#list-thread-members
583
+ def list_thread_members(token, channel_id, before, limit)
584
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
585
+
586
+ OnyxCord::API.request(
587
+ :channels_cid_thread_members,
588
+ channel_id,
589
+ :get,
590
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/thread-members?#{query}",
591
+ Authorization: token
592
+ )
593
+ end
594
+
595
+ # List active threads
596
+ # https://discord.com/developers/docs/resources/channel#list-active-threads
597
+ def list_active_threads(token, channel_id)
598
+ OnyxCord::API.request(
599
+ :channels_cid_threads_active,
600
+ channel_id,
601
+ :get,
602
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/threads/active",
603
+ Authorization: token
604
+ )
605
+ end
606
+
607
+ # List public archived threads.
608
+ # https://discord.com/developers/docs/resources/channel#list-public-archived-threads
609
+ def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
610
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
611
+
612
+ OnyxCord::API.request(
613
+ :channels_cid_threads_archived_public,
614
+ channel_id,
615
+ :get,
616
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
617
+ Authorization: token
618
+ )
619
+ end
620
+
621
+ # List private archived threads.
622
+ # https://discord.com/developers/docs/resources/channel#list-private-archived-threads
623
+ def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
624
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
625
+
626
+ OnyxCord::API.request(
627
+ :channels_cid_threads_archived_private,
628
+ channel_id,
629
+ :get,
630
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
631
+ Authorization: token
632
+ )
633
+ end
634
+
635
+ # List joined private archived threads.
636
+ # https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads
637
+ def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
638
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
639
+
640
+ OnyxCord::API.request(
641
+ :channels_cid_users_me_threads_archived_private,
642
+ channel_id,
643
+ :get,
644
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
645
+ Authorization: token
646
+ )
647
+ end
648
+
649
+ # Start a thread in a forum or media channel.
650
+ # https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
651
+ def start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = nil, reason = nil)
652
+ body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact
653
+
654
+ body = if attachments
655
+ files = [*0...attachments.size].zip(attachments).to_h
656
+ { **files, payload_json: body.to_json }
657
+ else
658
+ body.to_json
659
+ end
660
+
661
+ headers = { Authorization: token, 'X-Audit-Log-Reason': reason }
662
+ headers[:content_type] = :json unless attachments
663
+
664
+ OnyxCord::API.request(
665
+ :channels_cid_threads,
666
+ channel_id,
667
+ :post,
668
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/threads",
669
+ body,
670
+ headers
671
+ )
672
+ end
673
+
674
+ # Get a list of users that have voted for a poll answer.
675
+ # https://discord.com/developers/docs/resources/poll#get-answer-voters
676
+ def get_poll_voters(token, channel_id, message_id, answer_id, limit: 100, after: nil)
677
+ query = URI.encode_www_form({ limit:, after: }.compact)
678
+
679
+ OnyxCord::API.request(
680
+ :channels_cid_polls_mid_answers_aid,
681
+ channel_id,
682
+ :get,
683
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/polls/#{message_id}/answers/#{answer_id}?#{query}",
684
+ Authorization: token
685
+ )
686
+ end
687
+
688
+ # End a poll created by the current user.
689
+ # https://discord.com/developers/docs/resources/poll#end-poll
690
+ def end_poll(token, channel_id, message_id)
691
+ OnyxCord::API.request(
692
+ :channels_cid_polls_mid_expire,
693
+ channel_id,
694
+ :post,
695
+ "#{OnyxCord::API.api_base}/channels/#{channel_id}/polls/#{message_id}/expire",
696
+ nil,
697
+ Authorization: token
698
+ )
699
+ end
700
+ end