@velliajs/discord 1.0.2 → 1.0.4

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.
Files changed (258) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -3
  3. package/src/client/BaseClient.js +7 -28
  4. package/src/client/Client.js +116 -283
  5. package/src/client/WebhookClient.js +17 -59
  6. package/src/client/actions/Action.js +0 -10
  7. package/src/client/actions/ActionsManager.js +3 -3
  8. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
  9. package/src/client/actions/AutoModerationActionExecution.js +1 -6
  10. package/src/client/actions/AutoModerationRuleCreate.js +1 -6
  11. package/src/client/actions/AutoModerationRuleDelete.js +1 -6
  12. package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
  13. package/src/client/actions/ChannelCreate.js +1 -5
  14. package/src/client/actions/ChannelDelete.js +1 -5
  15. package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
  16. package/src/client/actions/GuildBanAdd.js +1 -5
  17. package/src/client/actions/GuildBanRemove.js +1 -5
  18. package/src/client/actions/GuildDelete.js +6 -14
  19. package/src/client/actions/GuildEmojiCreate.js +1 -5
  20. package/src/client/actions/GuildEmojiDelete.js +1 -5
  21. package/src/client/actions/GuildEmojiUpdate.js +1 -6
  22. package/src/client/actions/GuildEmojisUpdate.js +4 -4
  23. package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
  24. package/src/client/actions/GuildMemberRemove.js +1 -5
  25. package/src/client/actions/GuildMemberUpdate.js +2 -11
  26. package/src/client/actions/GuildRoleCreate.js +1 -5
  27. package/src/client/actions/GuildRoleDelete.js +1 -5
  28. package/src/client/actions/GuildRoleUpdate.js +1 -6
  29. package/src/client/actions/GuildScheduledEventCreate.js +1 -5
  30. package/src/client/actions/GuildScheduledEventDelete.js +1 -5
  31. package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
  32. package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
  33. package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
  34. package/src/client/actions/GuildStickerCreate.js +1 -5
  35. package/src/client/actions/GuildStickerDelete.js +1 -5
  36. package/src/client/actions/GuildStickerUpdate.js +1 -6
  37. package/src/client/actions/GuildStickersUpdate.js +4 -4
  38. package/src/client/actions/GuildUpdate.js +1 -6
  39. package/src/client/actions/InteractionCreate.js +3 -7
  40. package/src/client/actions/InviteCreate.js +1 -7
  41. package/src/client/actions/InviteDelete.js +1 -7
  42. package/src/client/actions/MessageCreate.js +1 -5
  43. package/src/client/actions/MessageDelete.js +1 -5
  44. package/src/client/actions/MessageDeleteBulk.js +1 -6
  45. package/src/client/actions/MessageReactionAdd.js +5 -18
  46. package/src/client/actions/MessageReactionRemove.js +5 -16
  47. package/src/client/actions/MessageReactionRemoveAll.js +4 -9
  48. package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
  49. package/src/client/actions/PresenceUpdate.js +1 -6
  50. package/src/client/actions/StageInstanceCreate.js +1 -5
  51. package/src/client/actions/StageInstanceDelete.js +1 -5
  52. package/src/client/actions/StageInstanceUpdate.js +1 -6
  53. package/src/client/actions/ThreadCreate.js +1 -6
  54. package/src/client/actions/ThreadDelete.js +1 -5
  55. package/src/client/actions/ThreadListSync.js +2 -7
  56. package/src/client/actions/ThreadMemberUpdate.js +2 -7
  57. package/src/client/actions/ThreadMembersUpdate.js +2 -9
  58. package/src/client/actions/TypingStart.js +1 -5
  59. package/src/client/actions/UserUpdate.js +1 -8
  60. package/src/client/actions/VoiceStateUpdate.js +4 -9
  61. package/src/client/actions/WebhooksUpdate.js +1 -6
  62. package/src/client/voice/ClientVoiceManager.js +3 -13
  63. package/src/client/websocket/WebSocketManager.js +25 -117
  64. package/src/client/websocket/WebSocketShard.js +29 -116
  65. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
  66. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
  67. package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
  68. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
  69. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
  70. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
  71. package/src/client/websocket/handlers/RESUMED.js +1 -6
  72. package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
  73. package/src/errors/DJSError.js +3 -14
  74. package/src/errors/ErrorCodes.js +2 -164
  75. package/src/index.js +6 -6
  76. package/src/managers/ApplicationCommandManager.js +14 -130
  77. package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
  78. package/src/managers/AutoModerationRuleManager.js +17 -145
  79. package/src/managers/BaseGuildEmojiManager.js +7 -38
  80. package/src/managers/BaseManager.js +2 -10
  81. package/src/managers/CachedManager.js +3 -17
  82. package/src/managers/CategoryChannelChildManager.js +6 -48
  83. package/src/managers/ChannelManager.js +11 -52
  84. package/src/managers/DataManager.js +5 -27
  85. package/src/managers/GuildApplicationCommandManager.js +3 -12
  86. package/src/managers/GuildBanManager.js +16 -105
  87. package/src/managers/GuildChannelManager.js +31 -226
  88. package/src/managers/GuildEmojiManager.js +9 -65
  89. package/src/managers/GuildEmojiRoleManager.js +8 -47
  90. package/src/managers/GuildForumThreadManager.js +5 -39
  91. package/src/managers/GuildInviteManager.js +18 -117
  92. package/src/managers/GuildManager.js +14 -115
  93. package/src/managers/GuildMemberManager.js +38 -256
  94. package/src/managers/GuildMemberRoleManager.js +13 -76
  95. package/src/managers/GuildScheduledEventManager.js +25 -128
  96. package/src/managers/GuildStickerManager.js +16 -96
  97. package/src/managers/GuildTextThreadManager.js +4 -47
  98. package/src/managers/MessageManager.js +23 -137
  99. package/src/managers/PermissionOverwriteManager.js +10 -78
  100. package/src/managers/PresenceManager.js +6 -27
  101. package/src/managers/ReactionManager.js +7 -40
  102. package/src/managers/ReactionUserManager.js +6 -29
  103. package/src/managers/RoleManager.js +29 -177
  104. package/src/managers/StageInstanceManager.js +14 -77
  105. package/src/managers/ThreadManager.js +23 -113
  106. package/src/managers/ThreadMemberManager.js +20 -89
  107. package/src/managers/UserManager.js +13 -65
  108. package/src/managers/VoiceStateManager.js +3 -13
  109. package/src/sharding/Shard.js +42 -158
  110. package/src/sharding/ShardClientUtil.js +17 -101
  111. package/src/sharding/ShardingManager.js +34 -151
  112. package/src/structures/ActionRow.js +4 -21
  113. package/src/structures/ActionRowBuilder.js +3 -13
  114. package/src/structures/AnonymousGuild.js +10 -43
  115. package/src/structures/ApplicationCommand.js +54 -308
  116. package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
  117. package/src/structures/Attachment.js +16 -65
  118. package/src/structures/AttachmentBuilder.js +13 -58
  119. package/src/structures/AutoModerationActionExecution.js +16 -69
  120. package/src/structures/AutoModerationRule.js +32 -164
  121. package/src/structures/AutocompleteInteraction.js +10 -52
  122. package/src/structures/Base.js +2 -10
  123. package/src/structures/BaseChannel.js +16 -80
  124. package/src/structures/BaseGuild.js +13 -59
  125. package/src/structures/BaseGuildEmoji.js +5 -21
  126. package/src/structures/BaseGuildTextChannel.js +19 -100
  127. package/src/structures/BaseGuildVoiceChannel.js +21 -110
  128. package/src/structures/BaseInteraction.js +40 -196
  129. package/src/structures/BaseSelectMenuComponent.js +6 -29
  130. package/src/structures/ButtonBuilder.js +4 -18
  131. package/src/structures/ButtonComponent.js +7 -34
  132. package/src/structures/ButtonInteraction.js +1 -4
  133. package/src/structures/CategoryChannel.js +5 -30
  134. package/src/structures/ChannelSelectMenuBuilder.js +3 -13
  135. package/src/structures/ChannelSelectMenuComponent.js +2 -9
  136. package/src/structures/ChannelSelectMenuInteraction.js +3 -12
  137. package/src/structures/ChatInputCommandInteraction.js +3 -13
  138. package/src/structures/ClientApplication.js +20 -83
  139. package/src/structures/ClientPresence.js +5 -20
  140. package/src/structures/ClientUser.js +21 -118
  141. package/src/structures/CommandInteraction.js +21 -96
  142. package/src/structures/CommandInteractionOptionResolver.js +26 -147
  143. package/src/structures/Component.js +5 -21
  144. package/src/structures/ContextMenuCommandInteraction.js +4 -18
  145. package/src/structures/DMChannel.js +17 -52
  146. package/src/structures/DirectoryChannel.js +4 -16
  147. package/src/structures/Embed.js +21 -107
  148. package/src/structures/EmbedBuilder.js +4 -18
  149. package/src/structures/Emoji.js +12 -60
  150. package/src/structures/ForumChannel.js +30 -140
  151. package/src/structures/Guild.js +117 -697
  152. package/src/structures/GuildAuditLogs.js +7 -32
  153. package/src/structures/GuildAuditLogsEntry.js +27 -135
  154. package/src/structures/GuildBan.js +6 -26
  155. package/src/structures/GuildChannel.js +36 -188
  156. package/src/structures/GuildEmoji.js +13 -67
  157. package/src/structures/GuildMember.js +47 -270
  158. package/src/structures/GuildPreview.js +19 -84
  159. package/src/structures/GuildPreviewEmoji.js +3 -13
  160. package/src/structures/GuildScheduledEvent.js +46 -250
  161. package/src/structures/GuildTemplate.js +24 -108
  162. package/src/structures/Integration.js +25 -103
  163. package/src/structures/IntegrationApplication.js +8 -32
  164. package/src/structures/InteractionCollector.js +22 -113
  165. package/src/structures/InteractionResponse.js +11 -46
  166. package/src/structures/InteractionWebhook.js +8 -33
  167. package/src/structures/Invite.js +27 -131
  168. package/src/structures/InviteGuild.js +2 -8
  169. package/src/structures/InviteStageInstance.js +9 -39
  170. package/src/structures/MentionableSelectMenuBuilder.js +3 -14
  171. package/src/structures/MentionableSelectMenuComponent.js +1 -4
  172. package/src/structures/MentionableSelectMenuInteraction.js +5 -20
  173. package/src/structures/Message.js +85 -460
  174. package/src/structures/MessageCollector.js +14 -70
  175. package/src/structures/MessageComponentInteraction.js +14 -57
  176. package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
  177. package/src/structures/MessageMentions.js +25 -136
  178. package/src/structures/MessagePayload.js +24 -94
  179. package/src/structures/MessageReaction.js +13 -51
  180. package/src/structures/ModalBuilder.js +3 -13
  181. package/src/structures/ModalSubmitFields.js +5 -22
  182. package/src/structures/ModalSubmitInteraction.js +17 -61
  183. package/src/structures/NewsChannel.js +2 -16
  184. package/src/structures/OAuth2Guild.js +3 -12
  185. package/src/structures/PartialGroupDMChannel.js +7 -27
  186. package/src/structures/PermissionOverwrites.js +20 -99
  187. package/src/structures/Presence.js +45 -190
  188. package/src/structures/ReactionCollector.js +20 -108
  189. package/src/structures/ReactionEmoji.js +2 -10
  190. package/src/structures/Role.js +39 -261
  191. package/src/structures/RoleSelectMenuBuilder.js +3 -13
  192. package/src/structures/RoleSelectMenuComponent.js +1 -4
  193. package/src/structures/RoleSelectMenuInteraction.js +3 -12
  194. package/src/structures/SelectMenuBuilder.js +1 -4
  195. package/src/structures/SelectMenuComponent.js +1 -4
  196. package/src/structures/SelectMenuInteraction.js +1 -4
  197. package/src/structures/SelectMenuOptionBuilder.js +1 -4
  198. package/src/structures/StageChannel.js +12 -84
  199. package/src/structures/StageInstance.js +16 -87
  200. package/src/structures/Sticker.js +25 -124
  201. package/src/structures/StickerPack.js +12 -52
  202. package/src/structures/StringSelectMenuBuilder.js +6 -29
  203. package/src/structures/StringSelectMenuComponent.js +2 -9
  204. package/src/structures/StringSelectMenuInteraction.js +2 -8
  205. package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
  206. package/src/structures/Team.js +11 -52
  207. package/src/structures/TeamMember.js +7 -33
  208. package/src/structures/TextChannel.js +3 -14
  209. package/src/structures/TextInputBuilder.js +3 -13
  210. package/src/structures/TextInputComponent.js +3 -14
  211. package/src/structures/ThreadChannel.js +59 -305
  212. package/src/structures/ThreadMember.js +12 -55
  213. package/src/structures/Typing.js +8 -35
  214. package/src/structures/User.js +29 -151
  215. package/src/structures/UserContextMenuCommandInteraction.js +3 -14
  216. package/src/structures/UserSelectMenuBuilder.js +3 -13
  217. package/src/structures/UserSelectMenuComponent.js +1 -4
  218. package/src/structures/UserSelectMenuInteraction.js +4 -16
  219. package/src/structures/VoiceChannel.js +8 -67
  220. package/src/structures/VoiceRegion.js +6 -23
  221. package/src/structures/VoiceState.js +28 -140
  222. package/src/structures/Webhook.js +37 -227
  223. package/src/structures/WelcomeChannel.js +7 -29
  224. package/src/structures/WelcomeScreen.js +5 -20
  225. package/src/structures/Widget.js +9 -40
  226. package/src/structures/WidgetMember.js +15 -61
  227. package/src/structures/interfaces/Application.js +10 -49
  228. package/src/structures/interfaces/Collector.js +34 -155
  229. package/src/structures/interfaces/InteractionResponses.js +25 -164
  230. package/src/structures/interfaces/TextBasedChannel.js +37 -232
  231. package/src/util/APITypes.js +183 -456
  232. package/src/util/ActivityFlagsBitField.js +3 -15
  233. package/src/util/ApplicationFlagsBitField.js +3 -15
  234. package/src/util/BitField.js +17 -82
  235. package/src/util/ChannelFlagsBitField.js +7 -30
  236. package/src/util/Channels.js +5 -35
  237. package/src/util/Colors.js +3 -38
  238. package/src/util/Components.js +21 -75
  239. package/src/util/Constants.js +17 -144
  240. package/src/util/DataResolver.js +20 -77
  241. package/src/util/Events.js +3 -81
  242. package/src/util/Formatters.js +58 -305
  243. package/src/util/GuildMemberFlagsBitField.js +7 -30
  244. package/src/util/IntentsBitField.js +4 -23
  245. package/src/util/LimitedCollection.js +4 -21
  246. package/src/util/MessageFlagsBitField.js +5 -21
  247. package/src/util/Options.js +24 -137
  248. package/src/util/Partials.js +3 -30
  249. package/src/util/PermissionsBitField.js +12 -67
  250. package/src/util/ShardEvents.js +3 -15
  251. package/src/util/Status.js +3 -17
  252. package/src/util/Sweepers.js +35 -184
  253. package/src/util/SystemChannelFlagsBitField.js +7 -32
  254. package/src/util/ThreadMemberFlagsBitField.js +5 -21
  255. package/src/util/Transformers.js +2 -11
  256. package/src/util/UserFlagsBitField.js +5 -21
  257. package/src/util/Util.js +30 -169
  258. package/src/util/WebSocketShardEvents.js +3 -14
