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.
- 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/{errors.rb → core/errors.rb} +18 -3
- 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/internal/message_payload.rb +78 -0
- 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/upload.rb +39 -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 +22 -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 +13 -11
- data/lib/onyxcord/models.rb +57 -0
- data/lib/onyxcord/{api.rb → rest/client.rb} +83 -27
- 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} +10 -33
- 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 +30 -32
- data/lib/onyxcord/{allowed_mentions.rb → utils/allowed_mentions.rb} +9 -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 -40
- metadata +208 -91
- 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 -202
- 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 -705
- 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 -1143
- data/lib/onyxcord/data.rb +0 -57
- data/lib/onyxcord/event_executor.rb +0 -153
- data/lib/onyxcord/gateway.rb +0 -500
- data/lib/onyxcord/http.rb +0 -115
- data/lib/onyxcord/json.rb +0 -49
- data/lib/onyxcord/rate_limiter/async_rest.rb +0 -149
- 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/{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,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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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/
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
47
|
+
REST.server_tag_badge_url(@server_id, @badge_id, format)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# Comparison based off of server ID.
|