@deffa5556/bail 1.0.6 → 1.0.7
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.
- package/cjs/WAProto/index.cjs +106053 -0
- package/cjs/deffa/config.cjs +14 -0
- package/cjs/deffa/plugins/ai/deepseekr1.cjs +35 -0
- package/cjs/deffa/plugins/ai/gita.cjs +26 -0
- package/cjs/deffa/plugins/ai/glm47flash.cjs +35 -0
- package/cjs/deffa/plugins/ai/gptoss120b.cjs +35 -0
- package/cjs/deffa/plugins/ai/qwq32b.cjs +35 -0
- package/cjs/deffa/plugins/berita/antara.cjs +25 -0
- package/cjs/deffa/plugins/berita/cnbcindonesia.cjs +25 -0
- package/cjs/deffa/plugins/berita/cnn.cjs +25 -0
- package/cjs/deffa/plugins/berita/kompas.cjs +25 -0
- package/cjs/deffa/plugins/berita/liputan6.cjs +25 -0
- package/cjs/deffa/plugins/berita/merdeka.cjs +25 -0
- package/cjs/deffa/plugins/berita/sindonews.cjs +25 -0
- package/cjs/deffa/plugins/berita/tribunnews.cjs +25 -0
- package/cjs/deffa/plugins/downloader/douyin.cjs +30 -0
- package/cjs/deffa/plugins/downloader/facebook.cjs +30 -0
- package/cjs/deffa/plugins/downloader/github.cjs +35 -0
- package/cjs/deffa/plugins/downloader/lahelu.cjs +30 -0
- package/cjs/deffa/plugins/downloader/snackvideo.cjs +30 -0
- package/cjs/deffa/plugins/downloader/soundcloud.cjs +30 -0
- package/cjs/deffa/plugins/downloader/tiktok.cjs +30 -0
- package/cjs/deffa/plugins/downloader/tiktokhd.cjs +30 -0
- package/cjs/deffa/plugins/downloader/twitter.cjs +30 -0
- package/cjs/deffa/plugins/downloader/ummy.cjs +36 -0
- package/cjs/deffa/plugins/index.cjs +213 -0
- package/cjs/deffa/plugins/info/bmkg.cjs +34 -0
- package/cjs/deffa/plugins/info/cuaca.cjs +31 -0
- package/cjs/deffa/plugins/info/jadwaltv.cjs +29 -0
- package/cjs/deffa/plugins/maker/brat.cjs +45 -0
- package/cjs/deffa/plugins/maker/bratvid.cjs +52 -0
- package/cjs/deffa/plugins/search/8font.cjs +28 -0
- package/cjs/deffa/plugins/search/applemusic.cjs +28 -0
- package/cjs/deffa/plugins/search/bimg.cjs +30 -0
- package/cjs/deffa/plugins/search/brave.cjs +34 -0
- package/cjs/deffa/plugins/search/duckduckgo.cjs +28 -0
- package/cjs/deffa/plugins/search/lahelu.cjs +28 -0
- package/cjs/deffa/plugins/search/mangatoon.cjs +28 -0
- package/cjs/deffa/plugins/search/mcpedl.cjs +28 -0
- package/cjs/deffa/plugins/search/myinstants.cjs +28 -0
- package/cjs/deffa/plugins/search/otakotaku.cjs +28 -0
- package/cjs/deffa/plugins/search/pinterest.cjs +30 -0
- package/cjs/deffa/plugins/search/resep.cjs +28 -0
- package/cjs/deffa/plugins/search/seegore.cjs +30 -0
- package/cjs/deffa/plugins/search/soundcloud.cjs +28 -0
- package/cjs/deffa/plugins/search/youtube.cjs +28 -0
- package/cjs/deffa/plugins/stalk/github.cjs +38 -0
- package/cjs/deffa/plugins/stalk/pinterest.cjs +37 -0
- package/cjs/deffa/plugins/stalk/threads.cjs +34 -0
- package/cjs/deffa/plugins/stalk/tiktok.cjs +37 -0
- package/cjs/deffa/plugins/stalk/twitter.cjs +37 -0
- package/cjs/deffa/plugins/stalk/youtube.cjs +37 -0
- package/cjs/lib/Defaults/index.cjs +158 -0
- package/cjs/lib/Discord/Client.cjs +263 -0
- package/cjs/lib/Discord/Constants.cjs +1842 -0
- package/cjs/lib/Discord/connect-dc.cjs +11 -0
- package/cjs/lib/Discord/esm-bridge.cjs +136 -0
- package/cjs/lib/Discord/gateway/Dispatcher.cjs +93 -0
- package/cjs/lib/Discord/gateway/Shard.cjs +695 -0
- package/cjs/lib/Discord/gateway/ShardManager.cjs +344 -0
- package/cjs/lib/Discord/gateway/compression/base.cjs +13 -0
- package/cjs/lib/Discord/gateway/compression/config.cjs +47 -0
- package/cjs/lib/Discord/gateway/compression/pako.cjs +44 -0
- package/cjs/lib/Discord/gateway/compression/zlib-native.cjs +47 -0
- package/cjs/lib/Discord/gateway/compression/zlib-sync.cjs +31 -0
- package/cjs/lib/Discord/gateway/compression/zstd-napi.cjs +80 -0
- package/cjs/lib/Discord/gateway/compression/zstd-native.cjs +46 -0
- package/cjs/lib/Discord/gateway/events.cjs +956 -0
- package/cjs/lib/Discord/index.cjs +238 -0
- package/cjs/lib/Discord/rest/Bucket.cjs +69 -0
- package/cjs/lib/Discord/rest/DiscordHTTPError.cjs +63 -0
- package/cjs/lib/Discord/rest/DiscordRESTError.cjs +84 -0
- package/cjs/lib/Discord/rest/OAuthHelper.cjs +226 -0
- package/cjs/lib/Discord/rest/RESTManager.cjs +116 -0
- package/cjs/lib/Discord/rest/RequestHandler.cjs +320 -0
- package/cjs/lib/Discord/rest/SequentialBucket.cjs +69 -0
- package/cjs/lib/Discord/routes/Applications.cjs +625 -0
- package/cjs/lib/Discord/routes/Channels.cjs +1199 -0
- package/cjs/lib/Discord/routes/Guilds.cjs +1792 -0
- package/cjs/lib/Discord/routes/Interactions.cjs +212 -0
- package/cjs/lib/Discord/routes/Lobbies.cjs +197 -0
- package/cjs/lib/Discord/routes/Miscellaneous.cjs +120 -0
- package/cjs/lib/Discord/routes/OAuth.cjs +350 -0
- package/cjs/lib/Discord/routes/Users.cjs +107 -0
- package/cjs/lib/Discord/routes/Webhooks.cjs +308 -0
- package/cjs/lib/Discord/structures/AnnouncementChannel.cjs +46 -0
- package/cjs/lib/Discord/structures/AnnouncementThreadChannel.cjs +28 -0
- package/cjs/lib/Discord/structures/Application.cjs +345 -0
- package/cjs/lib/Discord/structures/ApplicationCommand.cjs +109 -0
- package/cjs/lib/Discord/structures/Attachment.cjs +46 -0
- package/cjs/lib/Discord/structures/AuditLogEntry.cjs +41 -0
- package/cjs/lib/Discord/structures/AutoModerationRule.cjs +117 -0
- package/cjs/lib/Discord/structures/AutocompleteInteraction.cjs +90 -0
- package/cjs/lib/Discord/structures/Base.cjs +56 -0
- package/cjs/lib/Discord/structures/BaseEntitlement.cjs +40 -0
- package/cjs/lib/Discord/structures/CategoryChannel.cjs +102 -0
- package/cjs/lib/Discord/structures/Channel.cjs +89 -0
- package/cjs/lib/Discord/structures/ClientApplication.cjs +269 -0
- package/cjs/lib/Discord/structures/CommandInteraction.cjs +294 -0
- package/cjs/lib/Discord/structures/ComponentInteraction.cjs +306 -0
- package/cjs/lib/Discord/structures/Entitlement.cjs +24 -0
- package/cjs/lib/Discord/structures/ExtendedUser.cjs +48 -0
- package/cjs/lib/Discord/structures/ForumChannel.cjs +20 -0
- package/cjs/lib/Discord/structures/GroupChannel.cjs +160 -0
- package/cjs/lib/Discord/structures/Guild.cjs +1289 -0
- package/cjs/lib/Discord/structures/GuildChannel.cjs +82 -0
- package/cjs/lib/Discord/structures/GuildPreview.cjs +141 -0
- package/cjs/lib/Discord/structures/GuildScheduledEvent.cjs +166 -0
- package/cjs/lib/Discord/structures/GuildTemplate.cjs +96 -0
- package/cjs/lib/Discord/structures/Integration.cjs +123 -0
- package/cjs/lib/Discord/structures/Interaction.cjs +78 -0
- package/cjs/lib/Discord/structures/InteractionResolvedChannel.cjs +36 -0
- package/cjs/lib/Discord/structures/Invite.cjs +196 -0
- package/cjs/lib/Discord/structures/InviteGuild.cjs +117 -0
- package/cjs/lib/Discord/structures/InviteRole.cjs +88 -0
- package/cjs/lib/Discord/structures/Lobby.cjs +84 -0
- package/cjs/lib/Discord/structures/LobbyMember.cjs +30 -0
- package/cjs/lib/Discord/structures/MediaChannel.cjs +20 -0
- package/cjs/lib/Discord/structures/Member.cjs +300 -0
- package/cjs/lib/Discord/structures/Message.cjs +553 -0
- package/cjs/lib/Discord/structures/ModalSubmitInteraction.cjs +263 -0
- package/cjs/lib/Discord/structures/OAuthApplication.cjs +203 -0
- package/cjs/lib/Discord/structures/OAuthGuild.cjs +98 -0
- package/cjs/lib/Discord/structures/PartialApplication.cjs +97 -0
- package/cjs/lib/Discord/structures/Permission.cjs +61 -0
- package/cjs/lib/Discord/structures/PermissionOverwrite.cjs +46 -0
- package/cjs/lib/Discord/structures/PingInteraction.cjs +27 -0
- package/cjs/lib/Discord/structures/Poll.cjs +69 -0
- package/cjs/lib/Discord/structures/PrimaryGuild.cjs +93 -0
- package/cjs/lib/Discord/structures/PrivateChannel.cjs +131 -0
- package/cjs/lib/Discord/structures/PrivateThreadChannel.cjs +28 -0
- package/cjs/lib/Discord/structures/PublicThreadChannel.cjs +36 -0
- package/cjs/lib/Discord/structures/Role.cjs +126 -0
- package/cjs/lib/Discord/structures/SKU.cjs +58 -0
- package/cjs/lib/Discord/structures/Soundboard.cjs +58 -0
- package/cjs/lib/Discord/structures/StageChannel.cjs +45 -0
- package/cjs/lib/Discord/structures/StageInstance.cjs +80 -0
- package/cjs/lib/Discord/structures/Subscription.cjs +21 -0
- package/cjs/lib/Discord/structures/Team.cjs +70 -0
- package/cjs/lib/Discord/structures/TestEntitlement.cjs +22 -0
- package/cjs/lib/Discord/structures/TextChannel.cjs +48 -0
- package/cjs/lib/Discord/structures/TextableChannel.cjs +265 -0
- package/cjs/lib/Discord/structures/TextableVoiceChannel.cjs +70 -0
- package/cjs/lib/Discord/structures/ThreadChannel.cjs +276 -0
- package/cjs/lib/Discord/structures/ThreadOnlyChannel.cjs +205 -0
- package/cjs/lib/Discord/structures/ThreadableChannel.cjs +57 -0
- package/cjs/lib/Discord/structures/UnavailableGuild.cjs +21 -0
- package/cjs/lib/Discord/structures/User.cjs +223 -0
- package/cjs/lib/Discord/structures/VoiceChannel.cjs +34 -0
- package/cjs/lib/Discord/structures/VoiceState.cjs +113 -0
- package/cjs/lib/Discord/structures/Webhook.cjs +224 -0
- package/cjs/lib/Discord/util/Collection.cjs +77 -0
- package/cjs/lib/Discord/util/Errors.cjs +81 -0
- package/cjs/lib/Discord/util/QueryBuilder.cjs +20 -0
- package/cjs/lib/Discord/util/Routes.cjs +293 -0
- package/cjs/lib/Discord/util/SimpleCollection.cjs +78 -0
- package/cjs/lib/Discord/util/Time.cjs +92 -0
- package/cjs/lib/Discord/util/TypedCollection.cjs +78 -0
- package/cjs/lib/Discord/util/TypedEmitter.cjs +20 -0
- package/cjs/lib/Discord/util/Util.cjs +906 -0
- package/cjs/lib/Discord/util/interactions/InteractionOptionsWrapper.cjs +207 -0
- package/cjs/lib/Discord/util/interactions/MessageInteractionResponse.cjs +26 -0
- package/cjs/lib/Discord/util/interactions/ModalSubmitInteractionComponentsWrapper.cjs +98 -0
- package/cjs/lib/Discord/util/interactions/SelectMenuValuesWrapper.cjs +77 -0
- package/cjs/lib/Discord/util/interactions/shared.cjs +20 -0
- package/cjs/lib/Discord/util/warning.cjs +34 -0
- package/cjs/lib/Signal/Group/ciphertext-message.cjs +16 -0
- package/cjs/lib/Signal/Group/group-session-builder.cjs +67 -0
- package/cjs/lib/Signal/Group/group_cipher.cjs +86 -0
- package/cjs/lib/Signal/Group/index.cjs +58 -0
- package/cjs/lib/Signal/Group/keyhelper.cjs +56 -0
- package/cjs/lib/Signal/Group/sender-chain-key.cjs +30 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.cjs +67 -0
- package/cjs/lib/Signal/Group/sender-key-message.cjs +70 -0
- package/cjs/lib/Signal/Group/sender-key-name.cjs +52 -0
- package/cjs/lib/Signal/Group/sender-key-record.cjs +45 -0
- package/cjs/lib/Signal/Group/sender-key-state.cjs +88 -0
- package/cjs/lib/Signal/Group/sender-message-key.cjs +30 -0
- package/cjs/lib/Signal/libsignal.cjs +467 -0
- package/cjs/lib/Signal/lid-mapping.cjs +281 -0
- package/cjs/lib/Socket/Client/index.cjs +19 -0
- package/cjs/lib/Socket/Client/types.cjs +15 -0
- package/cjs/lib/Socket/Client/websocket.cjs +61 -0
- package/cjs/lib/Socket/business.cjs +384 -0
- package/cjs/lib/Socket/chats.cjs +1221 -0
- package/cjs/lib/Socket/communities.cjs +440 -0
- package/cjs/lib/Socket/groups.cjs +353 -0
- package/cjs/lib/Socket/index.cjs +14 -0
- package/cjs/lib/Socket/messages-recv.cjs +1772 -0
- package/cjs/lib/Socket/messages-send.cjs +1376 -0
- package/cjs/lib/Socket/mex.cjs +46 -0
- package/cjs/lib/Socket/newsletter.cjs +230 -0
- package/cjs/lib/Socket/socket.cjs +976 -0
- package/cjs/lib/Store/index.cjs +20 -0
- package/cjs/lib/Store/make-in-memory-store.cjs +470 -0
- package/cjs/lib/Store/make-ordered-dictionary.cjs +82 -0
- package/cjs/lib/Store/object-repository.cjs +28 -0
- package/cjs/lib/Telegram/button.cjs +147 -0
- package/cjs/lib/Telegram/composer.cjs +582 -0
- package/cjs/lib/Telegram/context.cjs +853 -0
- package/cjs/lib/Telegram/core/helpers/args.cjs +57 -0
- package/cjs/lib/Telegram/core/helpers/check.cjs +55 -0
- package/cjs/lib/Telegram/core/helpers/compact.cjs +16 -0
- package/cjs/lib/Telegram/core/helpers/deunionize.cjs +12 -0
- package/cjs/lib/Telegram/core/helpers/formatting.cjs +91 -0
- package/cjs/lib/Telegram/core/helpers/util.cjs +50 -0
- package/cjs/lib/Telegram/core/network/client.cjs +338 -0
- package/cjs/lib/Telegram/core/network/error.cjs +21 -0
- package/cjs/lib/Telegram/core/network/multipart-stream.cjs +79 -0
- package/cjs/lib/Telegram/core/network/polling.cjs +87 -0
- package/cjs/lib/Telegram/core/network/webhook.cjs +54 -0
- package/cjs/lib/Telegram/core/types/typegram.cjs +31 -0
- package/cjs/lib/Telegram/deffa-telegraf.cjs +264 -0
- package/cjs/lib/Telegram/esm-bridge.cjs +20 -0
- package/cjs/lib/Telegram/filters.cjs +69 -0
- package/cjs/lib/Telegram/format.cjs +58 -0
- package/cjs/lib/Telegram/future.cjs +140 -0
- package/cjs/lib/Telegram/index.cjs +67 -0
- package/cjs/lib/Telegram/input.cjs +61 -0
- package/cjs/lib/Telegram/markup.cjs +129 -0
- package/cjs/lib/Telegram/middleware.cjs +2 -0
- package/cjs/lib/Telegram/reactions.cjs +84 -0
- package/cjs/lib/Telegram/router.cjs +46 -0
- package/cjs/lib/Telegram/scenes/base.cjs +39 -0
- package/cjs/lib/Telegram/scenes/context.cjs +104 -0
- package/cjs/lib/Telegram/scenes/index.cjs +21 -0
- package/cjs/lib/Telegram/scenes/stage.cjs +49 -0
- package/cjs/lib/Telegram/scenes/wizard/context.cjs +31 -0
- package/cjs/lib/Telegram/scenes/wizard/index.cjs +45 -0
- package/cjs/lib/Telegram/scenes.cjs +21 -0
- package/cjs/lib/Telegram/session.cjs +166 -0
- package/cjs/lib/Telegram/telegram-types.cjs +6 -0
- package/cjs/lib/Telegram/telegram.cjs +945 -0
- package/cjs/lib/Telegram/types.cjs +2 -0
- package/cjs/lib/Telegram/utils.cjs +5 -0
- package/cjs/lib/Types/Auth.cjs +3 -0
- package/cjs/lib/Types/Bussines.cjs +3 -0
- package/cjs/lib/Types/Call.cjs +3 -0
- package/cjs/lib/Types/Chat.cjs +11 -0
- package/cjs/lib/Types/Contact.cjs +3 -0
- package/cjs/lib/Types/Events.cjs +4 -0
- package/cjs/lib/Types/GroupMetadata.cjs +3 -0
- package/cjs/lib/Types/Label.cjs +26 -0
- package/cjs/lib/Types/LabelAssociation.cjs +8 -0
- package/cjs/lib/Types/Message.cjs +19 -0
- package/cjs/lib/Types/Mex.cjs +40 -0
- package/cjs/lib/Types/Product.cjs +3 -0
- package/cjs/lib/Types/RichType.cjs +24 -0
- package/cjs/lib/Types/Signal.cjs +4 -0
- package/cjs/lib/Types/Socket.cjs +4 -0
- package/cjs/lib/Types/State.cjs +54 -0
- package/cjs/lib/Types/USync.cjs +4 -0
- package/cjs/lib/Types/index.cjs +42 -0
- package/cjs/lib/Utils/auth-utils.cjs +312 -0
- package/cjs/lib/Utils/browser-utils.cjs +39 -0
- package/cjs/lib/Utils/business.cjs +241 -0
- package/cjs/lib/Utils/chat-utils.cjs +890 -0
- package/cjs/lib/Utils/companion-reg-client-utils.cjs +51 -0
- package/cjs/lib/Utils/crypto.cjs +170 -0
- package/cjs/lib/Utils/decode-wa-message.cjs +330 -0
- package/cjs/lib/Utils/event-buffer.cjs +629 -0
- package/cjs/lib/Utils/generics.cjs +427 -0
- package/cjs/lib/Utils/history.cjs +141 -0
- package/cjs/lib/Utils/identity-change-handler.cjs +56 -0
- package/cjs/lib/Utils/index.cjs +43 -0
- package/cjs/lib/Utils/link-preview.cjs +122 -0
- package/cjs/lib/Utils/logger.cjs +8 -0
- package/cjs/lib/Utils/lt-hash.cjs +11 -0
- package/cjs/lib/Utils/make-mutex.cjs +38 -0
- package/cjs/lib/Utils/message-retry-manager.cjs +267 -0
- package/cjs/lib/Utils/messages-media.cjs +906 -0
- package/cjs/lib/Utils/messages.cjs +1909 -0
- package/cjs/lib/Utils/noise-handler.cjs +205 -0
- package/cjs/lib/Utils/offline-node-processor.cjs +43 -0
- package/cjs/lib/Utils/pre-key-manager.cjs +113 -0
- package/cjs/lib/Utils/process-message.cjs +755 -0
- package/cjs/lib/Utils/reporting-utils.cjs +263 -0
- package/cjs/lib/Utils/rich-message-utils.cjs +434 -0
- package/cjs/lib/Utils/session-guard.cjs +163 -0
- package/cjs/lib/Utils/signal.cjs +214 -0
- package/cjs/lib/Utils/stanza-ack.cjs +41 -0
- package/cjs/lib/Utils/sync-action-utils.cjs +54 -0
- package/cjs/lib/Utils/tc-token-utils.cjs +174 -0
- package/cjs/lib/Utils/text-sticker.cjs +174 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.cjs +125 -0
- package/cjs/lib/Utils/use-single-file-auth-state.cjs +113 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.cjs +145 -0
- package/cjs/lib/Utils/validate-connection.cjs +210 -0
- package/cjs/lib/WABinary/constants.cjs +1470 -0
- package/cjs/lib/WABinary/decode.cjs +301 -0
- package/cjs/lib/WABinary/encode.cjs +257 -0
- package/cjs/lib/WABinary/generic-utils.cjs +240 -0
- package/cjs/lib/WABinary/index.cjs +22 -0
- package/cjs/lib/WABinary/jid-utils.cjs +114 -0
- package/cjs/lib/WABinary/types.cjs +37 -0
- package/cjs/lib/WAM/BinaryInfo.cjs +14 -0
- package/cjs/lib/WAM/constants.cjs +22856 -0
- package/cjs/lib/WAM/encode.cjs +154 -0
- package/cjs/lib/WAM/index.cjs +20 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.cjs +56 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.cjs +58 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.cjs +31 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.cjs +42 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.cjs +29 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.cjs +55 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.cjs +33 -0
- package/cjs/lib/WAUSync/Protocols/index.cjs +22 -0
- package/cjs/lib/WAUSync/USyncQuery.cjs +102 -0
- package/cjs/lib/WAUSync/USyncUser.cjs +35 -0
- package/cjs/lib/WAUSync/index.cjs +20 -0
- package/cjs/lib/index.cjs +372 -0
- package/cjs/lib/plugins/loader.cjs +117 -0
- package/lib/Defaults/index.js +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined)
|
|
4
|
+
k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function () { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function (o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined)
|
|
12
|
+
k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function (o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function (o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o)
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(o, k))
|
|
26
|
+
ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule)
|
|
33
|
+
return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null)
|
|
36
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
37
|
+
if (k[i] !== "default")
|
|
38
|
+
__createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
44
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
const OAuthApplication_1 = __importDefault(require("../structures/OAuthApplication"));
|
|
48
|
+
const Routes = __importStar(require("../util/Routes"));
|
|
49
|
+
const PartialApplication_1 = __importDefault(require("../structures/PartialApplication"));
|
|
50
|
+
const Integration_1 = __importDefault(require("../structures/Integration"));
|
|
51
|
+
const Member_1 = __importDefault(require("../structures/Member"));
|
|
52
|
+
const OAuthGuild_1 = __importDefault(require("../structures/OAuthGuild"));
|
|
53
|
+
const ExtendedUser_1 = __importDefault(require("../structures/ExtendedUser"));
|
|
54
|
+
const Constants_1 = require("../Constants");
|
|
55
|
+
/** A helper to make using authenticated oauth requests without needing a new client instance. */
|
|
56
|
+
class OAuthHelper {
|
|
57
|
+
constructor(manager, token) {
|
|
58
|
+
this._token = token;
|
|
59
|
+
this._manager = manager;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Construct an oauth authorization url.
|
|
63
|
+
* @param options The options to construct the url with.
|
|
64
|
+
*/
|
|
65
|
+
static constructURL(options) {
|
|
66
|
+
const params = [
|
|
67
|
+
`client_id=${options.clientID}`,
|
|
68
|
+
`response_type=${options.responseType ?? "code"}`,
|
|
69
|
+
`scope=${options.scopes.join("%20")}`
|
|
70
|
+
];
|
|
71
|
+
if (options.redirectURI) {
|
|
72
|
+
params.push(`redirect_uri=${options.redirectURI}`);
|
|
73
|
+
}
|
|
74
|
+
if (options.disableGuildSelect !== undefined) {
|
|
75
|
+
params.push(`disable_guild_select=${String(options.disableGuildSelect)}`);
|
|
76
|
+
}
|
|
77
|
+
if (options.prompt) {
|
|
78
|
+
params.push(`prompt=${options.prompt}`);
|
|
79
|
+
}
|
|
80
|
+
if (options.permissions) {
|
|
81
|
+
params.push(`permissions=${options.permissions}`);
|
|
82
|
+
}
|
|
83
|
+
if (options.guildID) {
|
|
84
|
+
params.push(`guild_id=${options.guildID}`);
|
|
85
|
+
}
|
|
86
|
+
if (options.state) {
|
|
87
|
+
params.push(`state=${options.state}`);
|
|
88
|
+
}
|
|
89
|
+
if (options.integrationType) {
|
|
90
|
+
params.push(`integration_type=${options.integrationType}`);
|
|
91
|
+
}
|
|
92
|
+
return `${Constants_1.BASE_URL}${Routes.OAUTH_AUTHORIZE}?${params.join("&")}`;
|
|
93
|
+
}
|
|
94
|
+
async addGuildMember(guildID, userID, options) {
|
|
95
|
+
return this._manager.guilds.addMember(guildID, userID, { accessToken: this._token.split(" ").slice(1).join(" "), ...options });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the current OAuth2 application's information.
|
|
99
|
+
*/
|
|
100
|
+
async getApplication() {
|
|
101
|
+
return this._manager.request({
|
|
102
|
+
method: "GET",
|
|
103
|
+
path: Routes.OAUTH_APPLICATION,
|
|
104
|
+
auth: this._token
|
|
105
|
+
}).then(data => new OAuthApplication_1.default(data, this._manager.client));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get information about the current authorization.
|
|
109
|
+
*/
|
|
110
|
+
async getCurrentAuthorizationInformation() {
|
|
111
|
+
return this._manager.request({
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: Routes.OAUTH_INFO,
|
|
114
|
+
auth: this._token
|
|
115
|
+
}).then(data => ({
|
|
116
|
+
application: new PartialApplication_1.default(data.application, this._manager.client),
|
|
117
|
+
expires: new Date(data.expires),
|
|
118
|
+
scopes: data.scopes,
|
|
119
|
+
user: this._manager.client.users.update(data.user)
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the connections of the currently authenticated user.
|
|
124
|
+
*
|
|
125
|
+
* Note: Requires the `connections` scope.
|
|
126
|
+
*/
|
|
127
|
+
async getCurrentConnections() {
|
|
128
|
+
return this._manager.request({
|
|
129
|
+
method: "GET",
|
|
130
|
+
path: Routes.OAUTH_CONNECTIONS,
|
|
131
|
+
auth: this._token
|
|
132
|
+
}).then(data => data.map(connection => ({
|
|
133
|
+
friendSync: connection.friend_sync,
|
|
134
|
+
id: connection.id,
|
|
135
|
+
integrations: connection.integrations?.map(integration => new Integration_1.default(integration, this._manager.client)),
|
|
136
|
+
name: connection.name,
|
|
137
|
+
revoked: connection.revoked,
|
|
138
|
+
showActivity: connection.show_activity,
|
|
139
|
+
twoWayLink: connection.two_way_link,
|
|
140
|
+
type: connection.type,
|
|
141
|
+
verified: connection.verified,
|
|
142
|
+
visibility: connection.visibility
|
|
143
|
+
})));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the guild member information about the currently authenticated user.
|
|
147
|
+
*
|
|
148
|
+
* Note: Requires the `guilds.members.read` scope.
|
|
149
|
+
* @param guild the ID of the guild
|
|
150
|
+
*/
|
|
151
|
+
async getCurrentGuildMember(guild) {
|
|
152
|
+
return this._manager.request({
|
|
153
|
+
method: "GET",
|
|
154
|
+
path: Routes.OAUTH_GUILD_MEMBER(guild),
|
|
155
|
+
auth: this._token
|
|
156
|
+
}).then(data => new Member_1.default(data, this._manager.client, guild));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the currently authenticated user's guilds. Note these are missing several properties gateway guilds have.
|
|
160
|
+
*/
|
|
161
|
+
async getCurrentGuilds() {
|
|
162
|
+
return this._manager.request({
|
|
163
|
+
method: "GET",
|
|
164
|
+
path: Routes.OAUTH_GUILDS,
|
|
165
|
+
auth: this._token
|
|
166
|
+
}).then(data => data.map(d => new OAuthGuild_1.default(d, this._manager.client)));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get the currently authenticated user's information.
|
|
170
|
+
*
|
|
171
|
+
* Note: This does not touch the client's cache in any way.
|
|
172
|
+
*/
|
|
173
|
+
async getCurrentUser() {
|
|
174
|
+
return this._manager.request({
|
|
175
|
+
method: "GET",
|
|
176
|
+
path: Routes.OAUTH_CURRENT_USER,
|
|
177
|
+
auth: this._token
|
|
178
|
+
}).then(data => new ExtendedUser_1.default(data, this._manager.client));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Revoke the used access token.
|
|
182
|
+
* @param options The options for revoking the token.
|
|
183
|
+
*/
|
|
184
|
+
async revokeToken(options) {
|
|
185
|
+
const form = new FormData();
|
|
186
|
+
form.append("client_id", options.clientID);
|
|
187
|
+
form.append("client_secret", options.clientSecret);
|
|
188
|
+
form.append("token", this._token);
|
|
189
|
+
await this._manager.authRequest({
|
|
190
|
+
method: "POST",
|
|
191
|
+
path: Routes.OAUTH_TOKEN_REVOKE,
|
|
192
|
+
form
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Update the authenticated user's role connection object for an application. This requires the `role_connections.write` scope.
|
|
197
|
+
* @param applicationID The ID of the application.
|
|
198
|
+
* @param data The metadata to update.
|
|
199
|
+
*/
|
|
200
|
+
async updateRoleConnection(applicationID, data) {
|
|
201
|
+
return this._manager.request({
|
|
202
|
+
method: "PUT",
|
|
203
|
+
path: Routes.OAUTH_ROLE_CONNECTION(applicationID),
|
|
204
|
+
json: {
|
|
205
|
+
metadata: data.metadata,
|
|
206
|
+
platform_name: data.platformName,
|
|
207
|
+
platform_username: data.platformUsername
|
|
208
|
+
},
|
|
209
|
+
auth: this._token
|
|
210
|
+
}).then(d => ({
|
|
211
|
+
metadata: Object.entries(d.metadata).map(([key, value]) => ({
|
|
212
|
+
[key]: {
|
|
213
|
+
description: value.description,
|
|
214
|
+
descriptionLocalizations: value.description_localizations,
|
|
215
|
+
key: value.key,
|
|
216
|
+
name: value.name,
|
|
217
|
+
nameLocalizations: value.name_localizations,
|
|
218
|
+
type: value.type
|
|
219
|
+
}
|
|
220
|
+
})).reduce((a, b) => ({ ...a, ...b })),
|
|
221
|
+
platformName: d.platform_name,
|
|
222
|
+
platformUsername: d.platform_username
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.default = OAuthHelper;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined)
|
|
4
|
+
k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function () { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function (o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined)
|
|
12
|
+
k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function (o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function (o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o)
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(o, k))
|
|
26
|
+
ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule)
|
|
33
|
+
return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null)
|
|
36
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
37
|
+
if (k[i] !== "default")
|
|
38
|
+
__createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
44
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
/** @module RESTManager */
|
|
48
|
+
const RequestHandler_1 = __importDefault(require("./RequestHandler"));
|
|
49
|
+
const Channels_1 = __importDefault(require("../routes/Channels"));
|
|
50
|
+
const Guilds_1 = __importDefault(require("../routes/Guilds"));
|
|
51
|
+
const Users_1 = __importDefault(require("../routes/Users"));
|
|
52
|
+
const OAuth_1 = __importDefault(require("../routes/OAuth"));
|
|
53
|
+
const Webhooks_1 = __importDefault(require("../routes/Webhooks"));
|
|
54
|
+
const Applications_1 = __importDefault(require("../routes/Applications"));
|
|
55
|
+
const Interactions_1 = __importDefault(require("../routes/Interactions"));
|
|
56
|
+
const Routes = __importStar(require("../util/Routes"));
|
|
57
|
+
const Miscellaneous_1 = __importDefault(require("../routes/Miscellaneous"));
|
|
58
|
+
const Lobbies_1 = __importDefault(require("../routes/Lobbies"));
|
|
59
|
+
/** A manager for all rest actions. */
|
|
60
|
+
class RESTManager {
|
|
61
|
+
constructor(client, options) {
|
|
62
|
+
this.applications = new Applications_1.default(this);
|
|
63
|
+
this.channels = new Channels_1.default(this);
|
|
64
|
+
this._client = client;
|
|
65
|
+
this.guilds = new Guilds_1.default(this);
|
|
66
|
+
this.handler = new RequestHandler_1.default(this, options);
|
|
67
|
+
this.interactions = new Interactions_1.default(this);
|
|
68
|
+
this.lobbies = new Lobbies_1.default(this);
|
|
69
|
+
this.misc = new Miscellaneous_1.default(this);
|
|
70
|
+
this.oauth = new OAuth_1.default(this);
|
|
71
|
+
this.users = new Users_1.default(this);
|
|
72
|
+
this.webhooks = new Webhooks_1.default(this);
|
|
73
|
+
}
|
|
74
|
+
get client() {
|
|
75
|
+
return this._client;
|
|
76
|
+
}
|
|
77
|
+
get options() {
|
|
78
|
+
return this.handler.options;
|
|
79
|
+
}
|
|
80
|
+
/** Alias for {@link RequestHandler#authRequest | RequestHandler#authRequest} */
|
|
81
|
+
async authRequest(options) {
|
|
82
|
+
return this.handler.authRequest(options);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the gateway information related to your bot client.
|
|
86
|
+
*/
|
|
87
|
+
async getBotGateway() {
|
|
88
|
+
return this.authRequest({
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: Routes.GATEWAY_BOT
|
|
91
|
+
}).then(data => ({
|
|
92
|
+
url: data.url,
|
|
93
|
+
shards: data.shards,
|
|
94
|
+
sessionStartLimit: {
|
|
95
|
+
total: data.session_start_limit.total,
|
|
96
|
+
remaining: data.session_start_limit.remaining,
|
|
97
|
+
resetAfter: data.session_start_limit.reset_after,
|
|
98
|
+
maxConcurrency: data.session_start_limit.max_concurrency
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the gateway information.
|
|
104
|
+
*/
|
|
105
|
+
async getGateway() {
|
|
106
|
+
return this.request({
|
|
107
|
+
method: "GET",
|
|
108
|
+
path: Routes.GATEWAY
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Alias for {@link RequestHandler#request | RequestHandler#request} */
|
|
112
|
+
async request(options) {
|
|
113
|
+
return this.handler.request(options);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.default = RESTManager;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** @module RequestHandler */
|
|
7
|
+
const SequentialBucket_1 = __importDefault(require("./SequentialBucket"));
|
|
8
|
+
const DiscordRESTError_1 = __importDefault(require("./DiscordRESTError"));
|
|
9
|
+
const DiscordHTTPError_1 = __importDefault(require("./DiscordHTTPError"));
|
|
10
|
+
const Constants_1 = require("../Constants");
|
|
11
|
+
const Base_1 = __importDefault(require("../structures/Base"));
|
|
12
|
+
const Errors_1 = require("../util/Errors");
|
|
13
|
+
/**
|
|
14
|
+
* Latency & ratelimit related things lovingly borrowed from eris
|
|
15
|
+
* https://github.com/abalabahaha/eris/blob/dev/lib/rest/RequestHandler.js (eb403730855714eafa36c541dbe2cb84c9979158)
|
|
16
|
+
*/
|
|
17
|
+
/** The primary means of communicating with Discord via rest. */
|
|
18
|
+
class RequestHandler {
|
|
19
|
+
constructor(manager, options = {}) {
|
|
20
|
+
this.globalBlock = false;
|
|
21
|
+
this.ratelimits = {};
|
|
22
|
+
this.readyQueue = [];
|
|
23
|
+
if (options && options.baseURL && options.baseURL.endsWith("/")) {
|
|
24
|
+
options.baseURL = options.baseURL.slice(0, -1);
|
|
25
|
+
}
|
|
26
|
+
this._manager = manager;
|
|
27
|
+
this.options = {
|
|
28
|
+
agent: options.agent,
|
|
29
|
+
baseURL: options.baseURL ?? Constants_1.API_URL,
|
|
30
|
+
disableLatencyCompensation: !!options.disableLatencyCompensation,
|
|
31
|
+
followRedirects: !!options.followRedirects,
|
|
32
|
+
host: options.host ?? (options.baseURL ? new URL(options.baseURL).host : new URL(Constants_1.API_URL).host),
|
|
33
|
+
latencyThreshold: options.latencyThreshold ?? 30000,
|
|
34
|
+
maxRatelimitRetryWindow: options.maxRatelimitRetryWindow ?? 30000,
|
|
35
|
+
ratelimiterOffset: options.ratelimiterOffset ?? 0,
|
|
36
|
+
requestTimeout: options.requestTimeout ?? 15000,
|
|
37
|
+
superProperties: options.superProperties ?? null,
|
|
38
|
+
userAgent: options.userAgent ?? Constants_1.USER_AGENT
|
|
39
|
+
};
|
|
40
|
+
this.latencyRef = {
|
|
41
|
+
lastTimeOffsetCheck: 0,
|
|
42
|
+
latency: options.ratelimiterOffset ?? 0,
|
|
43
|
+
raw: Array.from({ length: 10 }).fill(options.ratelimiterOffset ?? 0),
|
|
44
|
+
timeOffsets: Array.from({ length: 10 }).fill(0),
|
|
45
|
+
timeoffset: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
getRoute(path, method) {
|
|
49
|
+
let route = path.replaceAll(/\/([a-z-]+)\/\d{15,21}/g, function (match, p) {
|
|
50
|
+
return p === "channels" || p === "guilds" || p === "webhooks" ? match : `/${p}/:id`;
|
|
51
|
+
}).replaceAll(/\/reactions\/[^/]+/g, "/reactions/:id").replaceAll(/\/reactions\/:id\/[^/]+/g, "/reactions/:id/:userID").replace(/^\/webhooks\/(\d+)\/[\w-]{64,}/, "/webhooks/$1/:token");
|
|
52
|
+
if (method === "DELETE" && route.endsWith("/messages/:id")) {
|
|
53
|
+
const messageID = path.slice(path.lastIndexOf("/") + 1);
|
|
54
|
+
const createdAt = Base_1.default.getCreatedAt(messageID).getTime();
|
|
55
|
+
if (Date.now() - this.latencyRef.latency - createdAt >= 1000 * 60 * 60 * 24 * 14) {
|
|
56
|
+
method += "_OLD";
|
|
57
|
+
}
|
|
58
|
+
else if (Date.now() - this.latencyRef.latency - createdAt <= 1000 * 10) {
|
|
59
|
+
method += "_NEW";
|
|
60
|
+
}
|
|
61
|
+
route = method + route;
|
|
62
|
+
}
|
|
63
|
+
else if (method === "GET" && /\/guilds\/\d+\/channels$/.test(route)) {
|
|
64
|
+
route = "/guilds/:id/channels";
|
|
65
|
+
}
|
|
66
|
+
if (method === "PUT" || method === "DELETE") {
|
|
67
|
+
const index = route.indexOf("/reactions");
|
|
68
|
+
if (index !== -1) {
|
|
69
|
+
route = "MODIFY" + route.slice(0, index + 10);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return route;
|
|
73
|
+
}
|
|
74
|
+
globalUnblock() {
|
|
75
|
+
this.globalBlock = false;
|
|
76
|
+
while (this.readyQueue.length !== 0) {
|
|
77
|
+
this.readyQueue.shift()();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** same as `request`, but with `auth` always set to `true`. */
|
|
81
|
+
async authRequest(options) {
|
|
82
|
+
return this.request({
|
|
83
|
+
...options,
|
|
84
|
+
auth: true
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Make a request. `null` will be returned if the request results in a `204 NO CONTENT`.
|
|
89
|
+
* @param options The options for the request.
|
|
90
|
+
*/
|
|
91
|
+
async request(options) {
|
|
92
|
+
options.method = options.method.toUpperCase();
|
|
93
|
+
if (!Constants_1.RESTMethods.includes(options.method)) {
|
|
94
|
+
throw new TypeError(`Invalid method "${options.method}.`);
|
|
95
|
+
}
|
|
96
|
+
const _stackHolder = {};
|
|
97
|
+
Error.captureStackTrace(_stackHolder);
|
|
98
|
+
if (!options.path.startsWith("/")) {
|
|
99
|
+
options.path = `/${options.path}`;
|
|
100
|
+
}
|
|
101
|
+
const route = options.route ?? this.getRoute(options.path, options.method);
|
|
102
|
+
if (!this.ratelimits[route]) {
|
|
103
|
+
this.ratelimits[route] = new SequentialBucket_1.default(1, this.latencyRef);
|
|
104
|
+
}
|
|
105
|
+
let attempts = 0;
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
async function attempt(cb) {
|
|
108
|
+
const headers = options.headers ?? {};
|
|
109
|
+
try {
|
|
110
|
+
if (typeof options.auth === "string") {
|
|
111
|
+
headers.Authorization = options.auth;
|
|
112
|
+
}
|
|
113
|
+
else if (options.auth && this._manager.client.options.auth) {
|
|
114
|
+
headers.Authorization = this._manager.client.options.auth;
|
|
115
|
+
}
|
|
116
|
+
if (options.reason) {
|
|
117
|
+
headers["X-Audit-Log-Reason"] = encodeURIComponent(options.reason);
|
|
118
|
+
}
|
|
119
|
+
let reqBody;
|
|
120
|
+
if (options.method !== "GET") {
|
|
121
|
+
let stringBody;
|
|
122
|
+
if (options.json) {
|
|
123
|
+
stringBody = JSON.stringify(options.json, (k, v) => typeof v === "bigint" ? v.toString() : v);
|
|
124
|
+
}
|
|
125
|
+
if (options.form || (options.files && options.files.length !== 0)) {
|
|
126
|
+
const data = options.form ?? new FormData();
|
|
127
|
+
let index = 0;
|
|
128
|
+
if (options.files)
|
|
129
|
+
for (const file of options.files.values()) {
|
|
130
|
+
index++;
|
|
131
|
+
if (file.index !== undefined) {
|
|
132
|
+
index = file.index;
|
|
133
|
+
}
|
|
134
|
+
if (!file.contents) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
data.set(file.field || `files[${index}]`, new Blob([file.contents]), file.name);
|
|
138
|
+
}
|
|
139
|
+
if (stringBody) {
|
|
140
|
+
data.set("payload_json", stringBody);
|
|
141
|
+
}
|
|
142
|
+
reqBody = data;
|
|
143
|
+
}
|
|
144
|
+
else if (options.json) {
|
|
145
|
+
reqBody = stringBody;
|
|
146
|
+
headers["Content-Type"] = "application/json";
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (this.options.host) {
|
|
150
|
+
headers.Host = this.options.host;
|
|
151
|
+
}
|
|
152
|
+
if (this.options.superProperties) {
|
|
153
|
+
headers["X-Super-Properties"] = typeof this.options.superProperties === "object" ? JSON.stringify(this.options.superProperties) : this.options.superProperties;
|
|
154
|
+
}
|
|
155
|
+
const url = `${this.options.baseURL}${options.path}${options.query && Array.from(options.query.keys()).length !== 0 ? `?${options.query.toString()}` : ""}`;
|
|
156
|
+
let latency = Date.now();
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
let timeout;
|
|
159
|
+
if (this.options.requestTimeout > 0 && this.options.requestTimeout !== Infinity) {
|
|
160
|
+
timeout = setTimeout(() => controller.abort(), this.options.requestTimeout);
|
|
161
|
+
}
|
|
162
|
+
const res = await fetch(url, {
|
|
163
|
+
method: options.method,
|
|
164
|
+
headers,
|
|
165
|
+
body: reqBody,
|
|
166
|
+
dispatcher: this.options.agent || undefined,
|
|
167
|
+
signal: controller.signal,
|
|
168
|
+
redirect: this.options.followRedirects ? "follow" : "manual"
|
|
169
|
+
});
|
|
170
|
+
if (timeout) {
|
|
171
|
+
clearTimeout(timeout);
|
|
172
|
+
}
|
|
173
|
+
latency = Date.now() - latency;
|
|
174
|
+
if (!this.options.disableLatencyCompensation) {
|
|
175
|
+
this.latencyRef.raw.push(latency);
|
|
176
|
+
this.latencyRef.latency = this.latencyRef.latency - Math.trunc((this.latencyRef.raw.shift() ?? 0) / 10) + Math.trunc(latency / 10);
|
|
177
|
+
}
|
|
178
|
+
let resBody;
|
|
179
|
+
if (res.status === 204) {
|
|
180
|
+
resBody = null;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (res.headers.get("content-type") === "application/json") {
|
|
184
|
+
const b = await res.text();
|
|
185
|
+
try {
|
|
186
|
+
resBody = JSON.parse(b);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
this._manager.client.emit("error", err);
|
|
190
|
+
resBody = b;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
resBody = Buffer.from(await res.arrayBuffer());
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
this._manager.client.emit("request", {
|
|
198
|
+
method: options.method,
|
|
199
|
+
path: options.path,
|
|
200
|
+
route,
|
|
201
|
+
withAuth: !!options.auth,
|
|
202
|
+
requestBody: reqBody,
|
|
203
|
+
responseBody: resBody
|
|
204
|
+
});
|
|
205
|
+
const headerNow = Date.parse(res.headers.get("date"));
|
|
206
|
+
const now = Date.now();
|
|
207
|
+
if (this.latencyRef.lastTimeOffsetCheck < (Date.now() - 5000)) {
|
|
208
|
+
const timeOffset = headerNow + 500 - (this.latencyRef.lastTimeOffsetCheck = Date.now());
|
|
209
|
+
if (this.latencyRef.timeoffset - this.latencyRef.latency >= this.options.latencyThreshold && timeOffset - this.latencyRef.latency >= this.options.latencyThreshold) {
|
|
210
|
+
this._manager.client.emit("warn", `Your clock is ${this.latencyRef.timeoffset}ms behind Discord's server clock. Please check your connection and system time.`);
|
|
211
|
+
}
|
|
212
|
+
this.latencyRef.timeoffset = this.latencyRef.timeoffset - Math.trunc(this.latencyRef.timeOffsets.shift() / 10) + Math.trunc(timeOffset / 10);
|
|
213
|
+
this.latencyRef.timeOffsets.push(timeOffset);
|
|
214
|
+
}
|
|
215
|
+
if (res.headers.has("x-ratelimit-limit")) {
|
|
216
|
+
this.ratelimits[route].limit = Number(res.headers.get("x-ratelimit-limit"));
|
|
217
|
+
}
|
|
218
|
+
if (options.method !== "GET" && (!res.headers.has("x-ratelimit-remaining") || !res.headers.has("x-ratelimit-limit")) && this.ratelimits[route].limit !== 1) {
|
|
219
|
+
this._manager.client.emit("debug", [`Missing ratelimit headers for SequentialBucket(${this.ratelimits[route].remaining}/${this.ratelimits[route].limit}) with non-default limit\n`,
|
|
220
|
+
`${res.status} ${res.headers.get("content-type") ?? "null"}: ${options.method} ${route} | ${res.headers.get("cf-ray") ?? "null"}\n`,
|
|
221
|
+
`content-type = ${res.headers.get("content-type") ?? "null"}\n`,
|
|
222
|
+
`x-ratelimit-remaining = ${res.headers.get("x-ratelimit-remaining") ?? "null"}\n`,
|
|
223
|
+
`x-ratelimit-limit = ${res.headers.get("x-ratelimit-limit") ?? "null"}\n`,
|
|
224
|
+
`x-ratelimit-reset = ${res.headers.get("x-ratelimit-reset") ?? "null"}\n`,
|
|
225
|
+
`x-ratelimit-global = ${res.headers.get("x-ratelimit-global") ?? "null"}`].join("\n"));
|
|
226
|
+
}
|
|
227
|
+
this.ratelimits[route].remaining = res.headers.has("x-ratelimit-remaining") ? Number(res.headers.get("x-ratelimit-remaining")) ?? 0 : 1;
|
|
228
|
+
const retryAfter = Number(res.headers.get("x-ratelimit-reset-after") ?? res.headers.get("retry-after") ?? 0) * 1000;
|
|
229
|
+
if (retryAfter >= 0) {
|
|
230
|
+
if (res.headers.has("x-ratelimit-global")) {
|
|
231
|
+
this.globalBlock = true;
|
|
232
|
+
setTimeout(this.globalUnblock.bind(this), retryAfter ?? 1);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.ratelimits[route].reset = (retryAfter ?? 1) + now;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (res.headers.has("x-ratelimit-reset")) {
|
|
239
|
+
let resetTime = Number(res.headers.get("x-ratelimit-reset")) * 1000;
|
|
240
|
+
if (route.endsWith("/reactions/:id") && (resetTime - headerNow) === 1000) {
|
|
241
|
+
resetTime = now + 250;
|
|
242
|
+
}
|
|
243
|
+
this.ratelimits[route].reset = Math.max(resetTime - this.latencyRef.latency, now);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this.ratelimits[route].reset = now;
|
|
247
|
+
}
|
|
248
|
+
if (res.status !== 429) {
|
|
249
|
+
this._manager.client.emit("debug", `${now} ${route} ${res.status}: ${latency}ms (${this.latencyRef.latency}ms avg) | ${this.ratelimits[route].remaining}/${this.ratelimits[route].limit} left | Reset ${this.ratelimits[route].reset} (${this.ratelimits[route].reset - now}ms left)`);
|
|
250
|
+
}
|
|
251
|
+
if (res.status > 300) {
|
|
252
|
+
if (res.status === 429) {
|
|
253
|
+
let delay = retryAfter;
|
|
254
|
+
if (res.headers.get("x-ratelimit-scope") === "shared") {
|
|
255
|
+
try {
|
|
256
|
+
delay = resBody.retry_after * 1000;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
cb();
|
|
260
|
+
reject(err);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this._manager.client.emit("debug", `${res.headers.has("x-ratelimit-global") ? "Global" : "Unexpected"} RateLimit: ${JSON.stringify(resBody)}\n${now} ${route} ${res.status}: ${latency}ms (${this.latencyRef.latency}ms avg) | ${this.ratelimits[route].remaining}/${this.ratelimits[route].limit} left | Reset ${delay} (${this.ratelimits[route].reset - now}ms left) | Scope ${res.headers.get("x-ratelimit-scope")}`);
|
|
264
|
+
if (delay) {
|
|
265
|
+
if (delay > this.options.maxRatelimitRetryWindow) {
|
|
266
|
+
cb();
|
|
267
|
+
return reject(new Errors_1.RateLimitedError(`Ratelimit on "${options.method} ${route}" exceeds the maximum retry window (${delay} > ${this.options.maxRatelimitRetryWindow})`, delay));
|
|
268
|
+
}
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
cb();
|
|
271
|
+
// eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, prefer-spread
|
|
272
|
+
this.request(options).then(resolve).catch(reject);
|
|
273
|
+
}, delay);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
cb();
|
|
278
|
+
this.request(options).then(resolve).catch(reject);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else if (res.status === 502 && ++attempts < 4) {
|
|
283
|
+
this._manager.client.emit("debug", `Unexpected 502 on ${options.method} ${route}`);
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
this.request(options).then(resolve).catch(reject);
|
|
286
|
+
}, Math.floor(Math.random() * 1900 + 100));
|
|
287
|
+
return cb();
|
|
288
|
+
}
|
|
289
|
+
cb();
|
|
290
|
+
let { stack } = _stackHolder;
|
|
291
|
+
if (stack.startsWith("Error\n")) {
|
|
292
|
+
stack = stack.slice(6);
|
|
293
|
+
}
|
|
294
|
+
const err = resBody && typeof resBody === "object" && "code" in resBody ? new DiscordRESTError_1.default(res, resBody, options.method, stack) : new DiscordHTTPError_1.default(res, resBody, options.method, stack);
|
|
295
|
+
reject(err);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
cb();
|
|
299
|
+
resolve(resBody);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
cb();
|
|
303
|
+
if (err instanceof Error && err.constructor.name === "DOMException" && err.name === "AbortError") {
|
|
304
|
+
reject(new Error(`Request Timed Out (>${this.options.requestTimeout}ms) on ${options.method} ${options.path}`));
|
|
305
|
+
}
|
|
306
|
+
this._manager.client.emit("error", err);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (this.globalBlock && options.auth) {
|
|
310
|
+
(options.priority ? this.readyQueue.unshift.bind(this.readyQueue) : this.readyQueue.push.bind(this.readyQueue))(() => {
|
|
311
|
+
this.ratelimits[route].queue(attempt.bind(this), options.priority);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
this.ratelimits[route].queue(attempt.bind(this), options.priority);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.default = RequestHandler;
|