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,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord
|
|
4
|
+
module Interactions
|
|
5
|
+
# Builder for creating server application command permissions.
|
|
6
|
+
# @deprecated This system is being replaced in the near future.
|
|
7
|
+
class PermissionBuilder
|
|
8
|
+
# Role permission type
|
|
9
|
+
ROLE = 1
|
|
10
|
+
# User permission type
|
|
11
|
+
USER = 2
|
|
12
|
+
|
|
13
|
+
# @!visibility hidden
|
|
14
|
+
def initialize
|
|
15
|
+
@permissions = []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Allow a role to use this command.
|
|
19
|
+
# @param role_id [Integer]
|
|
20
|
+
# @return [PermissionBuilder]
|
|
21
|
+
def allow_role(role_id)
|
|
22
|
+
create_entry(role_id, ROLE, true)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Deny a role usage of this command.
|
|
26
|
+
# @param role_id [Integer]
|
|
27
|
+
# @return [PermissionBuilder]
|
|
28
|
+
def deny_role(role_id)
|
|
29
|
+
create_entry(role_id, ROLE, false)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Allow a user to use this command.
|
|
33
|
+
# @param user_id [Integer]
|
|
34
|
+
# @return [PermissionBuilder]
|
|
35
|
+
def allow_user(user_id)
|
|
36
|
+
create_entry(user_id, USER, true)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Deny a user usage of this command.
|
|
40
|
+
# @param user_id [Integer]
|
|
41
|
+
# @return [PermissionBuilder]
|
|
42
|
+
def deny_user(user_id)
|
|
43
|
+
create_entry(user_id, USER, false)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Allow an entity to use this command.
|
|
47
|
+
# @param object [Role, User, Member]
|
|
48
|
+
# @return [PermissionBuilder]
|
|
49
|
+
# @raise [ArgumentError]
|
|
50
|
+
def allow(object)
|
|
51
|
+
case object
|
|
52
|
+
when OnyxCord::User, OnyxCord::Member
|
|
53
|
+
create_entry(object.id, USER, true)
|
|
54
|
+
when OnyxCord::Role
|
|
55
|
+
create_entry(object.id, ROLE, true)
|
|
56
|
+
else
|
|
57
|
+
raise ArgumentError, "Unable to create permission for unknown type: #{object.class}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Deny an entity usage of this command.
|
|
62
|
+
# @param object [Role, User, Member]
|
|
63
|
+
# @return [PermissionBuilder]
|
|
64
|
+
# @raise [ArgumentError]
|
|
65
|
+
def deny(object)
|
|
66
|
+
case object
|
|
67
|
+
when OnyxCord::User, OnyxCord::Member
|
|
68
|
+
create_entry(object.id, USER, false)
|
|
69
|
+
when OnyxCord::Role
|
|
70
|
+
create_entry(object.id, ROLE, false)
|
|
71
|
+
else
|
|
72
|
+
raise ArgumentError, "Unable to create permission for unknown type: #{object.class}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @!visibility private
|
|
77
|
+
# @return [Array<Hash>]
|
|
78
|
+
def to_a
|
|
79
|
+
@permissions
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def create_entry(id, type, permission)
|
|
85
|
+
@permissions << { id: id, type: type, permission: permission }
|
|
86
|
+
self
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord
|
|
4
|
+
module Interactions
|
|
5
|
+
class Option
|
|
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
|
+
SKIP_OPTION_TYPES = %i[subcommand subcommand_group].freeze
|
|
23
|
+
|
|
24
|
+
OPTION_METHODS = OPTION_TYPES.each_with_object({}) do |(name, value), hash|
|
|
25
|
+
next if SKIP_OPTION_TYPES.include?(name)
|
|
26
|
+
|
|
27
|
+
hash[name] = value
|
|
28
|
+
end.freeze
|
|
29
|
+
|
|
30
|
+
def initialize(name, description, type, **attributes, &block)
|
|
31
|
+
@name = name.to_s
|
|
32
|
+
@description = description
|
|
33
|
+
@type = type
|
|
34
|
+
@attributes = attributes
|
|
35
|
+
@options = []
|
|
36
|
+
@block = block
|
|
37
|
+
|
|
38
|
+
instance_eval(&@block) if @block && type == :subcommand
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_h
|
|
42
|
+
data = {
|
|
43
|
+
name: @name,
|
|
44
|
+
description: @description,
|
|
45
|
+
type: OPTION_TYPES[@type] || @type
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
data[:name_localizations] = @attributes[:name_localizations] if @attributes[:name_localizations]
|
|
49
|
+
data[:description_localizations] = @attributes[:description_localizations] if @attributes[:description_localizations]
|
|
50
|
+
data[:required] = @attributes[:required] unless @attributes[:required].nil?
|
|
51
|
+
data[:min_length] = @attributes[:min_length] if @attributes[:min_length]
|
|
52
|
+
data[:max_length] = @attributes[:max_length] if @attributes[:max_length]
|
|
53
|
+
data[:min_value] = @attributes[:min_value] if @attributes[:min_value]
|
|
54
|
+
data[:max_value] = @attributes[:max_value] if @attributes[:max_value]
|
|
55
|
+
data[:autocomplete] = @attributes[:autocomplete] unless @attributes[:autocomplete].nil?
|
|
56
|
+
data[:channel_types] = @attributes[:channel_types] if @attributes[:channel_types]
|
|
57
|
+
|
|
58
|
+
if @attributes[:choices]
|
|
59
|
+
choice_localizations = @attributes[:choice_localizations] || {}
|
|
60
|
+
data[:choices] = @attributes[:choices].map do |choice_name, value|
|
|
61
|
+
choice = { name: choice_name.to_s, value: value }
|
|
62
|
+
locs = choice_localizations[choice_name] || choice_localizations[choice_name.to_s]
|
|
63
|
+
choice[:name_localizations] = locs if locs
|
|
64
|
+
choice
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
data[:options] = @options.map(&:to_h) unless @options.empty?
|
|
69
|
+
|
|
70
|
+
data
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def subcommand(name, description, **attrs, &block)
|
|
74
|
+
sub = Option.new(name, description, :subcommand, **attrs, &block)
|
|
75
|
+
@options << sub
|
|
76
|
+
sub
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
OPTION_METHODS.each do |method_name, option_type|
|
|
80
|
+
define_method(method_name) do |name, description = '', **attrs, &blk|
|
|
81
|
+
opt = Option.new(name, description, option_type, **attrs, &blk)
|
|
82
|
+
@options << opt
|
|
83
|
+
opt
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OnyxCord
|
|
4
|
+
module Interactions
|
|
5
|
+
class Registry
|
|
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) # rubocop:disable Lint/UnusedMethodArgument
|
|
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
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'onyxcord/interactions/option'
|
|
4
|
+
require 'onyxcord/interactions/command'
|
|
5
|
+
require 'onyxcord/interactions/context'
|
|
6
|
+
require 'onyxcord/interactions/registry'
|
|
7
|
+
require 'onyxcord/interactions/internal/application_command'
|
|
8
|
+
require 'onyxcord/interactions/internal/option_builder'
|
|
9
|
+
require 'onyxcord/interactions/internal/permission_builder'
|
|
10
|
+
require 'onyxcord/interactions/internal/message'
|
|
11
|
+
require 'onyxcord/interactions/internal/metadata'
|
|
12
|
+
|
|
13
|
+
module OnyxCord
|
|
14
|
+
module Interactions
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'async'
|
|
4
|
+
|
|
5
|
+
module OnyxCord
|
|
6
|
+
module Internal
|
|
7
|
+
module AsyncRuntime
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def run(&block)
|
|
11
|
+
current = Async::Task.current?
|
|
12
|
+
return yield current if current
|
|
13
|
+
|
|
14
|
+
Sync(&block)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def async(&block)
|
|
18
|
+
current = Async::Task.current?
|
|
19
|
+
return current.async(&block) if current
|
|
20
|
+
|
|
21
|
+
Async(&block)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def sleep(duration)
|
|
25
|
+
task = Async::Task.current?
|
|
26
|
+
return task.sleep(duration) if task.respond_to?(:sleep)
|
|
27
|
+
|
|
28
|
+
Kernel.sleep(duration)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|