onyxcord 2.1.0 → 3.2.1
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.
- checksums.yaml +4 -4
- data/lib/onyxcord/application_commands/command.rb +4 -97
- data/lib/onyxcord/application_commands/context.rb +4 -94
- data/lib/onyxcord/application_commands/option.rb +4 -75
- data/lib/onyxcord/application_commands/registry.rb +4 -45
- data/lib/onyxcord/application_commands.rb +8 -5
- data/lib/onyxcord/bot.rb +24 -1759
- data/lib/onyxcord/{cache.rb → cache/manager.rb} +16 -14
- data/lib/onyxcord/cache/stores/gateway.rb +272 -0
- data/lib/onyxcord/commands/bot/channels.rb +48 -0
- data/lib/onyxcord/commands/bot/execution.rb +174 -0
- data/lib/onyxcord/commands/bot/message_dispatch.rb +58 -0
- data/lib/onyxcord/commands/bot/permissions.rb +72 -0
- data/lib/onyxcord/commands/bot.rb +209 -0
- data/lib/onyxcord/commands/container.rb +21 -2
- data/lib/onyxcord/commands/parser.rb +30 -1
- data/lib/onyxcord/container.rb +16 -960
- data/lib/onyxcord/core/bot/application_commands.rb +210 -0
- data/lib/onyxcord/core/bot/awaits.rb +112 -0
- data/lib/onyxcord/core/bot/invites.rb +42 -0
- data/lib/onyxcord/core/bot/messaging.rb +161 -0
- data/lib/onyxcord/core/bot/oauth.rb +27 -0
- data/lib/onyxcord/core/bot/presence.rb +103 -0
- data/lib/onyxcord/core/bot/runtime.rb +183 -0
- data/lib/onyxcord/core/bot/voice.rb +69 -0
- data/lib/onyxcord/{logger.rb → core/logger.rb} +5 -0
- data/lib/onyxcord/core/version.rb +5 -0
- data/lib/onyxcord/events/await/base.rb +48 -0
- data/lib/onyxcord/events/await.rb +1 -46
- data/lib/onyxcord/events/ban/base.rb +54 -0
- data/lib/onyxcord/events/ban/remove.rb +11 -0
- data/lib/onyxcord/events/bans.rb +2 -58
- data/lib/onyxcord/events/channels/base.rb +91 -0
- data/lib/onyxcord/events/channels/delete.rb +73 -0
- data/lib/onyxcord/events/channels/pins.rb +44 -0
- data/lib/onyxcord/events/channels/recipients.rb +77 -0
- data/lib/onyxcord/events/channels.rb +4 -239
- data/lib/onyxcord/events/guilds/audit_logs.rb +79 -0
- data/lib/onyxcord/events/guilds/base.rb +97 -0
- data/lib/onyxcord/events/guilds/emoji.rb +147 -0
- data/lib/onyxcord/events/guilds.rb +3 -267
- data/lib/onyxcord/events/handlers/channels.rb +133 -0
- data/lib/onyxcord/events/handlers/core.rb +146 -0
- data/lib/onyxcord/events/handlers/guilds.rb +375 -0
- data/lib/onyxcord/events/handlers/interactions.rb +238 -0
- data/lib/onyxcord/events/handlers/lifetime.rb +71 -0
- data/lib/onyxcord/events/handlers/messages.rb +218 -0
- data/lib/onyxcord/events/handlers/presence.rb +56 -0
- data/lib/onyxcord/events/handlers/raw.rb +39 -0
- data/lib/onyxcord/events/handlers/reactions.rb +98 -0
- data/lib/onyxcord/events/handlers/scheduled_events.rb +243 -0
- data/lib/onyxcord/events/handlers/voice.rb +46 -0
- data/lib/onyxcord/events/integration/base.rb +45 -0
- data/lib/onyxcord/events/integration/create.rb +11 -0
- data/lib/onyxcord/events/integration/delete.rb +48 -0
- data/lib/onyxcord/events/integration/update.rb +11 -0
- data/lib/onyxcord/events/integrations.rb +4 -98
- data/lib/onyxcord/events/interactions/application_commands.rb +185 -0
- data/lib/onyxcord/events/interactions/autocomplete.rb +62 -0
- data/lib/onyxcord/events/interactions/base.rb +175 -0
- data/lib/onyxcord/events/interactions/components.rb +221 -0
- data/lib/onyxcord/events/interactions/permissions.rb +53 -0
- data/lib/onyxcord/events/interactions.rb +5 -622
- data/lib/onyxcord/events/invite/create.rb +79 -0
- data/lib/onyxcord/events/invite/delete.rb +55 -0
- data/lib/onyxcord/events/invites.rb +2 -125
- data/lib/onyxcord/events/lifetime/base.rb +31 -0
- data/lib/onyxcord/events/lifetime.rb +1 -29
- data/lib/onyxcord/events/member/add.rb +12 -0
- data/lib/onyxcord/events/member/base.rb +67 -0
- data/lib/onyxcord/events/member/delete.rb +21 -0
- data/lib/onyxcord/events/member/update.rb +25 -0
- data/lib/onyxcord/events/members.rb +4 -108
- data/lib/onyxcord/events/message/base.rb +295 -0
- data/lib/onyxcord/events/message/ids.rb +71 -0
- data/lib/onyxcord/events/message/mentions.rb +55 -0
- data/lib/onyxcord/events/message/updates.rb +27 -0
- data/lib/onyxcord/events/message.rb +4 -397
- data/lib/onyxcord/events/poll/add.rb +11 -0
- data/lib/onyxcord/events/poll/base.rb +106 -0
- data/lib/onyxcord/events/poll/remove.rb +11 -0
- data/lib/onyxcord/events/polls.rb +3 -116
- data/lib/onyxcord/events/presence/playing.rb +77 -0
- data/lib/onyxcord/events/presence/status.rb +60 -0
- data/lib/onyxcord/events/presence.rb +2 -129
- data/lib/onyxcord/events/raw/base.rb +74 -0
- data/lib/onyxcord/events/raw.rb +1 -72
- data/lib/onyxcord/events/reactions/base.rb +143 -0
- data/lib/onyxcord/events/reactions/clear.rb +99 -0
- data/lib/onyxcord/events/reactions.rb +2 -216
- data/lib/onyxcord/events/role/create.rb +46 -0
- data/lib/onyxcord/events/role/delete.rb +40 -0
- data/lib/onyxcord/events/role/update.rb +11 -0
- data/lib/onyxcord/events/roles.rb +3 -85
- data/lib/onyxcord/events/scheduled_events/events.rb +112 -0
- data/lib/onyxcord/events/scheduled_events/users.rb +91 -0
- data/lib/onyxcord/events/scheduled_events.rb +2 -169
- data/lib/onyxcord/events/thread/base.rb +49 -0
- data/lib/onyxcord/events/thread/members.rb +44 -0
- data/lib/onyxcord/events/thread/update.rb +18 -0
- data/lib/onyxcord/events/threads.rb +3 -98
- data/lib/onyxcord/events/typing/base.rb +73 -0
- data/lib/onyxcord/events/typing.rb +1 -71
- data/lib/onyxcord/events/voice/server_update.rb +48 -0
- data/lib/onyxcord/events/voice/state_update.rb +137 -0
- data/lib/onyxcord/events/voice_server_update.rb +2 -46
- data/lib/onyxcord/events/voice_state_update.rb +2 -135
- data/lib/onyxcord/events/webhook/update.rb +65 -0
- data/lib/onyxcord/events/webhooks.rb +1 -63
- data/lib/onyxcord/gateway/client.rb +460 -0
- data/lib/onyxcord/interactions/command.rb +120 -0
- data/lib/onyxcord/interactions/context.rb +109 -0
- data/lib/onyxcord/interactions/internal/application_command.rb +203 -0
- data/lib/onyxcord/interactions/internal/message.rb +152 -0
- data/lib/onyxcord/interactions/internal/metadata.rb +109 -0
- data/lib/onyxcord/interactions/internal/option_builder.rb +230 -0
- data/lib/onyxcord/interactions/internal/permission_builder.rb +90 -0
- data/lib/onyxcord/interactions/option.rb +88 -0
- data/lib/onyxcord/interactions/registry.rb +50 -0
- data/lib/onyxcord/interactions.rb +16 -0
- data/lib/onyxcord/internal/async_runtime.rb +32 -0
- data/lib/onyxcord/internal/event_bus.rb +591 -0
- data/lib/onyxcord/internal/event_executor.rb +155 -0
- data/lib/onyxcord/internal/gateway/opcodes.rb +22 -0
- data/lib/onyxcord/internal/gateway/session.rb +45 -0
- data/lib/onyxcord/internal/http.rb +189 -0
- data/lib/onyxcord/internal/json.rb +51 -0
- data/lib/onyxcord/{message_payload.rb → internal/message_payload.rb} +3 -3
- data/lib/onyxcord/internal/rate_limiter/async_rest.rb +151 -0
- data/lib/onyxcord/internal/rate_limiter/gateway.rb +44 -0
- data/lib/onyxcord/internal/rate_limiter/rest.rb +144 -0
- data/lib/onyxcord/internal/websocket.rb +79 -0
- data/lib/onyxcord/light/data.rb +1 -1
- data/lib/onyxcord/light/integrations.rb +1 -1
- data/lib/onyxcord/light/light_bot.rb +7 -7
- data/lib/onyxcord/{data → models}/activity.rb +2 -2
- data/lib/onyxcord/{data → models}/application.rb +3 -3
- data/lib/onyxcord/{data → models}/avatar_decoration.rb +1 -1
- data/lib/onyxcord/{data → models}/channel.rb +23 -23
- data/lib/onyxcord/{data → models}/collectibles.rb +1 -1
- data/lib/onyxcord/{data → models}/emoji.rb +1 -1
- data/lib/onyxcord/models/interaction.rb +450 -0
- data/lib/onyxcord/{data → models}/invite.rb +1 -1
- data/lib/onyxcord/{data → models}/member.rb +11 -11
- data/lib/onyxcord/{data → models}/message.rb +18 -14
- data/lib/onyxcord/{data → models}/poll.rb +2 -2
- data/lib/onyxcord/{data → models}/primary_server.rb +1 -1
- data/lib/onyxcord/{data → models}/profile.rb +4 -4
- data/lib/onyxcord/{data → models}/role.rb +6 -12
- data/lib/onyxcord/{data → models}/scheduled_event.rb +5 -5
- data/lib/onyxcord/{data → models}/server.rb +41 -41
- data/lib/onyxcord/{data → models}/server_preview.rb +2 -2
- data/lib/onyxcord/{data → models}/team.rb +1 -1
- data/lib/onyxcord/{data → models}/user.rb +5 -5
- data/lib/onyxcord/{data → models}/webhook.rb +10 -10
- data/lib/onyxcord/models.rb +57 -0
- data/lib/onyxcord/{api.rb → rest/client.rb} +23 -22
- data/lib/onyxcord/{api → rest/routes}/application.rb +79 -57
- data/lib/onyxcord/rest/routes/channel/base.rb +73 -0
- data/lib/onyxcord/rest/routes/channel/groups.rb +78 -0
- data/lib/onyxcord/rest/routes/channel/messages.rb +130 -0
- data/lib/onyxcord/rest/routes/channel/permissions.rb +73 -0
- data/lib/onyxcord/rest/routes/channel/pins.rb +45 -0
- data/lib/onyxcord/rest/routes/channel/polls.rb +32 -0
- data/lib/onyxcord/rest/routes/channel/reactions.rb +86 -0
- data/lib/onyxcord/rest/routes/channel/threads.rb +176 -0
- data/lib/onyxcord/rest/routes/channel/webhooks.rb +47 -0
- data/lib/onyxcord/rest/routes/channel.rb +12 -0
- data/lib/onyxcord/{api/interaction.rb → rest/routes/interaction/base.rb} +7 -25
- data/lib/onyxcord/rest/routes/interaction/response.rb +24 -0
- data/lib/onyxcord/rest/routes/interaction.rb +4 -0
- data/lib/onyxcord/{api → rest/routes}/invite.rb +7 -7
- data/lib/onyxcord/rest/routes/server/admin.rb +174 -0
- data/lib/onyxcord/rest/routes/server/assets.rb +25 -0
- data/lib/onyxcord/rest/routes/server/bans.rb +67 -0
- data/lib/onyxcord/rest/routes/server/base.rb +77 -0
- data/lib/onyxcord/rest/routes/server/channels.rb +58 -0
- data/lib/onyxcord/rest/routes/server/emoji.rb +48 -0
- data/lib/onyxcord/rest/routes/server/members.rb +109 -0
- data/lib/onyxcord/rest/routes/server/messages.rb +19 -0
- data/lib/onyxcord/rest/routes/server/roles.rb +156 -0
- data/lib/onyxcord/rest/routes/server/scheduled_events.rb +86 -0
- data/lib/onyxcord/rest/routes/server.rb +12 -0
- data/lib/onyxcord/{api → rest/routes}/user.rb +23 -23
- data/lib/onyxcord/{api → rest/routes}/webhook.rb +22 -22
- data/lib/onyxcord/{allowed_mentions.rb → utils/allowed_mentions.rb} +1 -1
- data/lib/onyxcord/utils/timestamp.rb +69 -0
- data/lib/onyxcord/voice/{voice_bot.rb → client.rb} +4 -4
- data/lib/onyxcord/voice/encoder.rb +1 -1
- data/lib/onyxcord/voice/network/udp.rb +135 -0
- data/lib/onyxcord/voice/network/websocket.rb +225 -0
- data/lib/onyxcord/voice/network.rb +5 -357
- data/lib/onyxcord/webhooks/builder.rb +1 -1
- data/lib/onyxcord/webhooks/client.rb +13 -13
- data/lib/onyxcord/webhooks/modal/group_builder.rb +55 -0
- data/lib/onyxcord/webhooks/modal/label_builder.rb +183 -0
- data/lib/onyxcord/webhooks/modal.rb +2 -239
- data/lib/onyxcord/webhooks/version.rb +3 -3
- data/lib/onyxcord/webhooks/view/container_builder.rb +80 -0
- data/lib/onyxcord/webhooks/view/file_builder.rb +24 -0
- data/lib/onyxcord/webhooks/view/media_gallery_builder.rb +50 -0
- data/lib/onyxcord/webhooks/view/row_builder.rb +120 -0
- data/lib/onyxcord/webhooks/view/section_builder.rb +61 -0
- data/lib/onyxcord/webhooks/view/select_menu_builder.rb +77 -0
- data/lib/onyxcord/webhooks/view/separator_builder.rb +22 -0
- data/lib/onyxcord/webhooks/view/text_display_builder.rb +20 -0
- data/lib/onyxcord/webhooks/view.rb +9 -425
- data/lib/onyxcord.rb +106 -42
- metadata +207 -92
- data/.github/CONTRIBUTING.md +0 -13
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
- data/.github/pull_request_template.md +0 -37
- data/.github/workflows/ci.yml +0 -78
- data/.github/workflows/codeql.yml +0 -65
- data/.github/workflows/deploy.yml +0 -54
- data/.github/workflows/release.yml +0 -51
- data/.gitignore +0 -17
- data/.markdownlint.json +0 -4
- data/.overcommit.yml +0 -7
- data/.rspec +0 -2
- data/.rubocop.yml +0 -129
- data/.yardopts +0 -1
- data/CHANGELOG.md +0 -257
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.md +0 -448
- data/Rakefile +0 -13
- data/lib/onyxcord/api/channel.rb +0 -703
- data/lib/onyxcord/api/server.rb +0 -775
- data/lib/onyxcord/async/runtime.rb +0 -30
- data/lib/onyxcord/commands/command_bot.rb +0 -505
- data/lib/onyxcord/data/interaction.rb +0 -1151
- data/lib/onyxcord/data.rb +0 -57
- data/lib/onyxcord/event_executor.rb +0 -153
- data/lib/onyxcord/gateway.rb +0 -505
- data/lib/onyxcord/http.rb +0 -186
- data/lib/onyxcord/json.rb +0 -49
- data/lib/onyxcord/rate_limiter/async_rest.rb +0 -150
- data/lib/onyxcord/rate_limiter/gateway.rb +0 -42
- data/lib/onyxcord/rate_limiter/rest.rb +0 -142
- data/lib/onyxcord/version.rb +0 -7
- data/lib/onyxcord/websocket.rb +0 -77
- data/onyxcord.gemspec +0 -63
- /data/lib/onyxcord/{configuration.rb → core/configuration.rb} +0 -0
- /data/lib/onyxcord/{errors.rb → core/errors.rb} +0 -0
- /data/lib/onyxcord/{upload.rb → internal/upload.rb} +0 -0
- /data/lib/onyxcord/{data → models}/attachment.rb +0 -0
- /data/lib/onyxcord/{data → models}/audit_logs.rb +0 -0
- /data/lib/onyxcord/{data → models}/call.rb +0 -0
- /data/lib/onyxcord/{data → models}/channel_tag.rb +0 -0
- /data/lib/onyxcord/{data → models}/component.rb +0 -0
- /data/lib/onyxcord/{data → models}/embed.rb +0 -0
- /data/lib/onyxcord/{data → models}/install_params.rb +0 -0
- /data/lib/onyxcord/{data → models}/integration.rb +0 -0
- /data/lib/onyxcord/{data → models}/message_activity.rb +0 -0
- /data/lib/onyxcord/{data → models}/overwrite.rb +0 -0
- /data/lib/onyxcord/{data → models}/reaction.rb +0 -0
- /data/lib/onyxcord/{data → models}/recipient.rb +0 -0
- /data/lib/onyxcord/{data → models}/role_connection_data.rb +0 -0
- /data/lib/onyxcord/{data → models}/role_subscription.rb +0 -0
- /data/lib/onyxcord/{data → models}/snapshot.rb +0 -0
- /data/lib/onyxcord/{data → models}/timestamp.rb +0 -0
- /data/lib/onyxcord/{data → models}/voice_region.rb +0 -0
- /data/lib/onyxcord/{data → models}/voice_state.rb +0 -0
- /data/lib/onyxcord/{colour_rgb.rb → utils/colour_rgb.rb} +0 -0
- /data/lib/onyxcord/{id_object.rb → utils/id_object.rb} +0 -0
- /data/lib/onyxcord/{message_components.rb → utils/message_components.rb} +0 -0
- /data/lib/onyxcord/{paginator.rb → utils/paginator.rb} +0 -0
- /data/lib/onyxcord/{permissions.rb → utils/permissions.rb} +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Get a list of messages from a channel's history
|
|
7
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-messages
|
|
8
|
+
def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
|
|
9
|
+
query_string = URI.encode_www_form({ limit: amount, before: before, after: after, around: around }.compact)
|
|
10
|
+
OnyxCord::REST.request(
|
|
11
|
+
:channels_cid_messages,
|
|
12
|
+
channel_id,
|
|
13
|
+
:get,
|
|
14
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages?#{query_string}",
|
|
15
|
+
Authorization: token
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Get a single message from a channel's history by id
|
|
20
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-message
|
|
21
|
+
def message(token, channel_id, message_id)
|
|
22
|
+
OnyxCord::REST.request(
|
|
23
|
+
:channels_cid_messages_mid,
|
|
24
|
+
channel_id,
|
|
25
|
+
:get,
|
|
26
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
|
27
|
+
Authorization: token
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Send a message to a channel
|
|
32
|
+
# https://discord.com/developers/docs/resources/channel#create-message
|
|
33
|
+
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
|
|
34
|
+
# https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
|
|
35
|
+
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)
|
|
36
|
+
tts = false unless [true, false].include?(tts)
|
|
37
|
+
components = OnyxCord::MessageComponents.payload(components) unless components.nil?
|
|
38
|
+
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
39
|
+
OnyxCord::MessagePayload.validate!(content: message, embeds: embeds, components: components, flags: flags, attachments: attachments, poll: poll)
|
|
40
|
+
body = { content: message, tts: tts == true, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components, attachments: attachments ? attachment_payload(attachments) : nil, flags: flags, enforce_nonce: enforce_nonce, poll: poll }.compact
|
|
41
|
+
body = if attachments
|
|
42
|
+
multipart_body(body, attachments)
|
|
43
|
+
else
|
|
44
|
+
body.to_json
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
headers = { Authorization: token }
|
|
48
|
+
headers[:content_type] = :json unless attachments
|
|
49
|
+
|
|
50
|
+
OnyxCord::REST.request(
|
|
51
|
+
:channels_cid_messages_mid,
|
|
52
|
+
channel_id,
|
|
53
|
+
:post,
|
|
54
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages",
|
|
55
|
+
body,
|
|
56
|
+
**headers
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Send a file as a message to a channel
|
|
61
|
+
# https://discord.com/developers/docs/resources/channel#upload-file
|
|
62
|
+
def upload_file(token, channel_id, file, caption: nil, tts: false)
|
|
63
|
+
OnyxCord::REST.request(
|
|
64
|
+
:channels_cid_messages_mid,
|
|
65
|
+
channel_id,
|
|
66
|
+
:post,
|
|
67
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages",
|
|
68
|
+
{ file: file, content: caption, tts: tts },
|
|
69
|
+
Authorization: token
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Edit a message
|
|
74
|
+
# https://discord.com/developers/docs/resources/channel#edit-message
|
|
75
|
+
def edit_message(token, channel_id, message_id, message, mentions = nil, embeds = nil, components = nil, flags = nil)
|
|
76
|
+
components = OnyxCord::MessageComponents.payload(components) unless components.nil? || components == :undef
|
|
77
|
+
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
78
|
+
body = OnyxCord::MessagePayload.edit_body(message, embeds)
|
|
79
|
+
body.merge!(allowed_mentions: mentions, components: components, flags: flags)
|
|
80
|
+
OnyxCord::REST.request(
|
|
81
|
+
:channels_cid_messages_mid,
|
|
82
|
+
channel_id,
|
|
83
|
+
:patch,
|
|
84
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
|
85
|
+
body.reject { |_, v| v == :undef }.to_json,
|
|
86
|
+
Authorization: token,
|
|
87
|
+
content_type: :json
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Delete a message
|
|
92
|
+
# https://discord.com/developers/docs/resources/channel#delete-message
|
|
93
|
+
def delete_message(token, channel_id, message_id, reason = nil)
|
|
94
|
+
OnyxCord::REST.request(
|
|
95
|
+
:channels_cid_messages_mid,
|
|
96
|
+
channel_id,
|
|
97
|
+
:delete,
|
|
98
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
|
99
|
+
Authorization: token,
|
|
100
|
+
'X-Audit-Log-Reason': reason
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Crosspost a message
|
|
105
|
+
# https://discord.com/developers/docs/resources/message#crosspost-message
|
|
106
|
+
def crosspost_message(token, channel_id, message_id)
|
|
107
|
+
OnyxCord::REST.request(
|
|
108
|
+
:channels_cid_messages_mid,
|
|
109
|
+
channel_id,
|
|
110
|
+
:post,
|
|
111
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/crosspost",
|
|
112
|
+
Authorization: token
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Delete messages in bulk
|
|
117
|
+
# https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
|
118
|
+
def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
|
|
119
|
+
OnyxCord::REST.request(
|
|
120
|
+
:channels_cid_messages_bulk_delete,
|
|
121
|
+
channel_id,
|
|
122
|
+
:post,
|
|
123
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/bulk-delete",
|
|
124
|
+
{ messages: messages }.to_json,
|
|
125
|
+
Authorization: token,
|
|
126
|
+
content_type: :json,
|
|
127
|
+
'X-Audit-Log-Reason': reason
|
|
128
|
+
)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Update a channels permission for a role or member
|
|
7
|
+
# https://discord.com/developers/docs/resources/channel#edit-channel-permissions
|
|
8
|
+
def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
|
|
9
|
+
OnyxCord::REST.request(
|
|
10
|
+
:channels_cid_permissions_oid,
|
|
11
|
+
channel_id,
|
|
12
|
+
:put,
|
|
13
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
|
|
14
|
+
{ type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
|
|
15
|
+
Authorization: token,
|
|
16
|
+
content_type: :json,
|
|
17
|
+
'X-Audit-Log-Reason': reason
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Get a channel's invite list
|
|
22
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-invites
|
|
23
|
+
def invites(token, channel_id)
|
|
24
|
+
OnyxCord::REST.request(
|
|
25
|
+
:channels_cid_invites,
|
|
26
|
+
channel_id,
|
|
27
|
+
:get,
|
|
28
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/invites",
|
|
29
|
+
Authorization: token
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Create an instant invite from a server or a channel id
|
|
34
|
+
# https://discord.com/developers/docs/resources/channel#create-channel-invite
|
|
35
|
+
def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
|
|
36
|
+
OnyxCord::REST.request(
|
|
37
|
+
:channels_cid_invites,
|
|
38
|
+
channel_id,
|
|
39
|
+
:post,
|
|
40
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/invites",
|
|
41
|
+
{ max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json,
|
|
42
|
+
Authorization: token,
|
|
43
|
+
content_type: :json,
|
|
44
|
+
'X-Audit-Log-Reason': reason
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Delete channel permission
|
|
49
|
+
# https://discord.com/developers/docs/resources/channel#delete-channel-permission
|
|
50
|
+
def delete_permission(token, channel_id, overwrite_id, reason = nil)
|
|
51
|
+
OnyxCord::REST.request(
|
|
52
|
+
:channels_cid_permissions_oid,
|
|
53
|
+
channel_id,
|
|
54
|
+
:delete,
|
|
55
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
|
|
56
|
+
Authorization: token,
|
|
57
|
+
'X-Audit-Log-Reason': reason
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Start typing (needs to be resent every 5 seconds to keep up the typing)
|
|
62
|
+
# https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
|
|
63
|
+
def start_typing(token, channel_id)
|
|
64
|
+
OnyxCord::REST.request(
|
|
65
|
+
:channels_cid_typing,
|
|
66
|
+
channel_id,
|
|
67
|
+
:post,
|
|
68
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/typing",
|
|
69
|
+
nil,
|
|
70
|
+
Authorization: token
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Get a list of pinned messages in a channel
|
|
7
|
+
# https://discord.com/developers/docs/resources/message#get-channel-pins
|
|
8
|
+
def pinned_messages(token, channel_id, limit = 50, before = nil)
|
|
9
|
+
query = URI.encode_www_form({ limit: limit, before: before }.compact)
|
|
10
|
+
OnyxCord::REST.request(
|
|
11
|
+
:channels_cid_pins,
|
|
12
|
+
channel_id,
|
|
13
|
+
:get,
|
|
14
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/pins?#{query}",
|
|
15
|
+
Authorization: token
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Pin a message
|
|
20
|
+
# https://discord.com/developers/docs/resources/message#pin-message
|
|
21
|
+
def pin_message(token, channel_id, message_id, reason = nil)
|
|
22
|
+
OnyxCord::REST.request(
|
|
23
|
+
:channels_cid_pins_mid,
|
|
24
|
+
channel_id,
|
|
25
|
+
:put,
|
|
26
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
|
|
27
|
+
nil,
|
|
28
|
+
Authorization: token,
|
|
29
|
+
'X-Audit-Log-Reason': reason
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Unpin a message
|
|
34
|
+
# https://discord.com/developers/docs/resources/message#unpin-message
|
|
35
|
+
def unpin_message(token, channel_id, message_id, reason = nil)
|
|
36
|
+
OnyxCord::REST.request(
|
|
37
|
+
:channels_cid_pins_mid,
|
|
38
|
+
channel_id,
|
|
39
|
+
:delete,
|
|
40
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
|
|
41
|
+
Authorization: token,
|
|
42
|
+
'X-Audit-Log-Reason': reason
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Get a list of users that have voted for a poll answer.
|
|
7
|
+
# https://discord.com/developers/docs/resources/poll#get-answer-voters
|
|
8
|
+
def get_poll_voters(token, channel_id, message_id, answer_id, limit: 100, after: nil)
|
|
9
|
+
query = URI.encode_www_form({ limit:, after: }.compact)
|
|
10
|
+
|
|
11
|
+
OnyxCord::REST.request(
|
|
12
|
+
:channels_cid_polls_mid_answers_aid,
|
|
13
|
+
channel_id,
|
|
14
|
+
:get,
|
|
15
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/polls/#{message_id}/answers/#{answer_id}?#{query}",
|
|
16
|
+
Authorization: token
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# End a poll created by the current user.
|
|
21
|
+
# https://discord.com/developers/docs/resources/poll#end-poll
|
|
22
|
+
def end_poll(token, channel_id, message_id)
|
|
23
|
+
OnyxCord::REST.request(
|
|
24
|
+
:channels_cid_polls_mid_expire,
|
|
25
|
+
channel_id,
|
|
26
|
+
:post,
|
|
27
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/polls/#{message_id}/expire",
|
|
28
|
+
nil,
|
|
29
|
+
Authorization: token
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Create a reaction on a message using this client
|
|
7
|
+
# https://discord.com/developers/docs/resources/channel#create-reaction
|
|
8
|
+
def create_reaction(token, channel_id, message_id, emoji)
|
|
9
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
|
10
|
+
OnyxCord::REST.request(
|
|
11
|
+
:channels_cid_messages_mid_reactions_emoji_me,
|
|
12
|
+
channel_id,
|
|
13
|
+
:put,
|
|
14
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
|
|
15
|
+
nil,
|
|
16
|
+
Authorization: token,
|
|
17
|
+
content_type: :json
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Delete this client's own reaction on a message
|
|
22
|
+
# https://discord.com/developers/docs/resources/channel#delete-own-reaction
|
|
23
|
+
def delete_own_reaction(token, channel_id, message_id, emoji)
|
|
24
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
|
25
|
+
OnyxCord::REST.request(
|
|
26
|
+
:channels_cid_messages_mid_reactions_emoji_me,
|
|
27
|
+
channel_id,
|
|
28
|
+
:delete,
|
|
29
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
|
|
30
|
+
Authorization: token
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Delete another client's reaction on a message
|
|
35
|
+
# https://discord.com/developers/docs/resources/channel#delete-user-reaction
|
|
36
|
+
def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
|
|
37
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
|
38
|
+
OnyxCord::REST.request(
|
|
39
|
+
:channels_cid_messages_mid_reactions_emoji_uid,
|
|
40
|
+
channel_id,
|
|
41
|
+
:delete,
|
|
42
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}",
|
|
43
|
+
Authorization: token
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Get a list of clients who reacted with a specific reaction on a message
|
|
48
|
+
# https://discord.com/developers/docs/resources/channel#get-reactions
|
|
49
|
+
def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100, type = 0)
|
|
50
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
|
51
|
+
query_string = URI.encode_www_form({ limit: limit || 100, before: before_id, after: after_id, type: type }.compact)
|
|
52
|
+
OnyxCord::REST.request(
|
|
53
|
+
:channels_cid_messages_mid_reactions_emoji,
|
|
54
|
+
channel_id,
|
|
55
|
+
:get,
|
|
56
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
|
|
57
|
+
Authorization: token
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Deletes all reactions on a message from all clients
|
|
62
|
+
# https://discord.com/developers/docs/resources/channel#delete-all-reactions
|
|
63
|
+
def delete_all_reactions(token, channel_id, message_id)
|
|
64
|
+
OnyxCord::REST.request(
|
|
65
|
+
:channels_cid_messages_mid_reactions,
|
|
66
|
+
channel_id,
|
|
67
|
+
:delete,
|
|
68
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions",
|
|
69
|
+
Authorization: token
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Deletes all the reactions for a given emoji on a message
|
|
74
|
+
# https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji
|
|
75
|
+
def delete_all_emoji_reactions(token, channel_id, message_id, emoji)
|
|
76
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
|
77
|
+
|
|
78
|
+
OnyxCord::REST.request(
|
|
79
|
+
:channels_cid_messages_mid_reactions_emoji,
|
|
80
|
+
channel_id,
|
|
81
|
+
:delete,
|
|
82
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
|
|
83
|
+
Authorization: token
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Start a thread based off a channel message.
|
|
7
|
+
# https://discord.com/developers/docs/resources/channel#start-thread-with-message
|
|
8
|
+
def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
|
|
9
|
+
OnyxCord::REST.request(
|
|
10
|
+
:channels_cid_messages_mid_threads,
|
|
11
|
+
channel_id,
|
|
12
|
+
:post,
|
|
13
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
|
|
14
|
+
{ name: name, auto_archive_duration: auto_archive_duration }.to_json,
|
|
15
|
+
Authorization: token,
|
|
16
|
+
content_type: :json
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Start a thread without an associated message.
|
|
21
|
+
# https://discord.com/developers/docs/resources/channel#start-thread-without-message
|
|
22
|
+
def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
|
|
23
|
+
OnyxCord::REST.request(
|
|
24
|
+
:channels_cid_threads,
|
|
25
|
+
channel_id,
|
|
26
|
+
:post,
|
|
27
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads",
|
|
28
|
+
{ name: name, auto_archive_duration: auto_archive_duration, type: type },
|
|
29
|
+
Authorization: token,
|
|
30
|
+
content_type: :json
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Add the current user to a thread.
|
|
35
|
+
# https://discord.com/developers/docs/resources/channel#join-thread
|
|
36
|
+
def join_thread(token, channel_id)
|
|
37
|
+
OnyxCord::REST.request(
|
|
38
|
+
:channels_cid_thread_members_me,
|
|
39
|
+
channel_id,
|
|
40
|
+
:put,
|
|
41
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/@me",
|
|
42
|
+
nil,
|
|
43
|
+
Authorization: token
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Add a user to a thread.
|
|
48
|
+
# https://discord.com/developers/docs/resources/channel#add-thread-member
|
|
49
|
+
def add_thread_member(token, channel_id, user_id)
|
|
50
|
+
OnyxCord::REST.request(
|
|
51
|
+
:channels_cid_thread_members_uid,
|
|
52
|
+
channel_id,
|
|
53
|
+
:put,
|
|
54
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
|
55
|
+
nil,
|
|
56
|
+
Authorization: token
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Remove the current user from a thread.
|
|
61
|
+
# https://discord.com/developers/docs/resources/channel#leave-thread
|
|
62
|
+
def leave_thread(token, channel_id)
|
|
63
|
+
OnyxCord::REST.request(
|
|
64
|
+
:channels_cid_thread_members_me,
|
|
65
|
+
channel_id,
|
|
66
|
+
:delete,
|
|
67
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
|
68
|
+
Authorization: token
|
|
69
|
+
)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Remove a user from a thread.
|
|
73
|
+
# https://discord.com/developers/docs/resources/channel#remove-thread-member
|
|
74
|
+
def remove_thread_member(token, channel_id, user_id)
|
|
75
|
+
OnyxCord::REST.request(
|
|
76
|
+
:channels_cid_thread_members_uid,
|
|
77
|
+
channel_id,
|
|
78
|
+
:delete,
|
|
79
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
|
80
|
+
Authorization: token
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Get the members of a thread.
|
|
85
|
+
# https://discord.com/developers/docs/resources/channel#list-thread-members
|
|
86
|
+
def list_thread_members(token, channel_id, before, limit)
|
|
87
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
|
88
|
+
|
|
89
|
+
OnyxCord::REST.request(
|
|
90
|
+
:channels_cid_thread_members,
|
|
91
|
+
channel_id,
|
|
92
|
+
:get,
|
|
93
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/thread-members?#{query}",
|
|
94
|
+
Authorization: token
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# List active threads
|
|
99
|
+
# https://discord.com/developers/docs/resources/channel#list-active-threads
|
|
100
|
+
def list_active_threads(token, channel_id)
|
|
101
|
+
OnyxCord::REST.request(
|
|
102
|
+
:channels_cid_threads_active,
|
|
103
|
+
channel_id,
|
|
104
|
+
:get,
|
|
105
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/active",
|
|
106
|
+
Authorization: token
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# List public archived threads.
|
|
111
|
+
# https://discord.com/developers/docs/resources/channel#list-public-archived-threads
|
|
112
|
+
def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
|
|
113
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
|
114
|
+
|
|
115
|
+
OnyxCord::REST.request(
|
|
116
|
+
:channels_cid_threads_archived_public,
|
|
117
|
+
channel_id,
|
|
118
|
+
:get,
|
|
119
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
|
|
120
|
+
Authorization: token
|
|
121
|
+
)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# List private archived threads.
|
|
125
|
+
# https://discord.com/developers/docs/resources/channel#list-private-archived-threads
|
|
126
|
+
def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
|
|
127
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
|
128
|
+
|
|
129
|
+
OnyxCord::REST.request(
|
|
130
|
+
:channels_cid_threads_archived_private,
|
|
131
|
+
channel_id,
|
|
132
|
+
:get,
|
|
133
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
|
|
134
|
+
Authorization: token
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# List joined private archived threads.
|
|
139
|
+
# https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads
|
|
140
|
+
def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
|
|
141
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
|
142
|
+
|
|
143
|
+
OnyxCord::REST.request(
|
|
144
|
+
:channels_cid_users_me_threads_archived_private,
|
|
145
|
+
channel_id,
|
|
146
|
+
:get,
|
|
147
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
|
|
148
|
+
Authorization: token
|
|
149
|
+
)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Start a thread in a forum or media channel.
|
|
153
|
+
# https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
|
|
154
|
+
def start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = nil, reason = nil)
|
|
155
|
+
OnyxCord::MessagePayload.validate!(attachments: attachments)
|
|
156
|
+
body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact
|
|
157
|
+
|
|
158
|
+
body = if attachments
|
|
159
|
+
multipart_body(body, attachments)
|
|
160
|
+
else
|
|
161
|
+
body.to_json
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
headers = { Authorization: token, 'X-Audit-Log-Reason': reason }
|
|
165
|
+
headers[:content_type] = :json unless attachments
|
|
166
|
+
|
|
167
|
+
OnyxCord::REST.request(
|
|
168
|
+
:channels_cid_threads,
|
|
169
|
+
channel_id,
|
|
170
|
+
:post,
|
|
171
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/threads",
|
|
172
|
+
body,
|
|
173
|
+
headers
|
|
174
|
+
)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord::REST::Channel
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Create a webhook
|
|
7
|
+
# https://discord.com/developers/docs/resources/webhook#create-webhook
|
|
8
|
+
def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
|
|
9
|
+
OnyxCord::REST.request(
|
|
10
|
+
:channels_cid_webhooks,
|
|
11
|
+
channel_id,
|
|
12
|
+
:post,
|
|
13
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/webhooks",
|
|
14
|
+
{ name: name, avatar: avatar }.to_json,
|
|
15
|
+
Authorization: token,
|
|
16
|
+
content_type: :json,
|
|
17
|
+
'X-Audit-Log-Reason': reason
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Get channel webhooks
|
|
22
|
+
# https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
|
|
23
|
+
def webhooks(token, channel_id)
|
|
24
|
+
OnyxCord::REST.request(
|
|
25
|
+
:channels_cid_webhooks,
|
|
26
|
+
channel_id,
|
|
27
|
+
:get,
|
|
28
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/webhooks",
|
|
29
|
+
Authorization: token
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Follow an annoucement channel.
|
|
34
|
+
# https://discord.com/developers/docs/resources/channel#follow-announcement-channel
|
|
35
|
+
def follow_channel(token, channel_id, webhook_channel_id, reason = nil)
|
|
36
|
+
OnyxCord::REST.request(
|
|
37
|
+
:channels_cid_followers,
|
|
38
|
+
channel_id,
|
|
39
|
+
:post,
|
|
40
|
+
"#{OnyxCord::REST.api_base}/channels/#{channel_id}/followers",
|
|
41
|
+
{ webhook_channel_id: webhook_channel_id }.to_json,
|
|
42
|
+
Authorization: token,
|
|
43
|
+
content_type: :json,
|
|
44
|
+
'X-Audit-Log-Reason': reason
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'onyxcord/internal/message_payload'
|
|
4
|
+
require 'onyxcord/rest/routes/channel/base'
|
|
5
|
+
require 'onyxcord/rest/routes/channel/messages'
|
|
6
|
+
require 'onyxcord/rest/routes/channel/reactions'
|
|
7
|
+
require 'onyxcord/rest/routes/channel/permissions'
|
|
8
|
+
require 'onyxcord/rest/routes/channel/pins'
|
|
9
|
+
require 'onyxcord/rest/routes/channel/groups'
|
|
10
|
+
require 'onyxcord/rest/routes/channel/webhooks'
|
|
11
|
+
require 'onyxcord/rest/routes/channel/threads'
|
|
12
|
+
require 'onyxcord/rest/routes/channel/polls'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'onyxcord/message_payload'
|
|
3
|
+
require 'onyxcord/internal/message_payload'
|
|
4
4
|
|
|
5
|
-
# API calls for interactions.
|
|
6
|
-
module OnyxCord::
|
|
5
|
+
# API calls for interactions — base response methods.
|
|
6
|
+
module OnyxCord::REST::Interaction
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
9
|
# Build attachment metadata payload for multipart uploads.
|
|
@@ -33,11 +33,11 @@ module OnyxCord::API::Interaction
|
|
|
33
33
|
|
|
34
34
|
headers = { content_type: :json } unless attachments
|
|
35
35
|
|
|
36
|
-
OnyxCord::
|
|
36
|
+
OnyxCord::REST.request(
|
|
37
37
|
:interactions_iid_token_callback,
|
|
38
38
|
interaction_id,
|
|
39
39
|
:post,
|
|
40
|
-
"#{OnyxCord::
|
|
40
|
+
"#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback?with_response=#{with_response ? 'true' : 'false'}",
|
|
41
41
|
body,
|
|
42
42
|
headers
|
|
43
43
|
)
|
|
@@ -48,31 +48,13 @@ module OnyxCord::API::Interaction
|
|
|
48
48
|
def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components)
|
|
49
49
|
data = { custom_id: custom_id, title: title, components: components.to_a }.compact
|
|
50
50
|
|
|
51
|
-
OnyxCord::
|
|
51
|
+
OnyxCord::REST.request(
|
|
52
52
|
:interactions_iid_token_callback,
|
|
53
53
|
interaction_id,
|
|
54
54
|
:post,
|
|
55
|
-
"#{OnyxCord::
|
|
55
|
+
"#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
|
|
56
56
|
{ type: 9, data: data }.to_json,
|
|
57
57
|
content_type: :json
|
|
58
58
|
)
|
|
59
59
|
end
|
|
60
|
-
|
|
61
|
-
# Get the original response to an interaction.
|
|
62
|
-
# https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
|
|
63
|
-
def get_original_interaction_response(interaction_token, application_id)
|
|
64
|
-
OnyxCord::API::Webhook.token_get_message(interaction_token, application_id, '@original')
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Edit the original response to an interaction.
|
|
68
|
-
# https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
|
|
69
|
-
def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil)
|
|
70
|
-
OnyxCord::API::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments, flags, poll)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Delete the original response to an interaction.
|
|
74
|
-
# https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
|
|
75
|
-
def delete_original_interaction_response(interaction_token, application_id)
|
|
76
|
-
OnyxCord::API::Webhook.token_delete_message(interaction_token, application_id, '@original')
|
|
77
|
-
end
|
|
78
60
|
end
|