@@ -2,96 +2,50 @@
2
2
 
3
3
  const Base = require('./Base');
4
4
 
5
- /**
6
- * Represents a WidgetMember.
7
- * @extends {Base}
8
- */
5
+
9
6
  class WidgetMember extends Base {
10
- /**
11
- * Activity sent in a {@link WidgetMember}.
12
- * @typedef {Object} WidgetActivity
13
- * @property {string} name The name of the activity
14
- */
7
+
15
8
 
16
9
  constructor(client, data) {
17
10
  super(client);
18
11
 
19
- /**
20
- * The id of the user. It's an arbitrary number.
21
- * @type {string}
22
- */
12
+
23
13
  this.id = data.id;
24
14
 
25
- /**
26
- * The username of the member.
27
- * @type {string}
28
- */
15
+
29
16
  this.username = data.username;
30
17
 
31
- /**
32
- * The discriminator of the member.
33
- * @type {string}
34
- */
18
+
35
19
  this.discriminator = data.discriminator;
36
20
 
37
- /**
38
- * The avatar of the member.
39
- * @type {?string}
40
- */
21
+
41
22
  this.avatar = data.avatar;
42
23
 
43
- /**
44
- * The status of the member.
45
- * @type {PresenceStatus}
46
- */
24
+
47
25
  this.status = data.status;
48
26
 
49
- /**
50
- * If the member is server deafened
51
- * @type {?boolean}
52
- */
27
+
53
28
  this.deaf = data.deaf ?? null;
54
29
 
55
- /**
56
- * If the member is server muted
57
- * @type {?boolean}
58
- */
30
+
59
31
  this.mute = data.mute ?? null;
60
32
 
61
- /**
62
- * If the member is self deafened
63
- * @type {?boolean}
64
- */
33
+
65
34
  this.selfDeaf = data.self_deaf ?? null;
66
35
 
67
- /**
68
- * If the member is self muted
69
- * @type {?boolean}
70
- */
36
+
71
37
  this.selfMute = data.self_mute ?? null;
72
38
 
73
- /**
74
- * If the member is suppressed
75
- * @type {?boolean}
76
- */
39
+
77
40
  this.suppress = data.suppress ?? null;
78
41
 
79
- /**
80
- * The id of the voice channel the member is in, if any
81
- * @type {?Snowflake}
82
- */
42
+
83
43
  this.channelId = data.channel_id ?? null;
84
44
 
85
- /**
86
- * The avatar URL of the member.
87
- * @type {string}
88
- */
45
+
89
46
  this.avatarURL = data.avatar_url;
90
47
 
91
- /**
92
- * The activity of the member.
93
- * @type {?WidgetActivity}
94
- */
48
+
95
49
  this.activity = data.activity ?? null;
96
50
  }
97
51
  }
