@ovencord/discord.js 14.16.3
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 +191 -0
- package/README.md +148 -0
- package/package.json +73 -0
- package/src/client/Client.ts +967 -0
- package/src/client/actions/Action.ts +141 -0
- package/src/client/actions/ActionsManager.ts +138 -0
- package/src/client/actions/ChannelCreate.ts +21 -0
- package/src/client/actions/ChannelDelete.ts +20 -0
- package/src/client/actions/ChannelUpdate.ts +38 -0
- package/src/client/actions/GuildChannelsPositionUpdate.ts +17 -0
- package/src/client/actions/GuildEmojiCreate.ts +17 -0
- package/src/client/actions/GuildEmojiDelete.ts +16 -0
- package/src/client/actions/GuildEmojiUpdate.ts +17 -0
- package/src/client/actions/GuildEmojisUpdate.ts +30 -0
- package/src/client/actions/GuildMemberRemove.ts +29 -0
- package/src/client/actions/GuildMemberUpdate.ts +41 -0
- package/src/client/actions/GuildRoleCreate.ts +23 -0
- package/src/client/actions/GuildRoleDelete.ts +26 -0
- package/src/client/actions/GuildRolesPositionUpdate.ts +17 -0
- package/src/client/actions/GuildScheduledEventDelete.ts +28 -0
- package/src/client/actions/GuildScheduledEventUserAdd.ts +29 -0
- package/src/client/actions/GuildScheduledEventUserRemove.ts +29 -0
- package/src/client/actions/GuildSoundboardSoundDelete.ts +26 -0
- package/src/client/actions/GuildStickerCreate.ts +17 -0
- package/src/client/actions/GuildStickerDelete.ts +16 -0
- package/src/client/actions/GuildStickerUpdate.ts +17 -0
- package/src/client/actions/GuildStickersUpdate.ts +30 -0
- package/src/client/actions/GuildUpdate.ts +30 -0
- package/src/client/actions/InteractionCreate.ts +104 -0
- package/src/client/actions/MessageCreate.ts +38 -0
- package/src/client/actions/MessageDelete.ts +29 -0
- package/src/client/actions/MessageDeleteBulk.ts +45 -0
- package/src/client/actions/MessagePollVoteAdd.ts +37 -0
- package/src/client/actions/MessagePollVoteRemove.ts +35 -0
- package/src/client/actions/MessageReactionAdd.ts +68 -0
- package/src/client/actions/MessageReactionRemove.ts +47 -0
- package/src/client/actions/MessageReactionRemoveAll.ts +30 -0
- package/src/client/actions/MessageReactionRemoveEmoji.ts +25 -0
- package/src/client/actions/MessageUpdate.ts +22 -0
- package/src/client/actions/StageInstanceCreate.ts +25 -0
- package/src/client/actions/StageInstanceDelete.ts +28 -0
- package/src/client/actions/StageInstanceUpdate.ts +27 -0
- package/src/client/actions/ThreadCreate.ts +22 -0
- package/src/client/actions/ThreadMembersUpdate.ts +45 -0
- package/src/client/actions/TypingStart.ts +26 -0
- package/src/client/actions/UserUpdate.ts +33 -0
- package/src/client/voice/ClientVoiceManager.ts +46 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.ts +17 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.ts +18 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.ts +21 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.ts +22 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/ENTITLEMENT_CREATE.ts +14 -0
- package/src/client/websocket/handlers/ENTITLEMENT_DELETE.ts +18 -0
- package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.ts +15 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_CREATE.ts +34 -0
- package/src/client/websocket/handlers/GUILD_DELETE.ts +36 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.ts +15 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.ts +40 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.ts +17 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.ts +21 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.ts +17 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.ts +24 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.ts +18 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.ts +4 -0
- package/src/client/websocket/handlers/INVITE_CREATE.ts +20 -0
- package/src/client/websocket/handlers/INVITE_DELETE.ts +23 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.ts +42 -0
- package/src/client/websocket/handlers/RATE_LIMITED.ts +23 -0
- package/src/client/websocket/handlers/READY.ts +29 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.ts +24 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.ts +14 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.ts +16 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/THREAD_CREATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_DELETE.ts +17 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.ts +50 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.ts +25 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/TYPING_START.ts +4 -0
- package/src/client/websocket/handlers/USER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.ts +16 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.ts +5 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.ts +37 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/index.ts +74 -0
- package/src/errors/DJSError.ts +50 -0
- package/src/errors/ErrorCodes.ts +277 -0
- package/src/errors/Messages.ts +155 -0
- package/src/errors/index.ts +6 -0
- package/src/index.ts +241 -0
- package/src/managers/ApplicationCommandManager.ts +303 -0
- package/src/managers/ApplicationCommandPermissionsManager.ts +453 -0
- package/src/managers/ApplicationEmojiManager.ts +149 -0
- package/src/managers/AutoModerationRuleManager.ts +307 -0
- package/src/managers/BaseManager.ts +13 -0
- package/src/managers/CachedManager.ts +56 -0
- package/src/managers/CategoryChannelChildManager.ts +81 -0
- package/src/managers/ChannelManager.ts +194 -0
- package/src/managers/DMMessageManager.ts +15 -0
- package/src/managers/DataManager.ts +38 -0
- package/src/managers/EntitlementManager.ts +182 -0
- package/src/managers/GuildApplicationCommandManager.ts +29 -0
- package/src/managers/GuildBanManager.ts +221 -0
- package/src/managers/GuildChannelManager.ts +552 -0
- package/src/managers/GuildEmojiManager.ts +262 -0
- package/src/managers/GuildEmojiRoleManager.ts +134 -0
- package/src/managers/GuildForumThreadManager.ts +84 -0
- package/src/managers/GuildInviteManager.ts +236 -0
- package/src/managers/GuildManager.ts +265 -0
- package/src/managers/GuildMemberManager.ts +619 -0
- package/src/managers/GuildMemberRoleManager.ts +230 -0
- package/src/managers/GuildMessageManager.ts +31 -0
- package/src/managers/GuildScheduledEventManager.ts +330 -0
- package/src/managers/GuildSoundboardSoundManager.ts +157 -0
- package/src/managers/GuildStickerManager.ts +192 -0
- package/src/managers/GuildTextThreadManager.ts +91 -0
- package/src/managers/MessageManager.ts +352 -0
- package/src/managers/PartialGroupDMMessageManager.ts +15 -0
- package/src/managers/PermissionOverwriteManager.ts +174 -0
- package/src/managers/PollAnswerVoterManager.ts +59 -0
- package/src/managers/PresenceManager.ts +60 -0
- package/src/managers/ReactionManager.ts +72 -0
- package/src/managers/ReactionUserManager.ts +82 -0
- package/src/managers/RoleManager.ts +432 -0
- package/src/managers/StageInstanceManager.ts +166 -0
- package/src/managers/SubscriptionManager.ts +83 -0
- package/src/managers/ThreadManager.ts +210 -0
- package/src/managers/ThreadMemberManager.ts +194 -0
- package/src/managers/UserManager.ts +139 -0
- package/src/managers/VoiceStateManager.ts +61 -0
- package/src/sharding/Shard.ts +513 -0
- package/src/sharding/ShardClientUtil.ts +293 -0
- package/src/sharding/ShardingManager.ts +374 -0
- package/src/structures/ActionRow.ts +31 -0
- package/src/structures/AnnouncementChannel.ts +25 -0
- package/src/structures/AnonymousGuild.ts +110 -0
- package/src/structures/ApplicationCommand.ts +675 -0
- package/src/structures/ApplicationEmoji.ts +189 -0
- package/src/structures/ApplicationRoleConnectionMetadata.ts +54 -0
- package/src/structures/Attachment.ts +189 -0
- package/src/structures/AuthorizingIntegrationOwners.ts +63 -0
- package/src/structures/AutoModerationActionExecution.ts +138 -0
- package/src/structures/AutoModerationRule.ts +325 -0
- package/src/structures/AutocompleteInteraction.ts +115 -0
- package/src/structures/Base.ts +37 -0
- package/src/structures/BaseChannel.ts +188 -0
- package/src/structures/BaseGuild.ts +134 -0
- package/src/structures/BaseGuildEmoji.ts +113 -0
- package/src/structures/BaseGuildTextChannel.ts +230 -0
- package/src/structures/BaseGuildVoiceChannel.ts +270 -0
- package/src/structures/BaseInteraction.ts +393 -0
- package/src/structures/BaseInvite.ts +192 -0
- package/src/structures/BaseSelectMenuComponent.ts +58 -0
- package/src/structures/ButtonComponent.ts +68 -0
- package/src/structures/ButtonInteraction.ts +8 -0
- package/src/structures/CategoryChannel.ts +46 -0
- package/src/structures/ChannelSelectMenuComponent.ts +18 -0
- package/src/structures/ChannelSelectMenuInteraction.ts +34 -0
- package/src/structures/ChatInputCommandInteraction.ts +43 -0
- package/src/structures/ClientApplication.ts +470 -0
- package/src/structures/ClientPresence.ts +87 -0
- package/src/structures/ClientUser.ts +219 -0
- package/src/structures/CommandInteraction.ts +193 -0
- package/src/structures/CommandInteractionOptionResolver.ts +336 -0
- package/src/structures/Component.ts +59 -0
- package/src/structures/ContainerComponent.ts +63 -0
- package/src/structures/ContextMenuCommandInteraction.ts +68 -0
- package/src/structures/DMChannel.ts +148 -0
- package/src/structures/DirectoryChannel.ts +40 -0
- package/src/structures/Embed.ts +251 -0
- package/src/structures/Emoji.ts +61 -0
- package/src/structures/Entitlement.ts +206 -0
- package/src/structures/FileComponent.ts +41 -0
- package/src/structures/ForumChannel.ts +31 -0
- package/src/structures/GroupDMInvite.ts +34 -0
- package/src/structures/Guild.ts +1605 -0
- package/src/structures/GuildAuditLogs.ts +99 -0
- package/src/structures/GuildAuditLogsEntry.ts +557 -0
- package/src/structures/GuildBan.ts +65 -0
- package/src/structures/GuildChannel.ts +515 -0
- package/src/structures/GuildEmoji.ts +159 -0
- package/src/structures/GuildInvite.ts +233 -0
- package/src/structures/GuildMember.ts +643 -0
- package/src/structures/GuildOnboarding.ts +73 -0
- package/src/structures/GuildOnboardingPrompt.ts +93 -0
- package/src/structures/GuildOnboardingPromptOption.ts +100 -0
- package/src/structures/GuildPreview.ts +218 -0
- package/src/structures/GuildPreviewEmoji.ts +28 -0
- package/src/structures/GuildScheduledEvent.ts +593 -0
- package/src/structures/GuildTemplate.ts +229 -0
- package/src/structures/Integration.ts +257 -0
- package/src/structures/IntegrationApplication.ts +84 -0
- package/src/structures/InteractionCallback.ts +86 -0
- package/src/structures/InteractionCallbackResource.ts +57 -0
- package/src/structures/InteractionCallbackResponse.ts +35 -0
- package/src/structures/InteractionCollector.ts +260 -0
- package/src/structures/InteractionWebhook.ts +65 -0
- package/src/structures/InviteGuild.ts +22 -0
- package/src/structures/LabelComponent.ts +51 -0
- package/src/structures/MediaChannel.ts +8 -0
- package/src/structures/MediaGalleryComponent.ts +31 -0
- package/src/structures/MediaGalleryItem.ts +54 -0
- package/src/structures/MentionableSelectMenuComponent.ts +8 -0
- package/src/structures/MentionableSelectMenuInteraction.ts +76 -0
- package/src/structures/Message.ts +1202 -0
- package/src/structures/MessageCollector.ts +155 -0
- package/src/structures/MessageComponentInteraction.ts +132 -0
- package/src/structures/MessageContextMenuCommandInteraction.ts +18 -0
- package/src/structures/MessageMentions.ts +327 -0
- package/src/structures/MessagePayload.ts +325 -0
- package/src/structures/MessageReaction.ts +219 -0
- package/src/structures/ModalComponentResolver.ts +237 -0
- package/src/structures/ModalSubmitInteraction.ts +260 -0
- package/src/structures/OAuth2Guild.ts +30 -0
- package/src/structures/PartialGroupDMChannel.ts +151 -0
- package/src/structures/PermissionOverwrites.ts +222 -0
- package/src/structures/Poll.ts +195 -0
- package/src/structures/PollAnswer.ts +100 -0
- package/src/structures/Presence.ts +448 -0
- package/src/structures/PrimaryEntryPointCommandInteraction.ts +8 -0
- package/src/structures/ReactionCollector.ts +245 -0
- package/src/structures/ReactionEmoji.ts +30 -0
- package/src/structures/Role.ts +543 -0
- package/src/structures/RoleSelectMenuComponent.ts +8 -0
- package/src/structures/RoleSelectMenuInteraction.ts +34 -0
- package/src/structures/SKU.ts +62 -0
- package/src/structures/SectionComponent.ts +44 -0
- package/src/structures/SeparatorComponent.ts +29 -0
- package/src/structures/SoundboardSound.ts +176 -0
- package/src/structures/StageChannel.ts +118 -0
- package/src/structures/StageInstance.ts +173 -0
- package/src/structures/Sticker.ts +300 -0
- package/src/structures/StickerPack.ts +111 -0
- package/src/structures/StringSelectMenuComponent.ts +18 -0
- package/src/structures/StringSelectMenuInteraction.ts +21 -0
- package/src/structures/Subscription.ts +138 -0
- package/src/structures/Team.ts +131 -0
- package/src/structures/TeamMember.ts +77 -0
- package/src/structures/TextChannel.ts +33 -0
- package/src/structures/TextDisplayComponent.ts +18 -0
- package/src/structures/TextInputComponent.ts +28 -0
- package/src/structures/ThreadChannel.ts +680 -0
- package/src/structures/ThreadMember.ts +125 -0
- package/src/structures/ThreadOnlyChannel.ts +276 -0
- package/src/structures/ThumbnailComponent.ts +51 -0
- package/src/structures/Typing.ts +81 -0
- package/src/structures/UnfurledMediaItem.ts +33 -0
- package/src/structures/User.ts +511 -0
- package/src/structures/UserContextMenuCommandInteraction.ts +28 -0
- package/src/structures/UserSelectMenuComponent.ts +8 -0
- package/src/structures/UserSelectMenuInteraction.ts +54 -0
- package/src/structures/VoiceChannel.ts +119 -0
- package/src/structures/VoiceChannelEffect.ts +92 -0
- package/src/structures/VoiceRegion.ts +52 -0
- package/src/structures/VoiceState.ts +346 -0
- package/src/structures/Webhook.ts +526 -0
- package/src/structures/WelcomeChannel.ts +67 -0
- package/src/structures/WelcomeScreen.ts +53 -0
- package/src/structures/Widget.ts +110 -0
- package/src/structures/WidgetMember.ts +124 -0
- package/src/structures/interfaces/Application.ts +179 -0
- package/src/structures/interfaces/Collector.ts +372 -0
- package/src/structures/interfaces/InteractionResponses.ts +384 -0
- package/src/structures/interfaces/TextBasedChannel.ts +430 -0
- package/src/util/APITypes.ts +690 -0
- package/src/util/ActivityFlagsBitField.ts +26 -0
- package/src/util/ApplicationFlagsBitField.ts +43 -0
- package/src/util/AttachmentFlagsBitField.ts +26 -0
- package/src/util/BitField.ts +178 -0
- package/src/util/ChannelFlagsBitField.ts +43 -0
- package/src/util/Channels.ts +165 -0
- package/src/util/Colors.ts +72 -0
- package/src/util/Components.ts +285 -0
- package/src/util/Constants.ts +251 -0
- package/src/util/DataResolver.ts +146 -0
- package/src/util/Enums.ts +10 -0
- package/src/util/Events.ts +178 -0
- package/src/util/GuildMemberFlagsBitField.ts +43 -0
- package/src/util/IntentsBitField.ts +35 -0
- package/src/util/InviteFlagsBitField.ts +26 -0
- package/src/util/Invites.ts +27 -0
- package/src/util/LimitedCollection.ts +73 -0
- package/src/util/MessageFlagsBitField.ts +43 -0
- package/src/util/Options.ts +215 -0
- package/src/util/Partials.ts +50 -0
- package/src/util/PermissionsBitField.ts +113 -0
- package/src/util/RoleFlagsBitField.ts +26 -0
- package/src/util/SKUFlagsBitField.ts +26 -0
- package/src/util/ShardEvents.ts +26 -0
- package/src/util/Status.ts +16 -0
- package/src/util/Sweepers.ts +532 -0
- package/src/util/Symbols.ts +1 -0
- package/src/util/SystemChannelFlagsBitField.ts +45 -0
- package/src/util/ThreadMemberFlagsBitField.ts +33 -0
- package/src/util/Transformers.ts +123 -0
- package/src/util/UserFlagsBitField.ts +33 -0
- package/src/util/Util.ts +519 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { setTimeout, clearTimeout } from 'node:timers';
|
|
2
|
+
import { Collection } from '@ovencord/collection';
|
|
3
|
+
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
|
4
|
+
import { DiscordjsTypeError, ErrorCodes } from '../../errors/index.js';
|
|
5
|
+
import { flatten } from '../../util/Util.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Filter to be applied to the collector.
|
|
9
|
+
*
|
|
10
|
+
* @typedef {Function} CollectorFilter
|
|
11
|
+
* @param {...*} args Any arguments received by the listener
|
|
12
|
+
* @param {Collection} collection The items collected by this collector
|
|
13
|
+
* @returns {boolean|Promise<boolean>}
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Options to be applied to the collector.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {Object} CollectorOptions
|
|
20
|
+
* @property {CollectorFilter} [filter] The filter applied to this collector
|
|
21
|
+
* @property {number} [time] How long to run the collector for in milliseconds
|
|
22
|
+
* @property {number} [idle] How long to stop the collector after inactivity in milliseconds
|
|
23
|
+
* @property {boolean} [dispose=false] Whether to dispose data when it's deleted
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Abstract class for defining a new Collector.
|
|
28
|
+
*
|
|
29
|
+
* @extends {AsyncEventEmitter}
|
|
30
|
+
* @abstract
|
|
31
|
+
*/
|
|
32
|
+
export class Collector extends AsyncEventEmitter {
|
|
33
|
+
public client: any;
|
|
34
|
+
public options: any;
|
|
35
|
+
public collected: any;
|
|
36
|
+
public ended: any;
|
|
37
|
+
public _timeout: any;
|
|
38
|
+
public _idletimeout: any;
|
|
39
|
+
public _endReason: any;
|
|
40
|
+
public lastCollectedTimestamp: any;
|
|
41
|
+
constructor(client, options = {}) {
|
|
42
|
+
super();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The client that instantiated this Collector
|
|
46
|
+
*
|
|
47
|
+
* @name Collector#client
|
|
48
|
+
* @type {Client}
|
|
49
|
+
* @readonly
|
|
50
|
+
*/
|
|
51
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The filter applied to this collector
|
|
55
|
+
*
|
|
56
|
+
* @type {CollectorFilter}
|
|
57
|
+
* @returns {boolean|Promise<boolean>}
|
|
58
|
+
*/
|
|
59
|
+
this.filter = options.filter ?? (() => true);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The options of this collector
|
|
63
|
+
*
|
|
64
|
+
* @type {CollectorOptions}
|
|
65
|
+
*/
|
|
66
|
+
this.options = options;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The items collected by this collector
|
|
70
|
+
*
|
|
71
|
+
* @type {Collection}
|
|
72
|
+
*/
|
|
73
|
+
this.collected = new Collection();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Whether this collector has finished collecting
|
|
77
|
+
*
|
|
78
|
+
* @type {boolean}
|
|
79
|
+
*/
|
|
80
|
+
this.ended = false;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Timeout for cleanup
|
|
84
|
+
*
|
|
85
|
+
* @type {?Timeout}
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
this._timeout = null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Timeout for cleanup due to inactivity
|
|
92
|
+
*
|
|
93
|
+
* @type {?Timeout}
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
this._idletimeout = null;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The reason the collector ended
|
|
100
|
+
*
|
|
101
|
+
* @type {?string}
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
this._endReason = null;
|
|
105
|
+
|
|
106
|
+
if (typeof this.filter !== 'function') {
|
|
107
|
+
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options.filter', 'function');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.handleCollect = this.handleCollect.bind(this);
|
|
111
|
+
this.handleDispose = this.handleDispose.bind(this);
|
|
112
|
+
|
|
113
|
+
if (options.time) this._timeout = setTimeout(() => this.stop('time'), options.time).unref();
|
|
114
|
+
if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref();
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The timestamp at which this collector last collected an item
|
|
118
|
+
*
|
|
119
|
+
* @type {?number}
|
|
120
|
+
*/
|
|
121
|
+
this.lastCollectedTimestamp = null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The Date at which this collector last collected an item
|
|
126
|
+
*
|
|
127
|
+
* @type {?Date}
|
|
128
|
+
*/
|
|
129
|
+
get lastCollectedAt() {
|
|
130
|
+
return this.lastCollectedTimestamp && new Date(this.lastCollectedTimestamp);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Call this to handle an event as a collectable element. Accepts any event data as parameters.
|
|
135
|
+
*
|
|
136
|
+
* @param {...*} args The arguments emitted by the listener
|
|
137
|
+
* @returns {Promise<void>}
|
|
138
|
+
* @emits Collector#collect
|
|
139
|
+
*/
|
|
140
|
+
async handleCollect(...args) {
|
|
141
|
+
const collectedId = await this.collect(...args);
|
|
142
|
+
|
|
143
|
+
if (collectedId) {
|
|
144
|
+
const filterResult = await this.filter(...args, this.collected);
|
|
145
|
+
if (filterResult) {
|
|
146
|
+
this.collected.set(collectedId, args[0]);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Emitted whenever an element is collected.
|
|
150
|
+
*
|
|
151
|
+
* @event Collector#collect
|
|
152
|
+
* @param {...*} args The arguments emitted by the listener
|
|
153
|
+
*/
|
|
154
|
+
this.emit('collect', ...args);
|
|
155
|
+
|
|
156
|
+
this.lastCollectedTimestamp = Date.now();
|
|
157
|
+
if (this._idletimeout) {
|
|
158
|
+
clearTimeout(this._idletimeout);
|
|
159
|
+
this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref();
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
/**
|
|
163
|
+
* Emitted whenever an element is not collected by the collector.
|
|
164
|
+
*
|
|
165
|
+
* @event Collector#ignore
|
|
166
|
+
* @param {...*} args The arguments emitted by the listener
|
|
167
|
+
*/
|
|
168
|
+
this.emit('ignore', ...args);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.checkEnd();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Call this to remove an element from the collection. Accepts any event data as parameters.
|
|
177
|
+
*
|
|
178
|
+
* @param {...*} args The arguments emitted by the listener
|
|
179
|
+
* @returns {Promise<void>}
|
|
180
|
+
* @emits Collector#dispose
|
|
181
|
+
*/
|
|
182
|
+
async handleDispose(...args) {
|
|
183
|
+
if (!this.options.dispose) return;
|
|
184
|
+
|
|
185
|
+
const dispose = this.dispose(...args);
|
|
186
|
+
if (!dispose || !(await this.filter(...args)) || !this.collected.has(dispose)) return;
|
|
187
|
+
this.collected.delete(dispose);
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Emitted whenever an element is disposed of.
|
|
191
|
+
*
|
|
192
|
+
* @event Collector#dispose
|
|
193
|
+
* @param {...*} args The arguments emitted by the listener
|
|
194
|
+
*/
|
|
195
|
+
this.emit('dispose', ...args);
|
|
196
|
+
this.checkEnd();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Returns a promise that resolves with the next collected element;
|
|
201
|
+
* rejects with collected elements if the collector finishes without receiving a next element
|
|
202
|
+
*
|
|
203
|
+
* @type {Promise}
|
|
204
|
+
* @readonly
|
|
205
|
+
*/
|
|
206
|
+
get next() {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
if (this.ended) {
|
|
209
|
+
reject(this.collected);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const cleanup = () => {
|
|
214
|
+
// eslint-disable-next-line no-use-before-define
|
|
215
|
+
this.removeListener('collect', onCollect);
|
|
216
|
+
// eslint-disable-next-line no-use-before-define
|
|
217
|
+
this.removeListener('end', onEnd);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const onCollect = item => {
|
|
221
|
+
cleanup();
|
|
222
|
+
resolve(item);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const onEnd = () => {
|
|
226
|
+
cleanup();
|
|
227
|
+
reject(this.collected);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
this.on('collect', onCollect);
|
|
231
|
+
this.on('end', onEnd);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Stops this collector and emits the `end` event.
|
|
237
|
+
*
|
|
238
|
+
* @param {string} [reason='user'] The reason this collector is ending
|
|
239
|
+
* @emits Collector#end
|
|
240
|
+
*/
|
|
241
|
+
stop(reason = 'user') {
|
|
242
|
+
if (this.ended) return;
|
|
243
|
+
|
|
244
|
+
if (this._timeout) {
|
|
245
|
+
clearTimeout(this._timeout);
|
|
246
|
+
this._timeout = null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (this._idletimeout) {
|
|
250
|
+
clearTimeout(this._idletimeout);
|
|
251
|
+
this._idletimeout = null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
this._endReason = reason;
|
|
255
|
+
this.ended = true;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Emitted when the collector is finished collecting.
|
|
259
|
+
*
|
|
260
|
+
* @event Collector#end
|
|
261
|
+
* @param {Collection} collected The elements collected by the collector
|
|
262
|
+
* @param {string} reason The reason the collector ended
|
|
263
|
+
*/
|
|
264
|
+
this.emit('end', this.collected, reason);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Options used to reset the timeout and idle timer of a {@link Collector}.
|
|
269
|
+
*
|
|
270
|
+
* @typedef {Object} CollectorResetTimerOptions
|
|
271
|
+
* @property {number} [time] How long to run the collector for (in milliseconds)
|
|
272
|
+
* @property {number} [idle] How long to wait to stop the collector after inactivity (in milliseconds)
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Resets the collector's timeout and idle timer.
|
|
277
|
+
*
|
|
278
|
+
* @param {CollectorResetTimerOptions} [options] Options for resetting
|
|
279
|
+
*/
|
|
280
|
+
resetTimer({ time, idle } = {}) {
|
|
281
|
+
if (this._timeout) {
|
|
282
|
+
clearTimeout(this._timeout);
|
|
283
|
+
this._timeout = setTimeout(() => this.stop('time'), time ?? this.options.time).unref();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (this._idletimeout) {
|
|
287
|
+
clearTimeout(this._idletimeout);
|
|
288
|
+
this._idletimeout = setTimeout(() => this.stop('idle'), idle ?? this.options.idle).unref();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Checks whether the collector should end, and if so, ends it.
|
|
294
|
+
*
|
|
295
|
+
* @returns {boolean} Whether the collector ended or not
|
|
296
|
+
*/
|
|
297
|
+
checkEnd() {
|
|
298
|
+
const reason = this.endReason;
|
|
299
|
+
if (reason) this.stop(reason);
|
|
300
|
+
return Boolean(reason);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Allows collectors to be consumed with for-await-of loops
|
|
305
|
+
*
|
|
306
|
+
* @see {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/for-await...of}
|
|
307
|
+
*/
|
|
308
|
+
async *[Symbol.asyncIterator]() {
|
|
309
|
+
const queue = [];
|
|
310
|
+
const onCollect = (...item) => queue.push(item);
|
|
311
|
+
this.on('collect', onCollect);
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
while (queue.length || !this.ended) {
|
|
315
|
+
if (queue.length) {
|
|
316
|
+
yield queue.shift();
|
|
317
|
+
} else {
|
|
318
|
+
await new Promise(resolve => {
|
|
319
|
+
const tick = () => {
|
|
320
|
+
this.removeListener('collect', tick);
|
|
321
|
+
this.removeListener('end', tick);
|
|
322
|
+
resolve();
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
this.on('collect', tick);
|
|
326
|
+
this.on('end', tick);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
} finally {
|
|
331
|
+
this.removeListener('collect', onCollect);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
toJSON() {
|
|
336
|
+
return flatten(this);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The reason this collector has ended with, or null if it hasn't ended yet
|
|
341
|
+
*
|
|
342
|
+
* @type {?string}
|
|
343
|
+
* @readonly
|
|
344
|
+
*/
|
|
345
|
+
get endReason() {
|
|
346
|
+
return this._endReason;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
|
|
351
|
+
* be collected, or returns an object describing the data that should be stored.
|
|
352
|
+
*
|
|
353
|
+
* @see Collector#handleCollect
|
|
354
|
+
* @param {...*} args Any args the event listener emits
|
|
355
|
+
* @returns {?(*|Promise<?*>)} Data to insert into collection, if any
|
|
356
|
+
* @abstract
|
|
357
|
+
*/
|
|
358
|
+
// eslint-disable-next-line no-unused-vars
|
|
359
|
+
collect(...args) {}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Handles incoming events from the `handleDispose`. Returns null if the event should not
|
|
363
|
+
* be disposed, or returns the key that should be removed.
|
|
364
|
+
*
|
|
365
|
+
* @see Collector#handleDispose
|
|
366
|
+
* @param {...*} args Any args the event listener emits
|
|
367
|
+
* @returns {?*} Key to remove from the collection, if any
|
|
368
|
+
* @abstract
|
|
369
|
+
*/
|
|
370
|
+
// eslint-disable-next-line no-unused-vars
|
|
371
|
+
dispose(...args) {}
|
|
372
|
+
}
|