@deffa5556/bail 1.0.6 → 1.0.9
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/lib/Socket/socket.js +3 -3
- package/lib/Telegram/esm-bridge.mjs +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,344 @@
|
|
|
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 ShardManager */
|
|
7
|
+
const Shard_1 = __importDefault(require("./Shard.cjs"));
|
|
8
|
+
const Dispatcher_1 = __importDefault(require("./Dispatcher.cjs"));
|
|
9
|
+
const config_1 = __importDefault(require("./compression/config.cjs"));
|
|
10
|
+
const Constants_1 = require("../Constants.cjs");
|
|
11
|
+
const Collection_1 = __importDefault(require("../util/Collection.cjs"));
|
|
12
|
+
const Errors_1 = require("../util/Errors.cjs");
|
|
13
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, unicorn/prefer-module */
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
let Erlpack;
|
|
16
|
+
try {
|
|
17
|
+
Erlpack = require("erlpack");
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
/* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, unicorn/prefer-module */
|
|
21
|
+
/** A manager for all the client's shards. */
|
|
22
|
+
class ShardManager extends Collection_1.default {
|
|
23
|
+
constructor(client, options = {}) {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
super();
|
|
26
|
+
this.connected = false;
|
|
27
|
+
Object.defineProperty(this, "client", {
|
|
28
|
+
value: client,
|
|
29
|
+
writable: false,
|
|
30
|
+
enumerable: false,
|
|
31
|
+
configurable: false
|
|
32
|
+
});
|
|
33
|
+
this._buckets = {};
|
|
34
|
+
this._connectQueue = [];
|
|
35
|
+
this._connectTimeout = null;
|
|
36
|
+
this.options = {
|
|
37
|
+
autoReconnect: options.autoReconnect ?? true,
|
|
38
|
+
compress: options.compress ?? false,
|
|
39
|
+
compressLibrary: options.compressLibrary ?? null,
|
|
40
|
+
connectionProperties: {
|
|
41
|
+
browser: options.connectionProperties?.browser ?? "Oceanic",
|
|
42
|
+
device: options.connectionProperties?.device ?? "Oceanic",
|
|
43
|
+
os: options.connectionProperties?.os ?? process.platform
|
|
44
|
+
},
|
|
45
|
+
concurrency: options.concurrency === "auto" || options.concurrency && options.concurrency < 1 ? -1 : options.concurrency ?? -1,
|
|
46
|
+
connectionTimeout: options.connectionTimeout ?? 30000,
|
|
47
|
+
dispatcher: {
|
|
48
|
+
blacklist: options.dispatcher?.blacklist === undefined ? null : options.dispatcher.blacklist,
|
|
49
|
+
whitelist: options.dispatcher?.whitelist === undefined ? null : options.dispatcher.whitelist
|
|
50
|
+
},
|
|
51
|
+
firstShardID: options.firstShardID && options.firstShardID < 0 ? 0 : options.firstShardID ?? 0,
|
|
52
|
+
getAllUsers: options.getAllUsers ?? false,
|
|
53
|
+
override: options.override ?? {
|
|
54
|
+
appendQuery: true,
|
|
55
|
+
gatewayURLIsResumeURL: false,
|
|
56
|
+
timeBetweenShardConnects: 5000
|
|
57
|
+
},
|
|
58
|
+
guildCreateTimeout: options.guildCreateTimeout ?? 2000,
|
|
59
|
+
intents: typeof options.intents === "number" ? options.intents : 0,
|
|
60
|
+
largeThreshold: options.largeThreshold ?? 250,
|
|
61
|
+
lastShardID: options.lastShardID ?? -1,
|
|
62
|
+
lookupDisallowedIntents: options.lookupDisallowedIntents ?? false,
|
|
63
|
+
maxReconnectAttempts: options.maxReconnectAttempts ?? Infinity,
|
|
64
|
+
maxResumeAttempts: options.maxResumeAttempts ?? 10,
|
|
65
|
+
maxShards: options.maxShards === "auto" || options.maxShards && options.maxShards < 1 ? -1 : options.maxShards ?? -1,
|
|
66
|
+
presence: {
|
|
67
|
+
activities: options.presence?.activities ?? [],
|
|
68
|
+
afk: options.presence?.afk ?? false,
|
|
69
|
+
status: options.presence?.status ?? "online"
|
|
70
|
+
},
|
|
71
|
+
reconnectDelay: options.reconnectDelay ?? ((lastDelay, attempts) => Math.pow(attempts + 1, 0.7) * 20000),
|
|
72
|
+
removeDisallowedIntents: options.removeDisallowedIntents ?? false,
|
|
73
|
+
seedVoiceConnections: options.seedVoiceConnections ?? false,
|
|
74
|
+
shardIDs: options.shardIDs ?? [],
|
|
75
|
+
ws: options.ws ?? {}
|
|
76
|
+
};
|
|
77
|
+
if (this.options.compress) {
|
|
78
|
+
const types = Object.keys(config_1.default);
|
|
79
|
+
if (!types.includes(this.options.compress)) {
|
|
80
|
+
throw new Error(`Invalid compress type: ${this.options.compress}`);
|
|
81
|
+
}
|
|
82
|
+
if (this.options.compressLibrary) {
|
|
83
|
+
const config = config_1.default[this.options.compress].find(cnf => cnf.name === this.options.compressLibrary);
|
|
84
|
+
if (!config) {
|
|
85
|
+
throw new Error(`Invalid library "${this.options.compressLibrary}" for ${this.options.compress}`);
|
|
86
|
+
}
|
|
87
|
+
if (!config.check(client)) {
|
|
88
|
+
throw config.getError();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const available = config_1.default[this.options.compress] ?? [];
|
|
93
|
+
const usable = available.find(av => av.check(client));
|
|
94
|
+
if (!usable) {
|
|
95
|
+
throw new Errors_1.DependencyError(`Unable to find a usable ${this.options.compress} compressor`);
|
|
96
|
+
}
|
|
97
|
+
this.options.compressLibrary = usable.name;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
(_a = this.options.override).appendQuery ?? (_a.appendQuery = this.options.override.getBot === undefined && this.options.override.url === undefined);
|
|
101
|
+
(_b = this.options.override).gatewayURLIsResumeURL ?? (_b.gatewayURLIsResumeURL = this.options.override.getBot !== undefined || this.options.override.url !== undefined);
|
|
102
|
+
(_c = this.options.override).timeBetweenShardConnects ?? (_c.timeBetweenShardConnects = 5000);
|
|
103
|
+
if (this.options.lastShardID === -1 && this.options.maxShards !== -1) {
|
|
104
|
+
this.options.lastShardID = this.options.maxShards - 1;
|
|
105
|
+
}
|
|
106
|
+
if (!Array.isArray(this.options.shardIDs)) {
|
|
107
|
+
this.options.shardIDs = [];
|
|
108
|
+
}
|
|
109
|
+
if (Object.hasOwn(options, "intents")) {
|
|
110
|
+
if (Array.isArray(options.intents)) {
|
|
111
|
+
let bitmask = 0;
|
|
112
|
+
for (const intent of options.intents) {
|
|
113
|
+
if (typeof intent === "number") {
|
|
114
|
+
bitmask |= intent;
|
|
115
|
+
}
|
|
116
|
+
else if (Constants_1.Intents[intent]) {
|
|
117
|
+
bitmask |= Constants_1.Intents[intent];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
if (intent === "ALL") {
|
|
121
|
+
bitmask = Constants_1.AllIntents;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
else if (intent === "ALL_NON_PRIVILEGED") {
|
|
125
|
+
bitmask = Constants_1.AllNonPrivilegedIntents;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
client.emit("warn", `Unknown intent: ${intent}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.options.intents = bitmask;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.options.intents = Constants_1.AllNonPrivilegedIntents;
|
|
136
|
+
}
|
|
137
|
+
if (this.options.getAllUsers && !(this.options.intents & Constants_1.Intents.GUILD_MEMBERS)) {
|
|
138
|
+
throw new TypeError("Guild members cannot be requested without the GUILD_MEMBERS intent");
|
|
139
|
+
}
|
|
140
|
+
Object.defineProperty(this, "dispatcher", {
|
|
141
|
+
value: new Dispatcher_1.default(this),
|
|
142
|
+
writable: false,
|
|
143
|
+
enumerable: false,
|
|
144
|
+
configurable: false
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
_connect(shard) {
|
|
148
|
+
this._connectQueue.push(shard);
|
|
149
|
+
this.tryConnect();
|
|
150
|
+
}
|
|
151
|
+
_forGuild(guild) {
|
|
152
|
+
if (this.options.maxShards === -1) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return this.get((this.client.guildShardMap.get(guild) ?? Number((BigInt(guild) >> 22n) % BigInt(this.options.maxShards))));
|
|
156
|
+
}
|
|
157
|
+
async _gatewayURLForShard(shard) {
|
|
158
|
+
if (this.options.override.url !== undefined) {
|
|
159
|
+
return this.options.override.url(shard, this.options.shardIDs.length);
|
|
160
|
+
}
|
|
161
|
+
if (this._gatewayURL) {
|
|
162
|
+
return this._gatewayURL;
|
|
163
|
+
}
|
|
164
|
+
// how did we manage to get all the way to connecting without gatewayURL being set?
|
|
165
|
+
return (this._gatewayURL = (await (this.options.override.getBot?.() ?? this.client.rest.getBotGateway())).url);
|
|
166
|
+
}
|
|
167
|
+
_ready(id) {
|
|
168
|
+
const mod = id % this.options.concurrency;
|
|
169
|
+
const rateLimitKey = isNaN(mod) ? 0 : mod;
|
|
170
|
+
this._buckets[rateLimitKey] = Date.now();
|
|
171
|
+
this.tryConnect();
|
|
172
|
+
}
|
|
173
|
+
_resetConnectQueue() {
|
|
174
|
+
this._connectQueue = [];
|
|
175
|
+
}
|
|
176
|
+
async connect() {
|
|
177
|
+
if (this.connected) {
|
|
178
|
+
throw new Error("Already connected.");
|
|
179
|
+
}
|
|
180
|
+
let url, data;
|
|
181
|
+
const overrideURL = (this.options.override.getBot || this.options.override.url) !== undefined;
|
|
182
|
+
try {
|
|
183
|
+
if (this.options.maxShards === -1 || this.options.concurrency === -1) {
|
|
184
|
+
data = await (this.options.override.getBot?.() ?? this.client.rest.getBotGateway());
|
|
185
|
+
url = data.url;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
url = overrideURL ? null : (await this.client.rest.getGateway()).url;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
throw new TypeError("Failed to get gateway information.", { cause: err });
|
|
193
|
+
}
|
|
194
|
+
if (url && this.options.override.appendQuery) {
|
|
195
|
+
if (url.includes("?")) {
|
|
196
|
+
url = url.slice(0, url.indexOf("?"));
|
|
197
|
+
}
|
|
198
|
+
if (!url.endsWith("/")) {
|
|
199
|
+
url += "/";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
|
|
203
|
+
if (this.options.removeDisallowedIntents && Constants_1.PrivilegedIntentMapping.some(([intent]) => (this.options.intents & intent) === intent)) {
|
|
204
|
+
const { flags } = await this.client.rest.applications.getCurrent();
|
|
205
|
+
const check = (intent, allowed) => {
|
|
206
|
+
if ((this.options.intents & intent) === intent && !allowed.some(flag => (flags & flag) === flag)) {
|
|
207
|
+
this.client.emit("warn", `removeDisallowedIntents is enabled, and ${Constants_1.Intents[intent]} was included but not found to be allowed. It has been removed.`);
|
|
208
|
+
this.options.intents &= ~intent;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
for (const [intent, allowed] of Constants_1.PrivilegedIntentMapping) {
|
|
212
|
+
check(intent, allowed);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */
|
|
216
|
+
if (url && this.options.override.appendQuery) {
|
|
217
|
+
url += `?v=${Constants_1.GATEWAY_VERSION}&encoding=${Erlpack ? "etf" : "json"}`;
|
|
218
|
+
if (this.options.compress) {
|
|
219
|
+
const type = this.options.compress === "zstd-stream" ? "zstd-stream" : "zlib-stream";
|
|
220
|
+
url += `&compress=${type}`;
|
|
221
|
+
}
|
|
222
|
+
this._gatewayURL = url;
|
|
223
|
+
}
|
|
224
|
+
if (this.options.maxShards === -1) {
|
|
225
|
+
if (!data || !data.shards) {
|
|
226
|
+
throw new TypeError("AutoSharding failed, missing required information from Discord.");
|
|
227
|
+
}
|
|
228
|
+
this.options.maxShards = data.shards;
|
|
229
|
+
if (this.options.lastShardID === -1) {
|
|
230
|
+
this.options.lastShardID = data.shards - 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (this.options.concurrency === -1) {
|
|
234
|
+
if (!data) {
|
|
235
|
+
throw new TypeError("AutoConcurrency failed, missing required information from Discord.");
|
|
236
|
+
}
|
|
237
|
+
this.options.concurrency = data.sessionStartLimit.maxConcurrency;
|
|
238
|
+
}
|
|
239
|
+
if (this.options.shardIDs.length === 0 && this.options.firstShardID !== undefined && this.options.lastShardID !== undefined) {
|
|
240
|
+
for (let i = this.options.firstShardID; i <= this.options.lastShardID; i++) {
|
|
241
|
+
this.options.shardIDs.push(i);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
this.connected = true;
|
|
245
|
+
for (const id of this.options.shardIDs) {
|
|
246
|
+
this.spawn(id);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Disconnect all shards.
|
|
251
|
+
* @param reconnect If shards should be reconnected. Defaults to {@link Types/Gateway~GatewayOptions#autoReconnect | GatewayOptions#autoReconnect}
|
|
252
|
+
*/
|
|
253
|
+
disconnect(reconnect = this.options.autoReconnect) {
|
|
254
|
+
if (!reconnect) {
|
|
255
|
+
this.connected = false;
|
|
256
|
+
}
|
|
257
|
+
this.client.ready = false;
|
|
258
|
+
for (const [, shard] of this)
|
|
259
|
+
shard.disconnect(reconnect);
|
|
260
|
+
this.client.time.reset();
|
|
261
|
+
this._resetConnectQueue();
|
|
262
|
+
}
|
|
263
|
+
spawn(id) {
|
|
264
|
+
let shard = this.get(id);
|
|
265
|
+
if (!shard) {
|
|
266
|
+
shard = new Shard_1.default(id, this);
|
|
267
|
+
this.set(id, shard);
|
|
268
|
+
shard
|
|
269
|
+
.on("ready", () => {
|
|
270
|
+
this.client.time.set("ready", Date.now());
|
|
271
|
+
this.client.emit("shardReady", id);
|
|
272
|
+
if (this.client.ready) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
for (const other of this.values()) {
|
|
276
|
+
if (!other.ready) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
this.client.ready = true;
|
|
281
|
+
this.client.emit("ready");
|
|
282
|
+
})
|
|
283
|
+
.on("resume", () => {
|
|
284
|
+
this.client.time.set("resume", Date.now());
|
|
285
|
+
this.client.emit("shardResume", id);
|
|
286
|
+
if (this.client.ready) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
for (const other of this.values()) {
|
|
290
|
+
if (!other.ready) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
this.client.ready = true;
|
|
295
|
+
this.client.emit("ready");
|
|
296
|
+
})
|
|
297
|
+
.on("disconnect", error => {
|
|
298
|
+
this.client.time.set("disconnect", Date.now());
|
|
299
|
+
this.client.emit("shardDisconnect", error, id);
|
|
300
|
+
for (const other of this.values()) {
|
|
301
|
+
if (other.ready) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
this.client.ready = false;
|
|
306
|
+
this.client.emit("disconnect");
|
|
307
|
+
})
|
|
308
|
+
.on("preReady", () => {
|
|
309
|
+
this.client.time.set("preReady", Date.now());
|
|
310
|
+
this.client.emit("shardPreReady", id);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
if (shard.status === "disconnected") {
|
|
314
|
+
this._connect(shard);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
tryConnect() {
|
|
318
|
+
if (this._connectQueue.length === 0) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
for (const shard of this._connectQueue) {
|
|
322
|
+
const mod = shard.id % this.options.concurrency;
|
|
323
|
+
const rateLimitKey = isNaN(mod) ? 0 : mod;
|
|
324
|
+
const lastConnect = this._buckets[rateLimitKey] ?? 0;
|
|
325
|
+
if (!shard.sessionID && Date.now() - lastConnect < this.options.override.timeBetweenShardConnects) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (this.some(s => s.connecting && ((s.id % this.options.concurrency) || 0) === rateLimitKey)) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
this.client.time.set("connect", Date.now());
|
|
332
|
+
void shard.connect();
|
|
333
|
+
this._buckets[rateLimitKey] = Date.now();
|
|
334
|
+
this._connectQueue.splice(this._connectQueue.findIndex(s => s.id === shard.id), 1);
|
|
335
|
+
}
|
|
336
|
+
if (!this._connectTimeout && this._connectQueue.length !== 0) {
|
|
337
|
+
this._connectTimeout = setTimeout(() => {
|
|
338
|
+
this._connectTimeout = null;
|
|
339
|
+
this.tryConnect();
|
|
340
|
+
}, 500);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.default = ShardManager;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Compressor {
|
|
4
|
+
constructor(shard) {
|
|
5
|
+
Object.defineProperty(this, "shard", {
|
|
6
|
+
value: shard,
|
|
7
|
+
configurable: false,
|
|
8
|
+
enumerable: false,
|
|
9
|
+
writable: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = Compressor;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
9
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires, unicorn/prefer-module */
|
|
10
|
+
const CompressionConfigs = {
|
|
11
|
+
"zlib-stream": [
|
|
12
|
+
{
|
|
13
|
+
name: "zlib-sync",
|
|
14
|
+
check: (client) => client.util._isModuleInstalled("zlib-sync"),
|
|
15
|
+
getClass: () => require(node_path_1.default.join(__dirname, "zlib-sync")).default,
|
|
16
|
+
getError: () => new Errors_1.DependencyError("zlib-sync based zlib-stream compression is not available: zlib-sync is not installed")
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "pako",
|
|
20
|
+
check: (client) => client.util._isModuleInstalled("pako"),
|
|
21
|
+
getClass: () => require(node_path_1.default.join(__dirname, "pako")).default,
|
|
22
|
+
getError: () => new Errors_1.DependencyError("pako based zlib-stream compression is not available: pako is not installed")
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "native",
|
|
26
|
+
check: (_client) => "createInflate" in node_zlib_1.default,
|
|
27
|
+
getClass: () => require(node_path_1.default.join(__dirname, "zlib-native")).default,
|
|
28
|
+
getError: () => new Errors_1.DependencyError("native zlib-stream compression is not available: zlib.createInflate does not exist")
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"zstd-stream": [
|
|
32
|
+
{
|
|
33
|
+
name: "zstd-napi",
|
|
34
|
+
check: (client) => client.util._isModuleInstalled("zstd-napi"),
|
|
35
|
+
getClass: () => require(node_path_1.default.join(__dirname, "zstd-napi")).default,
|
|
36
|
+
getError: () => new Errors_1.DependencyError("zstd-napi based zstd-stream compression is not available: zstd-napi is not installed")
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "native",
|
|
40
|
+
check: (_client) => "createZstdDecompress" in node_zlib_1.default,
|
|
41
|
+
getClass: () => require(node_path_1.default.join(__dirname, "zstd-native")).default,
|
|
42
|
+
getError: () => new Errors_1.DependencyError("native zstd-stream compression is not available: zlib.createZstdDecompress does not exist")
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
/* eslint-enable @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unused-vars */
|
|
47
|
+
exports.default = CompressionConfigs;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
const base_1 = __importDefault(require("./base.cjs"));
|
|
7
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
8
|
+
const pako_1 = require("pako");
|
|
9
|
+
class PakoCompression extends base_1.default {
|
|
10
|
+
constructor(shard) {
|
|
11
|
+
super(shard);
|
|
12
|
+
this._sharedZLib = new pako_1.Inflate({ chunkSize: 128 * 1024 });
|
|
13
|
+
}
|
|
14
|
+
async decompress(data) {
|
|
15
|
+
if (data.length >= 4 && data.readUInt32BE(data.length - 4) === 0xFFFF) {
|
|
16
|
+
// store the current pointer for slicing buffers after pushing.
|
|
17
|
+
const currentPointer = this._sharedZLib.strm?.next_out;
|
|
18
|
+
this._sharedZLib.push(data, pako_1.constants.Z_SYNC_FLUSH);
|
|
19
|
+
if (this._sharedZLib.err) {
|
|
20
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`zlib error ${this._sharedZLib.err}: ${this._sharedZLib.msg ?? ""}`, 0));
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (this._sharedZLib.chunks.length === 0) {
|
|
24
|
+
// The current buffer hasn't been flushed
|
|
25
|
+
data = Buffer.from(this._sharedZLib.strm.output.slice(currentPointer));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Buffers have been flushed one or more times
|
|
29
|
+
data = Buffer.concat([
|
|
30
|
+
this._sharedZLib.chunks[0].slice(currentPointer),
|
|
31
|
+
...this._sharedZLib.chunks.slice(1),
|
|
32
|
+
this._sharedZLib.strm.output
|
|
33
|
+
]);
|
|
34
|
+
this._sharedZLib.chunks = [];
|
|
35
|
+
}
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this._sharedZLib.push(data, false);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = PakoCompression;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const base_1 = __importDefault(require("./base.cjs"));
|
|
7
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
8
|
+
const node_zlib_1 = require("node:zlib");
|
|
9
|
+
class ZlibNativeCompressor extends base_1.default {
|
|
10
|
+
constructor(shard) {
|
|
11
|
+
super(shard);
|
|
12
|
+
this._chunks = [];
|
|
13
|
+
this._decompressQueue = Promise.resolve();
|
|
14
|
+
this.stream = (0, node_zlib_1.createInflate)();
|
|
15
|
+
this.stream.on("error", err => {
|
|
16
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`zlib error: ${String(err)}`, 0));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async decompress(data) {
|
|
20
|
+
const isComplete = data.length >= 4 && data.readUInt32BE(data.length - 4) === 0xFFFF;
|
|
21
|
+
let result = null;
|
|
22
|
+
this._decompressQueue = this._decompressQueue.then(async () => new Promise(resolve => {
|
|
23
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
24
|
+
const onData = (chunk) => {
|
|
25
|
+
this._chunks.push(chunk);
|
|
26
|
+
};
|
|
27
|
+
this.stream.on("data", onData);
|
|
28
|
+
this.stream.write(data, error => {
|
|
29
|
+
this.stream.off("data", onData);
|
|
30
|
+
if (error) {
|
|
31
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`Failed to decompress zlib: ${String(error)}`, 0));
|
|
32
|
+
result = null;
|
|
33
|
+
resolve();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (isComplete) {
|
|
37
|
+
result = this._chunks.length === 0 ? null : Buffer.concat(this._chunks);
|
|
38
|
+
this._chunks = [];
|
|
39
|
+
}
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
await this._decompressQueue;
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.default = ZlibNativeCompressor;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
const base_1 = __importDefault(require("./base.cjs"));
|
|
7
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
8
|
+
const zlib_sync_1 = __importDefault(require("zlib-sync"));
|
|
9
|
+
class ZlibSyncCompressor extends base_1.default {
|
|
10
|
+
constructor(shard) {
|
|
11
|
+
super(shard);
|
|
12
|
+
this._sharedZLib = new zlib_sync_1.default.Inflate({ chunkSize: 128 * 1024 });
|
|
13
|
+
}
|
|
14
|
+
async decompress(data) {
|
|
15
|
+
if (data.length >= 4 && data.readUInt32BE(data.length - 4) === 0xFFFF) {
|
|
16
|
+
// store the current pointer for slicing buffers after pushing.
|
|
17
|
+
this._sharedZLib.push(data, zlib_sync_1.default.Z_SYNC_FLUSH);
|
|
18
|
+
if (this._sharedZLib.err) {
|
|
19
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`zlib error ${this._sharedZLib.err}: ${this._sharedZLib.msg ?? ""}`, 0));
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
data = Buffer.isBuffer(this._sharedZLib.result) ? this._sharedZLib.result : Buffer.from(this._sharedZLib.result ?? "");
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this._sharedZLib.push(data, false);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = ZlibSyncCompressor;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 base_1 = __importDefault(require("./base.cjs"));
|
|
48
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
49
|
+
const zstd = __importStar(require("zstd-napi"));
|
|
50
|
+
class ZstdCompressor extends base_1.default {
|
|
51
|
+
constructor(shard) {
|
|
52
|
+
super(shard);
|
|
53
|
+
this._decompressQueue = Promise.resolve();
|
|
54
|
+
this.stream = new zstd.DecompressStream();
|
|
55
|
+
}
|
|
56
|
+
async decompress(data) {
|
|
57
|
+
let result = null;
|
|
58
|
+
this._decompressQueue = this._decompressQueue.then(async () => await new Promise(resolve => {
|
|
59
|
+
const chunks = [];
|
|
60
|
+
const onData = (chunk) => {
|
|
61
|
+
chunks.push(chunk);
|
|
62
|
+
};
|
|
63
|
+
this.stream.on("data", onData);
|
|
64
|
+
this.stream.write(data, "binary", error => {
|
|
65
|
+
this.stream.off("data", onData);
|
|
66
|
+
if (error) {
|
|
67
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`Failed to decompress zstd: ${String(error)}`, 0));
|
|
68
|
+
result = null;
|
|
69
|
+
resolve();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
result = chunks.length === 0 ? null : Buffer.concat(chunks);
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
}));
|
|
76
|
+
await this._decompressQueue;
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = ZstdCompressor;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
|
|
7
|
+
const base_1 = __importDefault(require("./base.cjs"));
|
|
8
|
+
const Errors_1 = require("../../util/Errors.cjs");
|
|
9
|
+
// @ts-ignore only in node >=22.15.0
|
|
10
|
+
const node_zlib_1 = require("node:zlib");
|
|
11
|
+
class ZstdNativeCompressor extends base_1.default {
|
|
12
|
+
constructor(shard) {
|
|
13
|
+
super(shard);
|
|
14
|
+
this._decompressQueue = Promise.resolve();
|
|
15
|
+
this.stream = (0, node_zlib_1.createZstdDecompress)({ chunkSize: 65535 });
|
|
16
|
+
// @ts-ignore only in node >=22.15.0
|
|
17
|
+
this.stream.on("error", err => {
|
|
18
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`zstd error: ${String(err)}`, 0));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async decompress(data) {
|
|
22
|
+
let result = null;
|
|
23
|
+
this._decompressQueue = this._decompressQueue.then(async () => await new Promise(resolve => {
|
|
24
|
+
const chunks = [];
|
|
25
|
+
const onData = (chunk) => {
|
|
26
|
+
chunks.push(chunk);
|
|
27
|
+
};
|
|
28
|
+
this.stream.on("data", onData);
|
|
29
|
+
// @ts-ignore only in node >=22.15.0
|
|
30
|
+
this.stream.write(data, "binary", error => {
|
|
31
|
+
this.stream.off("data", onData);
|
|
32
|
+
if (error) {
|
|
33
|
+
this.shard.client.emit("error", new Errors_1.GatewayError(`Failed to decompress zstd: ${String(error)}`, 0));
|
|
34
|
+
result = null;
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
result = chunks.length === 0 ? null : Buffer.concat(chunks);
|
|
39
|
+
resolve();
|
|
40
|
+
});
|
|
41
|
+
}));
|
|
42
|
+
await this._decompressQueue;
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = ZstdNativeCompressor;
|