seyfert 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +57 -0
- package/lib/api/CDN.d.ts +220 -0
- package/lib/api/CDN.js +236 -0
- package/lib/api/REST.d.ts +127 -0
- package/lib/api/REST.js +424 -0
- package/lib/api/Router.d.ts +17 -0
- package/lib/api/Router.js +63 -0
- package/lib/api/Routes/applications.d.ts +46 -0
- package/lib/api/Routes/applications.js +2 -0
- package/lib/api/Routes/cdn.d.ts +66 -0
- package/lib/api/Routes/cdn.js +2 -0
- package/lib/api/Routes/channels.d.ts +109 -0
- package/lib/api/Routes/channels.js +2 -0
- package/lib/api/Routes/gateway.d.ts +11 -0
- package/lib/api/Routes/gateway.js +2 -0
- package/lib/api/Routes/guilds.d.ts +171 -0
- package/lib/api/Routes/guilds.js +2 -0
- package/lib/api/Routes/index.d.ts +13 -0
- package/lib/api/Routes/index.js +17 -0
- package/lib/api/Routes/interactions.d.ts +14 -0
- package/lib/api/Routes/interactions.js +2 -0
- package/lib/api/Routes/invites.d.ts +9 -0
- package/lib/api/Routes/invites.js +2 -0
- package/lib/api/Routes/stage-instances.d.ts +13 -0
- package/lib/api/Routes/stage-instances.js +2 -0
- package/lib/api/Routes/stickers.d.ts +11 -0
- package/lib/api/Routes/stickers.js +2 -0
- package/lib/api/Routes/users.d.ts +35 -0
- package/lib/api/Routes/users.js +2 -0
- package/lib/api/Routes/voice.d.ts +10 -0
- package/lib/api/Routes/voice.js +2 -0
- package/lib/api/Routes/webhooks.d.ts +29 -0
- package/lib/api/Routes/webhooks.js +2 -0
- package/lib/api/errors/DiscordAPIError.d.ts +51 -0
- package/lib/api/errors/DiscordAPIError.js +81 -0
- package/lib/api/errors/HTTPError.d.ts +20 -0
- package/lib/api/errors/HTTPError.js +28 -0
- package/lib/api/errors/RateLimitError.d.ts +19 -0
- package/lib/api/errors/RateLimitError.js +37 -0
- package/lib/api/handlers/BurstHandler.d.ts +51 -0
- package/lib/api/handlers/BurstHandler.js +124 -0
- package/lib/api/handlers/SequentialHandler.d.ts +81 -0
- package/lib/api/handlers/SequentialHandler.js +365 -0
- package/lib/api/handlers/Shared.d.ts +14 -0
- package/lib/api/handlers/Shared.js +125 -0
- package/lib/api/index.d.ts +5 -0
- package/lib/api/index.js +21 -0
- package/lib/api/interfaces/Handler.d.ts +21 -0
- package/lib/api/interfaces/Handler.js +2 -0
- package/lib/api/shared.d.ts +7 -0
- package/lib/api/shared.js +27 -0
- package/lib/api/utils/constants.d.ts +39 -0
- package/lib/api/utils/constants.js +50 -0
- package/lib/api/utils/types.d.ts +335 -0
- package/lib/api/utils/types.js +14 -0
- package/lib/api/utils/utils.d.ts +52 -0
- package/lib/api/utils/utils.js +159 -0
- package/lib/builders/ActionRow.d.ts +40 -0
- package/lib/builders/ActionRow.js +58 -0
- package/lib/builders/Attachment.d.ts +106 -0
- package/lib/builders/Attachment.js +196 -0
- package/lib/builders/Base.d.ts +10 -0
- package/lib/builders/Base.js +13 -0
- package/lib/builders/Button.d.ts +59 -0
- package/lib/builders/Button.js +94 -0
- package/lib/builders/MessageEmbed.d.ts +116 -0
- package/lib/builders/MessageEmbed.js +159 -0
- package/lib/builders/Modal.d.ts +111 -0
- package/lib/builders/Modal.js +162 -0
- package/lib/builders/SelectMenu.d.ts +201 -0
- package/lib/builders/SelectMenu.js +293 -0
- package/lib/builders/index.d.ts +12 -0
- package/lib/builders/index.js +54 -0
- package/lib/builders/types.d.ts +21 -0
- package/lib/builders/types.js +2 -0
- package/lib/cache/adapters/default.d.ts +24 -0
- package/lib/cache/adapters/default.js +118 -0
- package/lib/cache/adapters/index.d.ts +4 -0
- package/lib/cache/adapters/index.js +20 -0
- package/lib/cache/adapters/redis.d.ts +35 -0
- package/lib/cache/adapters/redis.js +180 -0
- package/lib/cache/adapters/types.d.ts +25 -0
- package/lib/cache/adapters/types.js +2 -0
- package/lib/cache/adapters/workeradapter.d.ts +24 -0
- package/lib/cache/adapters/workeradapter.js +76 -0
- package/lib/cache/index.d.ts +97 -0
- package/lib/cache/index.js +394 -0
- package/lib/cache/resources/channels.d.ts +7 -0
- package/lib/cache/resources/channels.js +20 -0
- package/lib/cache/resources/default/base.d.ts +25 -0
- package/lib/cache/resources/default/base.js +75 -0
- package/lib/cache/resources/default/guild-based.d.ts +33 -0
- package/lib/cache/resources/default/guild-based.js +91 -0
- package/lib/cache/resources/default/guild-related.d.ts +32 -0
- package/lib/cache/resources/default/guild-related.js +102 -0
- package/lib/cache/resources/emojis.d.ts +7 -0
- package/lib/cache/resources/emojis.js +17 -0
- package/lib/cache/resources/guilds.d.ts +10 -0
- package/lib/cache/resources/guilds.js +117 -0
- package/lib/cache/resources/members.d.ts +10 -0
- package/lib/cache/resources/members.js +41 -0
- package/lib/cache/resources/presence.d.ts +9 -0
- package/lib/cache/resources/presence.js +14 -0
- package/lib/cache/resources/roles.d.ts +7 -0
- package/lib/cache/resources/roles.js +17 -0
- package/lib/cache/resources/stage-instances.d.ts +5 -0
- package/lib/cache/resources/stage-instances.js +8 -0
- package/lib/cache/resources/stickers.d.ts +7 -0
- package/lib/cache/resources/stickers.js +17 -0
- package/lib/cache/resources/threads.d.ts +7 -0
- package/lib/cache/resources/threads.js +17 -0
- package/lib/cache/resources/users.d.ts +7 -0
- package/lib/cache/resources/users.js +17 -0
- package/lib/cache/resources/voice-states.d.ts +9 -0
- package/lib/cache/resources/voice-states.js +13 -0
- package/lib/client/base.d.ts +244 -0
- package/lib/client/base.js +178 -0
- package/lib/client/client.d.ts +32 -0
- package/lib/client/client.js +156 -0
- package/lib/client/httpclient.d.ts +21 -0
- package/lib/client/httpclient.js +143 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +19 -0
- package/lib/client/oninteraction.d.ts +4 -0
- package/lib/client/oninteraction.js +180 -0
- package/lib/client/workerclient.d.ts +28 -0
- package/lib/client/workerclient.js +213 -0
- package/lib/collection.d.ts +233 -0
- package/lib/collection.js +371 -0
- package/lib/commands/applications/chat.d.ts +139 -0
- package/lib/commands/applications/chat.js +173 -0
- package/lib/commands/applications/chatcontext.d.ts +28 -0
- package/lib/commands/applications/chatcontext.js +53 -0
- package/lib/commands/applications/menu.d.ts +39 -0
- package/lib/commands/applications/menu.js +87 -0
- package/lib/commands/applications/menucontext.d.ts +25 -0
- package/lib/commands/applications/menucontext.js +64 -0
- package/lib/commands/applications/options.d.ts +67 -0
- package/lib/commands/applications/options.js +44 -0
- package/lib/commands/applications/shared.d.ts +35 -0
- package/lib/commands/applications/shared.js +2 -0
- package/lib/commands/decorators.d.ts +107 -0
- package/lib/commands/decorators.js +85 -0
- package/lib/commands/handler.d.ts +15 -0
- package/lib/commands/handler.js +140 -0
- package/lib/commands/index.d.ts +8 -0
- package/lib/commands/index.js +24 -0
- package/lib/commands/optionresolver.d.ts +49 -0
- package/lib/commands/optionresolver.js +146 -0
- package/lib/common/bot/watcher.d.ts +53 -0
- package/lib/common/bot/watcher.js +104 -0
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.js +30 -0
- package/lib/common/it/colors.d.ts +274 -0
- package/lib/common/it/colors.js +453 -0
- package/lib/common/it/constants.d.ts +36 -0
- package/lib/common/it/constants.js +40 -0
- package/lib/common/it/logger.d.ts +114 -0
- package/lib/common/it/logger.js +189 -0
- package/lib/common/it/utils.d.ts +107 -0
- package/lib/common/it/utils.js +275 -0
- package/lib/common/shorters/base.d.ts +5 -0
- package/lib/common/shorters/base.js +10 -0
- package/lib/common/shorters/channels.d.ts +90 -0
- package/lib/common/shorters/channels.js +95 -0
- package/lib/common/shorters/guilds.d.ts +389 -0
- package/lib/common/shorters/guilds.js +350 -0
- package/lib/common/shorters/members.d.ts +115 -0
- package/lib/common/shorters/members.js +179 -0
- package/lib/common/shorters/messages.d.ts +27 -0
- package/lib/common/shorters/messages.js +117 -0
- package/lib/common/shorters/roles.d.ts +12 -0
- package/lib/common/shorters/roles.js +51 -0
- package/lib/common/shorters/templates.d.ts +12 -0
- package/lib/common/shorters/templates.js +29 -0
- package/lib/common/shorters/users.d.ts +11 -0
- package/lib/common/shorters/users.js +42 -0
- package/lib/common/shorters/webhook.d.ts +33 -0
- package/lib/common/shorters/webhook.js +69 -0
- package/lib/common/types/options.d.ts +10 -0
- package/lib/common/types/options.js +2 -0
- package/lib/common/types/resolvables.d.ts +10 -0
- package/lib/common/types/resolvables.js +2 -0
- package/lib/common/types/util.d.ts +90 -0
- package/lib/common/types/util.js +2 -0
- package/lib/common/types/write.d.ts +21 -0
- package/lib/common/types/write.js +2 -0
- package/lib/components/ActionRow.d.ts +10 -0
- package/lib/components/ActionRow.js +13 -0
- package/lib/components/ButtonComponent.d.ts +19 -0
- package/lib/components/ButtonComponent.js +34 -0
- package/lib/components/ChannelSelectMenuComponent.d.ts +6 -0
- package/lib/components/ChannelSelectMenuComponent.js +12 -0
- package/lib/components/MentionableSelectMenuComponent.d.ts +4 -0
- package/lib/components/MentionableSelectMenuComponent.js +7 -0
- package/lib/components/RoleSelectMenuComponent.d.ts +4 -0
- package/lib/components/RoleSelectMenuComponent.js +7 -0
- package/lib/components/StringSelectMenuComponent.d.ts +6 -0
- package/lib/components/StringSelectMenuComponent.js +12 -0
- package/lib/components/TextInputComponent.d.ts +7 -0
- package/lib/components/TextInputComponent.js +14 -0
- package/lib/components/UserSelectMenuComponent.d.ts +4 -0
- package/lib/components/UserSelectMenuComponent.js +7 -0
- package/lib/components/command.d.ts +23 -0
- package/lib/components/command.js +15 -0
- package/lib/components/handler.d.ts +48 -0
- package/lib/components/handler.js +231 -0
- package/lib/components/index.d.ts +20 -0
- package/lib/components/index.js +55 -0
- package/lib/components/listener.d.ts +11 -0
- package/lib/components/listener.js +18 -0
- package/lib/events/event.d.ts +23 -0
- package/lib/events/event.js +2 -0
- package/lib/events/handler.d.ts +19 -0
- package/lib/events/handler.js +112 -0
- package/lib/events/hooks/application_command.d.ts +12 -0
- package/lib/events/hooks/application_command.js +8 -0
- package/lib/events/hooks/auto_moderation.d.ts +22 -0
- package/lib/events/hooks/auto_moderation.js +21 -0
- package/lib/events/hooks/channel.d.ts +11 -0
- package/lib/events/hooks/channel.js +24 -0
- package/lib/events/hooks/custom.d.ts +4 -0
- package/lib/events/hooks/custom.js +11 -0
- package/lib/events/hooks/dispatch.d.ts +5 -0
- package/lib/events/hooks/dispatch.js +12 -0
- package/lib/events/hooks/entitlement.d.ts +35 -0
- package/lib/events/hooks/entitlement.js +16 -0
- package/lib/events/hooks/guild.d.ts +228 -0
- package/lib/events/hooks/guild.js +101 -0
- package/lib/events/hooks/index.d.ts +23 -0
- package/lib/events/hooks/index.js +34 -0
- package/lib/events/hooks/integration.d.ts +94 -0
- package/lib/events/hooks/integration.js +27 -0
- package/lib/events/hooks/interactions.d.ts +4 -0
- package/lib/events/hooks/interactions.js +8 -0
- package/lib/events/hooks/invite.d.ts +21 -0
- package/lib/events/hooks/invite.js +12 -0
- package/lib/events/hooks/message.d.ts +69 -0
- package/lib/events/hooks/message.js +37 -0
- package/lib/events/hooks/presence.d.ts +27 -0
- package/lib/events/hooks/presence.js +8 -0
- package/lib/events/hooks/stage.d.ts +29 -0
- package/lib/events/hooks/stage.js +16 -0
- package/lib/events/hooks/thread.d.ts +198 -0
- package/lib/events/hooks/thread.js +29 -0
- package/lib/events/hooks/typing.d.ts +16 -0
- package/lib/events/hooks/typing.js +14 -0
- package/lib/events/hooks/user.d.ts +4 -0
- package/lib/events/hooks/user.js +8 -0
- package/lib/events/hooks/voice.d.ts +37 -0
- package/lib/events/hooks/voice.js +18 -0
- package/lib/events/hooks/webhook.d.ts +6 -0
- package/lib/events/hooks/webhook.js +8 -0
- package/lib/events/index.d.ts +2 -0
- package/lib/events/index.js +18 -0
- package/lib/index.d.ts +79 -0
- package/lib/index.js +104 -0
- package/lib/langs/handler.d.ts +11 -0
- package/lib/langs/handler.js +34 -0
- package/lib/langs/index.d.ts +2 -0
- package/lib/langs/index.js +18 -0
- package/lib/langs/router.d.ts +18 -0
- package/lib/langs/router.js +42 -0
- package/lib/structures/AnonymousGuild.d.ts +7 -0
- package/lib/structures/AnonymousGuild.js +11 -0
- package/lib/structures/AutoModerationRule.d.ts +22 -0
- package/lib/structures/AutoModerationRule.js +34 -0
- package/lib/structures/ClientUser.d.ts +25 -0
- package/lib/structures/ClientUser.js +52 -0
- package/lib/structures/Guild.d.ts +86 -0
- package/lib/structures/Guild.js +66 -0
- package/lib/structures/GuildEmoji.d.ts +29 -0
- package/lib/structures/GuildEmoji.js +47 -0
- package/lib/structures/GuildMember.d.ts +92 -0
- package/lib/structures/GuildMember.js +137 -0
- package/lib/structures/GuildPreview.d.ts +10 -0
- package/lib/structures/GuildPreview.js +14 -0
- package/lib/structures/GuildRole.d.ts +21 -0
- package/lib/structures/GuildRole.js +32 -0
- package/lib/structures/GuildTemplate.d.ts +23 -0
- package/lib/structures/GuildTemplate.js +36 -0
- package/lib/structures/Interaction.d.ts +152 -0
- package/lib/structures/Interaction.js +409 -0
- package/lib/structures/Message.d.ts +53 -0
- package/lib/structures/Message.js +123 -0
- package/lib/structures/Sticker.d.ts +27 -0
- package/lib/structures/Sticker.js +44 -0
- package/lib/structures/User.d.ts +20 -0
- package/lib/structures/User.js +37 -0
- package/lib/structures/Webhook.d.ts +42 -0
- package/lib/structures/Webhook.js +63 -0
- package/lib/structures/channels.d.ts +232 -0
- package/lib/structures/channels.js +366 -0
- package/lib/structures/extra/Base.d.ts +7 -0
- package/lib/structures/extra/Base.js +39 -0
- package/lib/structures/extra/BaseComponent.d.ts +9 -0
- package/lib/structures/extra/BaseComponent.js +12 -0
- package/lib/structures/extra/BaseGuild.d.ts +40 -0
- package/lib/structures/extra/BaseGuild.js +71 -0
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +9 -0
- package/lib/structures/extra/BaseSelectMenuComponent.js +13 -0
- package/lib/structures/extra/BitField.d.ts +14 -0
- package/lib/structures/extra/BitField.js +56 -0
- package/lib/structures/extra/DiscordBase.d.ts +18 -0
- package/lib/structures/extra/DiscordBase.js +28 -0
- package/lib/structures/extra/Permissions.d.ts +54 -0
- package/lib/structures/extra/Permissions.js +9 -0
- package/lib/structures/extra/functions.d.ts +11 -0
- package/lib/structures/extra/functions.js +69 -0
- package/lib/structures/index.d.ts +15 -0
- package/lib/structures/index.js +31 -0
- package/lib/websocket/SharedTypes.d.ts +128 -0
- package/lib/websocket/SharedTypes.js +2 -0
- package/lib/websocket/constants/index.d.ts +26 -0
- package/lib/websocket/constants/index.js +31 -0
- package/lib/websocket/discord/basesocket.d.ts +12 -0
- package/lib/websocket/discord/basesocket.js +37 -0
- package/lib/websocket/discord/events/memberUpdate.d.ts +16 -0
- package/lib/websocket/discord/events/memberUpdate.js +47 -0
- package/lib/websocket/discord/events/presenceUpdate.d.ts +24 -0
- package/lib/websocket/discord/events/presenceUpdate.js +46 -0
- package/lib/websocket/discord/handlemessage.d.ts +0 -0
- package/lib/websocket/discord/handlemessage.js +1 -0
- package/lib/websocket/discord/index.d.ts +4 -0
- package/lib/websocket/discord/index.js +20 -0
- package/lib/websocket/discord/memberUpdate.d.ts +16 -0
- package/lib/websocket/discord/memberUpdate.js +47 -0
- package/lib/websocket/discord/shard.d.ts +46 -0
- package/lib/websocket/discord/shard.js +278 -0
- package/lib/websocket/discord/sharder.d.ts +25 -0
- package/lib/websocket/discord/sharder.js +153 -0
- package/lib/websocket/discord/shared.d.ts +99 -0
- package/lib/websocket/discord/shared.js +8 -0
- package/lib/websocket/discord/worker.d.ts +43 -0
- package/lib/websocket/discord/worker.js +2 -0
- package/lib/websocket/discord/workermanager.d.ts +69 -0
- package/lib/websocket/discord/workermanager.js +273 -0
- package/lib/websocket/index.d.ts +3 -0
- package/lib/websocket/index.js +19 -0
- package/lib/websocket/structures/index.d.ts +117 -0
- package/lib/websocket/structures/index.js +261 -0
- package/lib/websocket/structures/timeout.d.ts +20 -0
- package/lib/websocket/structures/timeout.js +75 -0
- package/package.json +70 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SequentialBucket = exports.PriorityQueue = exports.LinkedList = exports.Queue = exports.PNode = exports.TNode = exports.DynamicBucket = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
/**
|
|
6
|
+
* generally useless for interaction based bots
|
|
7
|
+
* ideally this would only be triggered on certain paths
|
|
8
|
+
* example: a huge amount of messages being spammed
|
|
9
|
+
*
|
|
10
|
+
* a dynamic bucket is just a priority queue implemented using linked lists
|
|
11
|
+
* we create an empty bucket for every path
|
|
12
|
+
* dynamically allocating memory improves the final memory footprint
|
|
13
|
+
*/
|
|
14
|
+
class DynamicBucket {
|
|
15
|
+
limit;
|
|
16
|
+
refillInterval;
|
|
17
|
+
refillAmount;
|
|
18
|
+
/** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */
|
|
19
|
+
queue = new PriorityQueue();
|
|
20
|
+
/** The amount of requests that have been used up already. */
|
|
21
|
+
used = 0;
|
|
22
|
+
/** Whether or not the queue is already processing. */
|
|
23
|
+
processing = false;
|
|
24
|
+
/** The timeout id for the timer to reduce the used amount by the refill amount. */
|
|
25
|
+
timeoutId;
|
|
26
|
+
/** The timestamp in milliseconds when the next refill is scheduled. */
|
|
27
|
+
refillsAt;
|
|
28
|
+
debugger;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.limit = options.limit;
|
|
31
|
+
this.refillInterval = options.refillInterval;
|
|
32
|
+
this.refillAmount = options.refillAmount;
|
|
33
|
+
if (options.debugger) {
|
|
34
|
+
this.debugger = options.debugger;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get remaining() {
|
|
38
|
+
if (this.limit < this.used) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
return this.limit - this.used;
|
|
42
|
+
}
|
|
43
|
+
refill() {
|
|
44
|
+
// Lower the used amount by the refill amount
|
|
45
|
+
this.used = this.refillAmount > this.used ? 0 : this.used - this.refillAmount;
|
|
46
|
+
// Reset the refillsAt timestamp since it just got refilled
|
|
47
|
+
this.refillsAt = undefined;
|
|
48
|
+
if (this.used > 0) {
|
|
49
|
+
if (this.timeoutId) {
|
|
50
|
+
clearTimeout(this.timeoutId);
|
|
51
|
+
}
|
|
52
|
+
this.timeoutId = setTimeout(() => {
|
|
53
|
+
this.refill();
|
|
54
|
+
}, this.refillInterval);
|
|
55
|
+
this.refillsAt = Date.now() + this.refillInterval;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Begin processing the queue. */
|
|
59
|
+
async processQueue() {
|
|
60
|
+
// There is already a queue that is processing
|
|
61
|
+
if (this.processing) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Begin going through the queue.
|
|
65
|
+
while (!this.queue.isEmpty()) {
|
|
66
|
+
if (this.remaining) {
|
|
67
|
+
this.debugger?.debug(`Processing queue. Remaining: ${this.remaining} Length: ${this.queue.size()}`);
|
|
68
|
+
// Resolves the promise allowing the paused execution of this request to resolve and continue.
|
|
69
|
+
this.queue.peek()();
|
|
70
|
+
this.queue.pop();
|
|
71
|
+
// A request can be made
|
|
72
|
+
this.used++;
|
|
73
|
+
// Create a new timeout for this request if none exists.
|
|
74
|
+
if (!this.timeoutId) {
|
|
75
|
+
this.timeoutId = setTimeout(() => {
|
|
76
|
+
this.refill();
|
|
77
|
+
}, this.refillInterval);
|
|
78
|
+
// Set the time for when this refill will occur.
|
|
79
|
+
this.refillsAt = Date.now() + this.refillInterval;
|
|
80
|
+
}
|
|
81
|
+
// Check if a refill is scheduled, since we have used up all available requests
|
|
82
|
+
}
|
|
83
|
+
else if (this.refillsAt) {
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
// If there is time left until next refill, just delay execution.
|
|
86
|
+
if (this.refillsAt > now) {
|
|
87
|
+
await (0, common_1.delay)(this.refillsAt - now);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Loop has ended mark false so it can restart later when needed
|
|
92
|
+
this.processing = false;
|
|
93
|
+
}
|
|
94
|
+
/** Pauses the execution until the request is available to be made. */
|
|
95
|
+
async acquire(priority) {
|
|
96
|
+
return new Promise(resolve => {
|
|
97
|
+
this.queue.push(resolve, priority);
|
|
98
|
+
void this.processQueue();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
toString() {
|
|
102
|
+
return [...this.queue].toString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.DynamicBucket = DynamicBucket;
|
|
106
|
+
class TNode {
|
|
107
|
+
data;
|
|
108
|
+
next;
|
|
109
|
+
constructor(data) {
|
|
110
|
+
this.data = data;
|
|
111
|
+
this.next = null;
|
|
112
|
+
}
|
|
113
|
+
static null(list) {
|
|
114
|
+
return !list;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.TNode = TNode;
|
|
118
|
+
class PNode extends TNode {
|
|
119
|
+
priority;
|
|
120
|
+
constructor(data, priority) {
|
|
121
|
+
super(data);
|
|
122
|
+
this.priority = priority;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.PNode = PNode;
|
|
126
|
+
class Queue {
|
|
127
|
+
/**
|
|
128
|
+
* O(1)
|
|
129
|
+
*/
|
|
130
|
+
pop() {
|
|
131
|
+
if (TNode.null(this.head)) {
|
|
132
|
+
throw new Error('cannot pop a list without elements');
|
|
133
|
+
}
|
|
134
|
+
return (this.head = this.head.next);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* O(1)
|
|
138
|
+
*/
|
|
139
|
+
peek() {
|
|
140
|
+
if (TNode.null(this.head)) {
|
|
141
|
+
throw new Error('cannot peek an empty list');
|
|
142
|
+
}
|
|
143
|
+
return this.head.data;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* O(n)
|
|
147
|
+
*/
|
|
148
|
+
size() {
|
|
149
|
+
let aux = this.head;
|
|
150
|
+
if (TNode.null(aux)) {
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
let count = 1;
|
|
154
|
+
while (aux.next !== null) {
|
|
155
|
+
count++;
|
|
156
|
+
aux = aux.next;
|
|
157
|
+
}
|
|
158
|
+
return count;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* O(1)
|
|
162
|
+
*/
|
|
163
|
+
isEmpty() {
|
|
164
|
+
return TNode.null(this.head);
|
|
165
|
+
}
|
|
166
|
+
*[Symbol.iterator]() {
|
|
167
|
+
let temp = this.head;
|
|
168
|
+
while (temp !== null) {
|
|
169
|
+
yield temp.data;
|
|
170
|
+
temp = temp.next;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
toArray() {
|
|
174
|
+
return Array.from(this);
|
|
175
|
+
}
|
|
176
|
+
toString() {
|
|
177
|
+
return this.head?.toString() || '';
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.Queue = Queue;
|
|
181
|
+
class LinkedList extends Queue {
|
|
182
|
+
head = null;
|
|
183
|
+
/**
|
|
184
|
+
* O(1)
|
|
185
|
+
*/
|
|
186
|
+
push(data) {
|
|
187
|
+
const temp = new TNode(data);
|
|
188
|
+
temp.next = this.head;
|
|
189
|
+
this.head = temp;
|
|
190
|
+
return this.head;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.LinkedList = LinkedList;
|
|
194
|
+
class PriorityQueue extends Queue {
|
|
195
|
+
head = null;
|
|
196
|
+
/**
|
|
197
|
+
* O(#priorities)
|
|
198
|
+
*/
|
|
199
|
+
push(data, priority) {
|
|
200
|
+
let start = this.head;
|
|
201
|
+
const temp = new PNode(data, priority);
|
|
202
|
+
if (TNode.null(this.head) || TNode.null(start)) {
|
|
203
|
+
this.head = temp;
|
|
204
|
+
return this.head;
|
|
205
|
+
}
|
|
206
|
+
if (this.head.priority > priority) {
|
|
207
|
+
temp.next = this.head;
|
|
208
|
+
this.head = temp;
|
|
209
|
+
return this.head;
|
|
210
|
+
}
|
|
211
|
+
while (start.next !== null && start.next.priority < priority) {
|
|
212
|
+
start = start.next;
|
|
213
|
+
}
|
|
214
|
+
temp.next = start.next;
|
|
215
|
+
start.next = temp;
|
|
216
|
+
return this.head;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.PriorityQueue = PriorityQueue;
|
|
220
|
+
class SequentialBucket {
|
|
221
|
+
connections;
|
|
222
|
+
capacity; // max_concurrency
|
|
223
|
+
spawnTimeout;
|
|
224
|
+
constructor(maxCapacity) {
|
|
225
|
+
this.connections = new LinkedList();
|
|
226
|
+
this.capacity = maxCapacity;
|
|
227
|
+
this.spawnTimeout = 5000;
|
|
228
|
+
}
|
|
229
|
+
async destroy() {
|
|
230
|
+
this.connections = new LinkedList();
|
|
231
|
+
}
|
|
232
|
+
async push(promise) {
|
|
233
|
+
this.connections.push(promise);
|
|
234
|
+
if (this.capacity <= this.connections.size()) {
|
|
235
|
+
await this.acquire();
|
|
236
|
+
await (0, common_1.delay)(this.spawnTimeout);
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
async acquire(promises = this.connections) {
|
|
241
|
+
while (!promises.isEmpty()) {
|
|
242
|
+
const item = promises.peek();
|
|
243
|
+
item().catch((...args) => {
|
|
244
|
+
Promise.reject(...args);
|
|
245
|
+
});
|
|
246
|
+
promises.pop();
|
|
247
|
+
}
|
|
248
|
+
return Promise.resolve(true);
|
|
249
|
+
}
|
|
250
|
+
static chunk(array, chunks) {
|
|
251
|
+
let index = 0;
|
|
252
|
+
let resIndex = 0;
|
|
253
|
+
const result = Array(Math.ceil(array.length / chunks));
|
|
254
|
+
while (index < array.length) {
|
|
255
|
+
result[resIndex] = array.slice(index, (index += chunks));
|
|
256
|
+
resIndex++;
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.SequentialBucket = SequentialBucket;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class ConnectTimeout {
|
|
3
|
+
intervalTime: number;
|
|
4
|
+
readonly promises: ((x: boolean) => any)[];
|
|
5
|
+
protected interval?: NodeJS.Timeout;
|
|
6
|
+
constructor(intervalTime?: number);
|
|
7
|
+
wait(): Promise<boolean>;
|
|
8
|
+
shift(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class ConnectQueue {
|
|
11
|
+
intervalTime: number;
|
|
12
|
+
concurrency: number;
|
|
13
|
+
readonly queue: {
|
|
14
|
+
cb: (() => any) | undefined;
|
|
15
|
+
}[];
|
|
16
|
+
protected interval?: NodeJS.Timeout;
|
|
17
|
+
constructor(intervalTime?: number, concurrency?: number);
|
|
18
|
+
push(callback: () => any): void;
|
|
19
|
+
shift(): any;
|
|
20
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectQueue = exports.ConnectTimeout = void 0;
|
|
4
|
+
class ConnectTimeout {
|
|
5
|
+
intervalTime;
|
|
6
|
+
promises = [];
|
|
7
|
+
interval = undefined;
|
|
8
|
+
constructor(intervalTime = 5000) {
|
|
9
|
+
this.intervalTime = intervalTime;
|
|
10
|
+
}
|
|
11
|
+
wait() {
|
|
12
|
+
let resolve = (_x) => {
|
|
13
|
+
//
|
|
14
|
+
};
|
|
15
|
+
const promise = new Promise(r => (resolve = r));
|
|
16
|
+
if (!this.promises.length) {
|
|
17
|
+
this.interval = setInterval(() => {
|
|
18
|
+
this.shift();
|
|
19
|
+
}, this.intervalTime);
|
|
20
|
+
resolve(true);
|
|
21
|
+
}
|
|
22
|
+
this.promises.push(resolve);
|
|
23
|
+
return promise;
|
|
24
|
+
}
|
|
25
|
+
shift() {
|
|
26
|
+
this.promises.shift()?.(true);
|
|
27
|
+
if (!this.promises.length) {
|
|
28
|
+
clearInterval(this.interval);
|
|
29
|
+
this.interval = undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ConnectTimeout = ConnectTimeout;
|
|
34
|
+
class ConnectQueue {
|
|
35
|
+
intervalTime;
|
|
36
|
+
concurrency;
|
|
37
|
+
queue = [];
|
|
38
|
+
interval = undefined;
|
|
39
|
+
constructor(intervalTime = 5000, concurrency = 1) {
|
|
40
|
+
this.intervalTime = intervalTime;
|
|
41
|
+
this.concurrency = concurrency;
|
|
42
|
+
}
|
|
43
|
+
push(callback) {
|
|
44
|
+
this.queue.push({ cb: callback });
|
|
45
|
+
if (this.queue.length === this.concurrency) {
|
|
46
|
+
for (let i = 0; i < this.concurrency; i++) {
|
|
47
|
+
this.queue[i].cb?.();
|
|
48
|
+
this.queue[i].cb = undefined;
|
|
49
|
+
}
|
|
50
|
+
this.interval = setInterval(() => {
|
|
51
|
+
for (let i = 0; i < this.concurrency; i++) {
|
|
52
|
+
this.shift();
|
|
53
|
+
}
|
|
54
|
+
}, this.intervalTime);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
shift() {
|
|
58
|
+
const shift = this.queue.shift();
|
|
59
|
+
if (!shift) {
|
|
60
|
+
if (!this.queue.length) {
|
|
61
|
+
clearInterval(this.interval);
|
|
62
|
+
this.interval = undefined;
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!shift.cb)
|
|
67
|
+
return this.shift();
|
|
68
|
+
shift.cb?.();
|
|
69
|
+
if (!this.queue.length) {
|
|
70
|
+
clearInterval(this.interval);
|
|
71
|
+
this.interval = undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ConnectQueue = ConnectQueue;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "seyfert",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"module": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc --outDir ./lib",
|
|
12
|
+
"dev": "swc src -d lib -w",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"prepare": "npm run build && husky install",
|
|
15
|
+
"lint": "biome lint --apply ./src",
|
|
16
|
+
"format": "biome format --write ./src",
|
|
17
|
+
"check-h": "biome check --apply ./src",
|
|
18
|
+
"check": "biome check --apply --changed --no-errors-on-unmatched ./src"
|
|
19
|
+
},
|
|
20
|
+
"author": "MARCROCK22",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@sapphire/async-queue": "^1.5.1",
|
|
24
|
+
"chokidar": "^3.5.3",
|
|
25
|
+
"discord-api-types": "^0.37.67",
|
|
26
|
+
"form-data": "^4.0.0",
|
|
27
|
+
"ioredis": "^5.3.2",
|
|
28
|
+
"magic-bytes.js": "^1.7.0",
|
|
29
|
+
"ts-mixer": "^6.0.3",
|
|
30
|
+
"ws": "^8.16.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@biomejs/biome": "1.5.0",
|
|
34
|
+
"@swc/cli": "^0.1.63",
|
|
35
|
+
"@swc/core": "^1.3.102",
|
|
36
|
+
"@types/node": "^20.10.7",
|
|
37
|
+
"@types/ws": "^8.5.10",
|
|
38
|
+
"husky": "^8.0.3",
|
|
39
|
+
"nodemon": "^3.0.2",
|
|
40
|
+
"typescript": "^5.3.3"
|
|
41
|
+
},
|
|
42
|
+
"optionalDependencies": {
|
|
43
|
+
"tweetnacl": "^1.0.3",
|
|
44
|
+
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.39.0"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://biscuitjs.com",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/potoland/potocuit.git"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/potoland/potocuit"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"api",
|
|
56
|
+
"discord",
|
|
57
|
+
"bots",
|
|
58
|
+
"typescript",
|
|
59
|
+
"botdev"
|
|
60
|
+
],
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
},
|
|
64
|
+
"contributors": [
|
|
65
|
+
{
|
|
66
|
+
"name": "socram03",
|
|
67
|
+
"url": "https://github.com/socram03"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|