@@ -3,11 +3,7 @@
3
3
  const { DiscordSnowflake } = require('@sapphire/snowflake');
4
4
  const Base = require('../Base');
5
5
 
6
- /**
7
- * Represents an OAuth2 Application.
8
- * @extends {Base}
9
- * @abstract
10
- */
6
+
11
7
  class Application extends Base {
12
8
  constructor(client, data) {
13
9
  super(client);
@@ -15,87 +11,52 @@ class Application extends Base {
15
11
  }
16
12
 
17
13
  _patch(data) {
18
- /**
19
- * The application's id
20
- * @type {Snowflake}
21
- */
14
+
22
15
  this.id = data.id;
23
16
 
24
17
  if ('name' in data) {
25
- /**
26
- * The name of the application
27
- * @type {?string}
28
- */
18
+
29
19
  this.name = data.name;
30
20
  } else {
31
21
  this.name ??= null;
32
22
  }
33
23
 
34
24
  if ('description' in data) {
35
- /**
36
- * The application's description
37
- * @type {?string}
38
- */
25
+
39
26
  this.description = data.description;
40
27
  } else {
41
28
  this.description ??= null;
42
29
  }
43
30
 
44
31
  if ('icon' in data) {
45
- /**
46
- * The application's icon hash
47
- * @type {?string}
48
- */
32
+
49
33
  this.icon = data.icon;
50
34
  } else {
51
35
  this.icon ??= null;
52
36
  }
53
37
  }
54
38
 
55
- /**
56
- * The timestamp the application was created at
57
- * @type {number}
58
- * @readonly
59
- */
39
+
60
40
  get createdTimestamp() {
61
41
  return DiscordSnowflake.timestampFrom(this.id);
62
42
  }
63
43
 
64
- /**
65
- * The time the application was created at
66
- * @type {Date}
67
- * @readonly
68
- */
44
+
69
45
  get createdAt() {
70
46
  return new Date(this.createdTimestamp);
71
47
  }
72
48
 
73
- /**
74
- * A link to the application's icon.
75
- * @param {ImageURLOptions} [options={}] Options for the image URL
76
- * @returns {?string}
77
- */
49
+
78
50
  iconURL(options = {}) {
79
51
  return this.icon && this.client.rest.cdn.appIcon(this.id, this.icon, options);
80
52
  }
81
53
 
82
- /**
83
- * A link to this application's cover image.
84
- * @param {ImageURLOptions} [options={}] Options for the image URL
85
- * @returns {?string}
86
- */
54
+
87
55
  coverURL(options = {}) {
88
56
  return this.cover && this.client.rest.cdn.appIcon(this.id, this.cover, options);
89
57
  }
90
58
 
91
- /**
92
- * When concatenated with a string, this automatically returns the application's name instead of the
93
- * Application object.
94
- * @returns {?string}
95
- * @example
96
- * // Logs: Application name: My App
97
- * console.log(`Application name: ${application}`);
98
- */
59
+
99
60
  toString() {
100
61
  return this.name;
101
62
  }
@@ -6,84 +6,37 @@ const { Collection } = require('@discordjs/collection');
6
6
  const { DiscordjsTypeError, ErrorCodes } = require('../../errors');
7
7
  const { flatten } = require('../../util/Util');
8
8
 
9
- /**
10
- * Filter to be applied to the collector.
11
- * @typedef {Function} CollectorFilter
12
- * @param {...*} args Any arguments received by the listener
13
- * @param {Collection} collection The items collected by this collector
14
- * @returns {boolean|Promise<boolean>}
15
- */
16
-
17
- /**
18
- * Options to be applied to the collector.
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
- * @extends {EventEmitter}
29
- * @abstract
30
- */
9
+
10
+
11
+
12
+
13
+
31
14
  class Collector extends EventEmitter {
32
15
  constructor(client, options = {}) {
33
16
  super();
34
17
 
35
- /**
36
- * The client that instantiated this Collector
37
- * @name Collector#client
38
- * @type {Client}
39
- * @readonly
40
- */
18
+
41
19
  Object.defineProperty(this, 'client', { value: client });
42
20
 
43
- /**
44
- * The filter applied to this collector
45
- * @type {CollectorFilter}
46
- * @returns {boolean|Promise<boolean>}
47
- */
21
+
48
22
  this.filter = options.filter ?? (() => true);
49
23
 
50
- /**
51
- * The options of this collector
52
- * @type {CollectorOptions}
53
- */
24
+
54
25
  this.options = options;
55
26
 
56
- /**
57
- * The items collected by this collector
58
- * @type {Collection}
59
- */
27
+
60
28
  this.collected = new Collection();
61
29
 
62
- /**
63
- * Whether this collector has finished collecting
64
- * @type {boolean}
65
- */
30
+
66
31
  this.ended = false;
67
32
 
68
- /**
69
- * Timeout for cleanup
70
- * @type {?Timeout}
71
- * @private
72
- */
33
+
73
34
  this._timeout = null;
74
35
 
75
- /**
76
- * Timeout for cleanup due to inactivity
77
- * @type {?Timeout}
78
- * @private
79
- */
36
+
80
37
  this._idletimeout = null;
81
38
 
82
- /**
83
- * The reason the collector ended
84
- * @type {string|null}
85
- * @private
86
- */
39
+
87
40
  this._endReason = null;
88
41
 
89
42
  if (typeof this.filter !== 'function') {
@@ -96,27 +49,16 @@ class Collector extends EventEmitter {
96
49
  if (options.time) this._timeout = setTimeout(() => this.stop('time'), options.time).unref();
97
50
  if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref();
98
51
 
99
- /**
100
- * The timestamp at which this collector last collected an item
101
- * @type {?number}
102
- */
52
+
103
53
  this.lastCollectedTimestamp = null;
104
54
  }
105
55
 
106
- /**
107
- * The Date at which this collector last collected an item
108
- * @type {?Date}
109
- */
56
+
110
57
  get lastCollectedAt() {
111
58
  return this.lastCollectedTimestamp && new Date(this.lastCollectedTimestamp);
112
59
  }
113
60
 
114
- /**
115
- * Call this to handle an event as a collectable element. Accepts any event data as parameters.
116
- * @param {...*} args The arguments emitted by the listener
117
- * @returns {Promise<void>}
118
- * @emits Collector#collect
119
- */
61
+
120
62
  async handleCollect(...args) {
121
63
  const collectedId = await this.collect(...args);
122
64
 
@@ -125,11 +67,7 @@ class Collector extends EventEmitter {
125
67
  if (filterResult) {
126
68
  this.collected.set(collectedId, args[0]);
127
69
 
128
- /**
129
- * Emitted whenever an element is collected.
130
- * @event Collector#collect
131
- * @param {...*} args The arguments emitted by the listener
132
- */
70
+
133
71
  this.emit('collect', ...args);
134
72
 
135
73
  this.lastCollectedTimestamp = Date.now();
@@ -138,23 +76,14 @@ class Collector extends EventEmitter {
138
76
  this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref();
139
77
  }
140
78
  } else {
141
- /**
142
- * Emitted whenever an element is not collected by the collector.
143
- * @event Collector#ignore
144
- * @param {...*} args The arguments emitted by the listener
145
- */
79
+
146
80
  this.emit('ignore', ...args);
147
81
  }
148
82
  }
149
83
  this.checkEnd();
150
84
  }
151
85
 
152
- /**
153
- * Call this to remove an element from the collection. Accepts any event data as parameters.
154
- * @param {...*} args The arguments emitted by the listener
155
- * @returns {Promise<void>}
156
- * @emits Collector#dispose
157
- */
86
+
158
87
  async handleDispose(...args) {
159
88
  if (!this.options.dispose) return;
160
89
 
@@ -162,21 +91,12 @@ class Collector extends EventEmitter {
162
91
  if (!dispose || !(await this.filter(...args)) || !this.collected.has(dispose)) return;
163
92
  this.collected.delete(dispose);
164
93
 
165
- /**
166
- * Emitted whenever an element is disposed of.
167
- * @event Collector#dispose
168
- * @param {...*} args The arguments emitted by the listener
169
- */
94
+
170
95
  this.emit('dispose', ...args);
171
96
  this.checkEnd();
172
97
  }
173
98
 
174
- /**
175
- * Returns a promise that resolves with the next collected element;
176
- * rejects with collected elements if the collector finishes without receiving a next element
177
- * @type {Promise}
178
- * @readonly
179
- */
99
+
180
100
  get next() {
181
101
  return new Promise((resolve, reject) => {
182
102
  if (this.ended) {
@@ -204,11 +124,7 @@ class Collector extends EventEmitter {
204
124
  });
205
125
  }
206
126
 
207
- /**
208
- * Stops this collector and emits the `end` event.
209
- * @param {string} [reason='user'] The reason this collector is ending
210
- * @emits Collector#end
211
- */
127
+
212
128
  stop(reason = 'user') {
213
129
  if (this.ended) return;
214
130
 
@@ -224,26 +140,13 @@ class Collector extends EventEmitter {
224
140
  this._endReason = reason;
225
141
  this.ended = true;
226
142
 
227
- /**
228
- * Emitted when the collector is finished collecting.
229
- * @event Collector#end
230
- * @param {Collection} collected The elements collected by the collector
231
- * @param {string} reason The reason the collector ended
232
- */
143
+
233
144
  this.emit('end', this.collected, reason);
234
145
  }
235
146
 
236
- /**
237
- * Options used to reset the timeout and idle timer of a {@link Collector}.
238
- * @typedef {Object} CollectorResetTimerOptions
239
- * @property {number} [time] How long to run the collector for (in milliseconds)
240
- * @property {number} [idle] How long to wait to stop the collector after inactivity (in milliseconds)
241
- */
242
-
243
- /**
244
- * Resets the collector's timeout and idle timer.
245
- * @param {CollectorResetTimerOptions} [options] Options for resetting
246
- */
147
+
148
+
149
+
247
150
  resetTimer({ time, idle } = {}) {
248
151
  if (this._timeout) {
249
152
  clearTimeout(this._timeout);
@@ -255,20 +158,14 @@ class Collector extends EventEmitter {
255
158
  }
256
159
  }
257
160
 
258
- /**
259
- * Checks whether the collector should end, and if so, ends it.
260
- * @returns {boolean} Whether the collector ended or not
261
- */
161
+
262
162
  checkEnd() {
263
163
  const reason = this.endReason;
264
164
  if (reason) this.stop(reason);
265
165
  return Boolean(reason);
266
166
  }
267
167
 
268
- /**
269
- * Allows collectors to be consumed with for-await-of loops
270
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of}
271
- */
168
+
272
169
  async *[Symbol.asyncIterator]() {
273
170
  const queue = [];
274
171
  const onCollect = (...item) => queue.push(item);
@@ -279,7 +176,7 @@ class Collector extends EventEmitter {
279
176
  if (queue.length) {
280
177
  yield queue.shift();
281
178
  } else {
282
- // eslint-disable-next-line no-await-in-loop
179
+
283
180
  await new Promise(resolve => {
284
181
  const tick = () => {
285
182
  this.removeListener('collect', tick);
@@ -300,36 +197,18 @@ class Collector extends EventEmitter {
300
197
  return flatten(this);
301
198
  }
302
199
 
303
- /* eslint-disable no-empty-function */
304
- /**
305
- * The reason this collector has ended with, or null if it hasn't ended yet
306
- * @type {?string}
307
- * @readonly
308
- */
200
+
201
+
309
202
  get endReason() {
310
203
  return this._endReason;
311
204
  }
312
205
 
313
- /**
314
- * Handles incoming events from the `handleCollect` function. Returns null if the event should not
315
- * be collected, or returns an object describing the data that should be stored.
316
- * @see Collector#handleCollect
317
- * @param {...*} args Any args the event listener emits
318
- * @returns {?(*|Promise<?*>)} Data to insert into collection, if any
319
- * @abstract
320
- */
206
+
321
207
  collect() {}
322
208
 
323
- /**
324
- * Handles incoming events from the `handleDispose`. Returns null if the event should not
325
- * be disposed, or returns the key that should be removed.
326
- * @see Collector#handleDispose
327
- * @param {...*} args Any args the event listener emits
328
- * @returns {?*} Key to remove from the collection, if any
329
- * @abstract
330
- */
209
+
331
210
  dispose() {}
332
- /* eslint-enable no-empty-function */
211
+
333
212
  }
334
213
 
335
214
  module.exports = Collector;