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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8bfaa918dc2547c727fdfb9efb1bc4515448dfc0462fa08def060b249b3b8eb7
|
|
4
|
+
data.tar.gz: 182ba7a3c195c8d57db22ca1faf6e65260ad93450912342a8d65891c031ae1c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aaf98711f9cb28e4c0c15769e95c13cb834c9cb3bb8c25cb10219e3f524c9f7e7db04562ff8663628e467e4cbd60a431930ad96e5a70505753170ceec2872cbc
|
|
7
|
+
data.tar.gz: 5d9fa5dd930a3918e1cf8770cea07cbbeee77002edb1116277582e3d0c3292b9a561bfa87c1d240b10662b625100eb8b6fd7f7e5d421a1ec4a40b5d2df376621
|
|
@@ -1,102 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'onyxcord/interactions/internal/application_command'
|
|
4
|
+
|
|
3
5
|
module OnyxCord
|
|
4
6
|
module ApplicationCommands
|
|
5
|
-
|
|
6
|
-
attr_reader :name, :description, :type, :attributes, :options, :block
|
|
7
|
-
|
|
8
|
-
TYPES = {
|
|
9
|
-
chat_input: 1,
|
|
10
|
-
user: 2,
|
|
11
|
-
message: 3
|
|
12
|
-
}.freeze
|
|
13
|
-
|
|
14
|
-
def self.chat_input(name, description:, **attributes, &block)
|
|
15
|
-
new(name, description: description, type: :chat_input, **attributes, &block)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def self.user(name, **attributes, &block)
|
|
19
|
-
new(name, description: '', type: :user, **attributes, &block)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def self.message(name, **attributes, &block)
|
|
23
|
-
new(name, description: '', type: :message, **attributes, &block)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def initialize(name, description: '', type: :chat_input, **attributes, &block)
|
|
27
|
-
@name = name.to_s
|
|
28
|
-
@description = description
|
|
29
|
-
@type = type
|
|
30
|
-
@attributes = attributes
|
|
31
|
-
@options = []
|
|
32
|
-
@block = block
|
|
33
|
-
@executor = nil
|
|
34
|
-
@default_member_permissions = attributes[:default_member_permissions]
|
|
35
|
-
@nsfw = attributes[:nsfw]
|
|
36
|
-
@contexts = attributes[:contexts]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def parse(&block)
|
|
40
|
-
instance_eval(&block) if block
|
|
41
|
-
self
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def execute(&block)
|
|
45
|
-
@executor = block
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def call(context)
|
|
49
|
-
return unless @executor
|
|
50
|
-
|
|
51
|
-
@executor.call(context)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def to_h
|
|
55
|
-
data = {
|
|
56
|
-
name: @name,
|
|
57
|
-
type: TYPES[@type] || @type
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
data[:description] = @description if @type == :chat_input
|
|
61
|
-
data[:options] = @options.map(&:to_h) unless @options.empty?
|
|
62
|
-
data[:default_member_permissions] = @default_member_permissions if @default_member_permissions
|
|
63
|
-
data[:nsfw] = @nsfw if @nsfw
|
|
64
|
-
data[:contexts] = @contexts if @contexts
|
|
65
|
-
|
|
66
|
-
data
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
Option::OPTION_METHODS.each do |method_name, option_type|
|
|
70
|
-
define_method(method_name) do |name, description = '', **attrs, &blk|
|
|
71
|
-
opt = Option.new(name, description, option_type, **attrs, &blk)
|
|
72
|
-
@options << opt
|
|
73
|
-
opt
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def subcommand(name, description, &block)
|
|
78
|
-
sub = Option.new(name, description, :subcommand, &block)
|
|
79
|
-
@options << sub
|
|
80
|
-
sub
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def subcommand_group(name, description, &block)
|
|
84
|
-
group = Option.new(name, description, :subcommand_group, &block)
|
|
85
|
-
@options << group
|
|
86
|
-
group
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def method_missing(method_name, *args, **kwargs, &block)
|
|
90
|
-
if @block && @block.arity.positive?
|
|
91
|
-
@block.call(Context::Proxy.new(self, method_name, args, kwargs, block))
|
|
92
|
-
else
|
|
93
|
-
super
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
98
|
-
true
|
|
99
|
-
end
|
|
100
|
-
end
|
|
7
|
+
Command = Interactions::Command
|
|
101
8
|
end
|
|
102
|
-
end
|
|
9
|
+
end
|
|
@@ -1,99 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'onyxcord/interactions/context'
|
|
4
|
+
|
|
3
5
|
module OnyxCord
|
|
4
6
|
module ApplicationCommands
|
|
5
|
-
|
|
6
|
-
attr_reader :event, :command
|
|
7
|
-
|
|
8
|
-
def initialize(event, command)
|
|
9
|
-
@event = event
|
|
10
|
-
@command = command
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def bot
|
|
14
|
-
event.bot
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def user
|
|
18
|
-
event.user
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def member
|
|
22
|
-
event.user
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def guild
|
|
26
|
-
event.server
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def guild_id
|
|
30
|
-
event.server_id
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def channel
|
|
34
|
-
event.channel
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def channel_id
|
|
38
|
-
event.channel_id
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def server
|
|
42
|
-
event.server
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def server_id
|
|
46
|
-
event.server_id
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def options
|
|
50
|
-
return {} unless event.data
|
|
51
|
-
|
|
52
|
-
if event.data['options']
|
|
53
|
-
result = {}
|
|
54
|
-
event.data['options'].each do |opt|
|
|
55
|
-
key = opt['name'].to_sym
|
|
56
|
-
result[key] = opt['value']
|
|
57
|
-
end
|
|
58
|
-
result
|
|
59
|
-
else
|
|
60
|
-
{}
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def respond(...)
|
|
65
|
-
event.respond(...)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def defer(...)
|
|
69
|
-
event.defer(...)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def edit_original(...)
|
|
73
|
-
event.edit_response(...)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def delete_original
|
|
77
|
-
event.delete_response
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def followup(...)
|
|
81
|
-
event.send_message(...)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
class Proxy
|
|
85
|
-
def initialize(command, method_name, args, kwargs, block)
|
|
86
|
-
@command = command
|
|
87
|
-
@method_name = method_name
|
|
88
|
-
@args = args
|
|
89
|
-
@kwargs = kwargs
|
|
90
|
-
@block = block
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def to_h
|
|
94
|
-
{}
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
7
|
+
Context = Interactions::Context
|
|
98
8
|
end
|
|
99
|
-
end
|
|
9
|
+
end
|
|
@@ -1,80 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'onyxcord/interactions/option'
|
|
4
|
+
|
|
3
5
|
module OnyxCord
|
|
4
6
|
module ApplicationCommands
|
|
5
|
-
|
|
6
|
-
attr_reader :name, :description, :type, :attributes, :options
|
|
7
|
-
|
|
8
|
-
OPTION_TYPES = {
|
|
9
|
-
subcommand: 1,
|
|
10
|
-
subcommand_group: 2,
|
|
11
|
-
string: 3,
|
|
12
|
-
integer: 4,
|
|
13
|
-
boolean: 5,
|
|
14
|
-
user: 6,
|
|
15
|
-
channel: 7,
|
|
16
|
-
role: 8,
|
|
17
|
-
mentionable: 9,
|
|
18
|
-
number: 10,
|
|
19
|
-
attachment: 11
|
|
20
|
-
}.freeze
|
|
21
|
-
|
|
22
|
-
OPTION_METHODS = OPTION_TYPES.each_with_object({}) do |(name, value), hash|
|
|
23
|
-
next if %i[subcommand subcommand_group].include?(name)
|
|
24
|
-
|
|
25
|
-
hash[name] = value
|
|
26
|
-
end.freeze
|
|
27
|
-
|
|
28
|
-
def initialize(name, description, type, **attributes, &block)
|
|
29
|
-
@name = name.to_s
|
|
30
|
-
@description = description
|
|
31
|
-
@type = type
|
|
32
|
-
@attributes = attributes
|
|
33
|
-
@options = []
|
|
34
|
-
@block = block
|
|
35
|
-
|
|
36
|
-
instance_eval(&@block) if @block && type == :subcommand
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_h
|
|
40
|
-
data = {
|
|
41
|
-
name: @name,
|
|
42
|
-
description: @description,
|
|
43
|
-
type: OPTION_TYPES[@type] || @type
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
data[:required] = @attributes[:required] unless @attributes[:required].nil?
|
|
47
|
-
data[:min_length] = @attributes[:min_length] if @attributes[:min_length]
|
|
48
|
-
data[:max_length] = @attributes[:max_length] if @attributes[:max_length]
|
|
49
|
-
data[:min_value] = @attributes[:min_value] if @attributes[:min_value]
|
|
50
|
-
data[:max_value] = @attributes[:max_value] if @attributes[:max_value]
|
|
51
|
-
data[:autocomplete] = @attributes[:autocomplete] unless @attributes[:autocomplete].nil?
|
|
52
|
-
data[:channel_types] = @attributes[:channel_types] if @attributes[:channel_types]
|
|
53
|
-
|
|
54
|
-
if @attributes[:choices]
|
|
55
|
-
data[:choices] = @attributes[:choices].map do |name, value|
|
|
56
|
-
{ name: name.to_s, value: value }
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
data[:options] = @options.map(&:to_h) unless @options.empty?
|
|
61
|
-
|
|
62
|
-
data
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def subcommand(name, description, **attrs, &block)
|
|
66
|
-
sub = Option.new(name, description, :subcommand, **attrs, &block)
|
|
67
|
-
@options << sub
|
|
68
|
-
sub
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
OPTION_METHODS.each do |method_name, option_type|
|
|
72
|
-
define_method(method_name) do |name, description = '', **attrs, &blk|
|
|
73
|
-
opt = Option.new(name, description, option_type, **attrs, &blk)
|
|
74
|
-
@options << opt
|
|
75
|
-
opt
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
7
|
+
Option = Interactions::Option
|
|
79
8
|
end
|
|
80
|
-
end
|
|
9
|
+
end
|
|
@@ -1,50 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'onyxcord/interactions/registry'
|
|
4
|
+
|
|
3
5
|
module OnyxCord
|
|
4
6
|
module ApplicationCommands
|
|
5
|
-
|
|
6
|
-
attr_reader :bot, :commands
|
|
7
|
-
|
|
8
|
-
def initialize(bot)
|
|
9
|
-
@bot = bot
|
|
10
|
-
@commands = {}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def slash(name, description:, **attributes, &block)
|
|
14
|
-
register(Command.chat_input(name, description: description, **attributes, &block))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def user(name, **attributes, &block)
|
|
18
|
-
register(Command.user(name, **attributes, &block))
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def message(name, **attributes, &block)
|
|
22
|
-
register(Command.message(name, **attributes, &block))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def register(command)
|
|
26
|
-
@commands[command.name] = command
|
|
27
|
-
wire_handler(command)
|
|
28
|
-
command
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def sync!(server_id: nil, delete_unknown: false)
|
|
32
|
-
payload = @commands.values.map(&:to_h)
|
|
33
|
-
|
|
34
|
-
if server_id
|
|
35
|
-
@bot.bulk_overwrite_guild_application_commands(server_id, payload)
|
|
36
|
-
else
|
|
37
|
-
@bot.bulk_overwrite_global_application_commands(payload)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
def wire_handler(command)
|
|
44
|
-
@bot.application_command(command.name) do |event|
|
|
45
|
-
command.call(Context.new(event, command))
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
7
|
+
Registry = Interactions::Registry
|
|
49
8
|
end
|
|
50
|
-
end
|
|
9
|
+
end
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'onyxcord/
|
|
4
|
-
require 'onyxcord/application_commands/command'
|
|
5
|
-
require 'onyxcord/application_commands/context'
|
|
6
|
-
require 'onyxcord/application_commands/registry'
|
|
3
|
+
require 'onyxcord/interactions'
|
|
7
4
|
|
|
8
5
|
module OnyxCord
|
|
9
6
|
module ApplicationCommands
|
|
7
|
+
Command = Interactions::Command
|
|
8
|
+
Option = Interactions::Option
|
|
9
|
+
Context = Interactions::Context
|
|
10
|
+
Registry = Interactions::Registry
|
|
11
|
+
OptionBuilder = Interactions::OptionBuilder
|
|
12
|
+
PermissionBuilder = Interactions::PermissionBuilder
|
|
10
13
|
end
|
|
11
|
-
end
|
|
14
|
+
end
|