@velliajs/discord 1.0.3 → 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 (257) hide show
  1. package/package.json +1 -1
  2. package/src/client/BaseClient.js +7 -28
  3. package/src/client/Client.js +116 -283
  4. package/src/client/WebhookClient.js +17 -59
  5. package/src/client/actions/Action.js +0 -10
  6. package/src/client/actions/ActionsManager.js +3 -3
  7. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
  8. package/src/client/actions/AutoModerationActionExecution.js +1 -6
  9. package/src/client/actions/AutoModerationRuleCreate.js +1 -6
  10. package/src/client/actions/AutoModerationRuleDelete.js +1 -6
  11. package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
  12. package/src/client/actions/ChannelCreate.js +1 -5
  13. package/src/client/actions/ChannelDelete.js +1 -5
  14. package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
  15. package/src/client/actions/GuildBanAdd.js +1 -5
  16. package/src/client/actions/GuildBanRemove.js +1 -5
  17. package/src/client/actions/GuildDelete.js +6 -14
  18. package/src/client/actions/GuildEmojiCreate.js +1 -5
  19. package/src/client/actions/GuildEmojiDelete.js +1 -5
  20. package/src/client/actions/GuildEmojiUpdate.js +1 -6
  21. package/src/client/actions/GuildEmojisUpdate.js +4 -4
  22. package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
  23. package/src/client/actions/GuildMemberRemove.js +1 -5
  24. package/src/client/actions/GuildMemberUpdate.js +2 -11
  25. package/src/client/actions/GuildRoleCreate.js +1 -5
  26. package/src/client/actions/GuildRoleDelete.js +1 -5
  27. package/src/client/actions/GuildRoleUpdate.js +1 -6
  28. package/src/client/actions/GuildScheduledEventCreate.js +1 -5
  29. package/src/client/actions/GuildScheduledEventDelete.js +1 -5
  30. package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
  31. package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
  32. package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
  33. package/src/client/actions/GuildStickerCreate.js +1 -5
  34. package/src/client/actions/GuildStickerDelete.js +1 -5
  35. package/src/client/actions/GuildStickerUpdate.js +1 -6
  36. package/src/client/actions/GuildStickersUpdate.js +4 -4
  37. package/src/client/actions/GuildUpdate.js +1 -6
  38. package/src/client/actions/InteractionCreate.js +3 -7
  39. package/src/client/actions/InviteCreate.js +1 -7
  40. package/src/client/actions/InviteDelete.js +1 -7
  41. package/src/client/actions/MessageCreate.js +1 -5
  42. package/src/client/actions/MessageDelete.js +1 -5
  43. package/src/client/actions/MessageDeleteBulk.js +1 -6
  44. package/src/client/actions/MessageReactionAdd.js +5 -18
  45. package/src/client/actions/MessageReactionRemove.js +5 -16
  46. package/src/client/actions/MessageReactionRemoveAll.js +4 -9
  47. package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
  48. package/src/client/actions/PresenceUpdate.js +1 -6
  49. package/src/client/actions/StageInstanceCreate.js +1 -5
  50. package/src/client/actions/StageInstanceDelete.js +1 -5
  51. package/src/client/actions/StageInstanceUpdate.js +1 -6
  52. package/src/client/actions/ThreadCreate.js +1 -6
  53. package/src/client/actions/ThreadDelete.js +1 -5
  54. package/src/client/actions/ThreadListSync.js +2 -7
  55. package/src/client/actions/ThreadMemberUpdate.js +2 -7
  56. package/src/client/actions/ThreadMembersUpdate.js +2 -9
  57. package/src/client/actions/TypingStart.js +1 -5
  58. package/src/client/actions/UserUpdate.js +1 -8
  59. package/src/client/actions/VoiceStateUpdate.js +4 -9
  60. package/src/client/actions/WebhooksUpdate.js +1 -6
  61. package/src/client/voice/ClientVoiceManager.js +3 -13
  62. package/src/client/websocket/WebSocketManager.js +25 -117
  63. package/src/client/websocket/WebSocketShard.js +29 -116
  64. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
  65. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
  66. package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
  69. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
  70. package/src/client/websocket/handlers/RESUMED.js +1 -6
  71. package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
  72. package/src/errors/DJSError.js +3 -14
  73. package/src/errors/ErrorCodes.js +2 -164
  74. package/src/index.js +6 -6
  75. package/src/managers/ApplicationCommandManager.js +14 -130
  76. package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
  77. package/src/managers/AutoModerationRuleManager.js +17 -145
  78. package/src/managers/BaseGuildEmojiManager.js +7 -38
  79. package/src/managers/BaseManager.js +2 -10
  80. package/src/managers/CachedManager.js +3 -17
  81. package/src/managers/CategoryChannelChildManager.js +6 -48
  82. package/src/managers/ChannelManager.js +11 -52
  83. package/src/managers/DataManager.js +5 -27
  84. package/src/managers/GuildApplicationCommandManager.js +3 -12
  85. package/src/managers/GuildBanManager.js +16 -105
  86. package/src/managers/GuildChannelManager.js +31 -226
  87. package/src/managers/GuildEmojiManager.js +9 -65
  88. package/src/managers/GuildEmojiRoleManager.js +8 -47
  89. package/src/managers/GuildForumThreadManager.js +5 -39
  90. package/src/managers/GuildInviteManager.js +18 -117
  91. package/src/managers/GuildManager.js +14 -115
  92. package/src/managers/GuildMemberManager.js +38 -256
  93. package/src/managers/GuildMemberRoleManager.js +13 -76
  94. package/src/managers/GuildScheduledEventManager.js +25 -128
  95. package/src/managers/GuildStickerManager.js +16 -96
  96. package/src/managers/GuildTextThreadManager.js +4 -47
  97. package/src/managers/MessageManager.js +23 -137
  98. package/src/managers/PermissionOverwriteManager.js +10 -78
  99. package/src/managers/PresenceManager.js +6 -27
  100. package/src/managers/ReactionManager.js +7 -40
  101. package/src/managers/ReactionUserManager.js +6 -29
  102. package/src/managers/RoleManager.js +29 -177
  103. package/src/managers/StageInstanceManager.js +14 -77
  104. package/src/managers/ThreadManager.js +23 -113
  105. package/src/managers/ThreadMemberManager.js +20 -89
  106. package/src/managers/UserManager.js +13 -65
  107. package/src/managers/VoiceStateManager.js +3 -13
  108. package/src/sharding/Shard.js +42 -158
  109. package/src/sharding/ShardClientUtil.js +17 -101
  110. package/src/sharding/ShardingManager.js +34 -151
  111. package/src/structures/ActionRow.js +4 -21
  112. package/src/structures/ActionRowBuilder.js +3 -13
  113. package/src/structures/AnonymousGuild.js +10 -43
  114. package/src/structures/ApplicationCommand.js +54 -308
  115. package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
  116. package/src/structures/Attachment.js +16 -65
  117. package/src/structures/AttachmentBuilder.js +13 -58
  118. package/src/structures/AutoModerationActionExecution.js +16 -69
  119. package/src/structures/AutoModerationRule.js +32 -164
  120. package/src/structures/AutocompleteInteraction.js +10 -52
  121. package/src/structures/Base.js +2 -10
  122. package/src/structures/BaseChannel.js +16 -80
  123. package/src/structures/BaseGuild.js +13 -59
  124. package/src/structures/BaseGuildEmoji.js +5 -21
  125. package/src/structures/BaseGuildTextChannel.js +19 -100
  126. package/src/structures/BaseGuildVoiceChannel.js +21 -110
  127. package/src/structures/BaseInteraction.js +40 -196
  128. package/src/structures/BaseSelectMenuComponent.js +6 -29
  129. package/src/structures/ButtonBuilder.js +4 -18
  130. package/src/structures/ButtonComponent.js +7 -34
  131. package/src/structures/ButtonInteraction.js +1 -4
  132. package/src/structures/CategoryChannel.js +5 -30
  133. package/src/structures/ChannelSelectMenuBuilder.js +3 -13
  134. package/src/structures/ChannelSelectMenuComponent.js +2 -9
  135. package/src/structures/ChannelSelectMenuInteraction.js +3 -12
  136. package/src/structures/ChatInputCommandInteraction.js +3 -13
  137. package/src/structures/ClientApplication.js +20 -83
  138. package/src/structures/ClientPresence.js +5 -20
  139. package/src/structures/ClientUser.js +21 -118
  140. package/src/structures/CommandInteraction.js +21 -96
  141. package/src/structures/CommandInteractionOptionResolver.js +26 -147
  142. package/src/structures/Component.js +5 -21
  143. package/src/structures/ContextMenuCommandInteraction.js +4 -18
  144. package/src/structures/DMChannel.js +17 -52
  145. package/src/structures/DirectoryChannel.js +4 -16
  146. package/src/structures/Embed.js +21 -107
  147. package/src/structures/EmbedBuilder.js +4 -18
  148. package/src/structures/Emoji.js +12 -60
  149. package/src/structures/ForumChannel.js +30 -140
  150. package/src/structures/Guild.js +117 -697
  151. package/src/structures/GuildAuditLogs.js +7 -32
  152. package/src/structures/GuildAuditLogsEntry.js +27 -135
  153. package/src/structures/GuildBan.js +6 -26
  154. package/src/structures/GuildChannel.js +36 -188
  155. package/src/structures/GuildEmoji.js +13 -67
  156. package/src/structures/GuildMember.js +47 -270
  157. package/src/structures/GuildPreview.js +19 -84
  158. package/src/structures/GuildPreviewEmoji.js +3 -13
  159. package/src/structures/GuildScheduledEvent.js +46 -250
  160. package/src/structures/GuildTemplate.js +24 -108
  161. package/src/structures/Integration.js +25 -103
  162. package/src/structures/IntegrationApplication.js +8 -32
  163. package/src/structures/InteractionCollector.js +22 -113
  164. package/src/structures/InteractionResponse.js +11 -46
  165. package/src/structures/InteractionWebhook.js +8 -33
  166. package/src/structures/Invite.js +27 -131
  167. package/src/structures/InviteGuild.js +2 -8
  168. package/src/structures/InviteStageInstance.js +9 -39
  169. package/src/structures/MentionableSelectMenuBuilder.js +3 -14
  170. package/src/structures/MentionableSelectMenuComponent.js +1 -4
  171. package/src/structures/MentionableSelectMenuInteraction.js +5 -20
  172. package/src/structures/Message.js +85 -460
  173. package/src/structures/MessageCollector.js +14 -70
  174. package/src/structures/MessageComponentInteraction.js +14 -57
  175. package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
  176. package/src/structures/MessageMentions.js +25 -136
  177. package/src/structures/MessagePayload.js +24 -94
  178. package/src/structures/MessageReaction.js +13 -51
  179. package/src/structures/ModalBuilder.js +3 -13
  180. package/src/structures/ModalSubmitFields.js +5 -22
  181. package/src/structures/ModalSubmitInteraction.js +17 -61
  182. package/src/structures/NewsChannel.js +2 -16
  183. package/src/structures/OAuth2Guild.js +3 -12
  184. package/src/structures/PartialGroupDMChannel.js +7 -27
  185. package/src/structures/PermissionOverwrites.js +20 -99
  186. package/src/structures/Presence.js +45 -190
  187. package/src/structures/ReactionCollector.js +20 -108
  188. package/src/structures/ReactionEmoji.js +2 -10
  189. package/src/structures/Role.js +39 -261
  190. package/src/structures/RoleSelectMenuBuilder.js +3 -13
  191. package/src/structures/RoleSelectMenuComponent.js +1 -4
  192. package/src/structures/RoleSelectMenuInteraction.js +3 -12
  193. package/src/structures/SelectMenuBuilder.js +1 -4
  194. package/src/structures/SelectMenuComponent.js +1 -4
  195. package/src/structures/SelectMenuInteraction.js +1 -4
  196. package/src/structures/SelectMenuOptionBuilder.js +1 -4
  197. package/src/structures/StageChannel.js +12 -84
  198. package/src/structures/StageInstance.js +16 -87
  199. package/src/structures/Sticker.js +25 -124
  200. package/src/structures/StickerPack.js +12 -52
  201. package/src/structures/StringSelectMenuBuilder.js +6 -29
  202. package/src/structures/StringSelectMenuComponent.js +2 -9
  203. package/src/structures/StringSelectMenuInteraction.js +2 -8
  204. package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
  205. package/src/structures/Team.js +11 -52
  206. package/src/structures/TeamMember.js +7 -33
  207. package/src/structures/TextChannel.js +3 -14
  208. package/src/structures/TextInputBuilder.js +3 -13
  209. package/src/structures/TextInputComponent.js +3 -14
  210. package/src/structures/ThreadChannel.js +59 -305
  211. package/src/structures/ThreadMember.js +12 -55
  212. package/src/structures/Typing.js +8 -35
  213. package/src/structures/User.js +29 -151
  214. package/src/structures/UserContextMenuCommandInteraction.js +3 -14
  215. package/src/structures/UserSelectMenuBuilder.js +3 -13
  216. package/src/structures/UserSelectMenuComponent.js +1 -4
  217. package/src/structures/UserSelectMenuInteraction.js +4 -16
  218. package/src/structures/VoiceChannel.js +8 -67
  219. package/src/structures/VoiceRegion.js +6 -23
  220. package/src/structures/VoiceState.js +28 -140
  221. package/src/structures/Webhook.js +37 -227
  222. package/src/structures/WelcomeChannel.js +7 -29
  223. package/src/structures/WelcomeScreen.js +5 -20
  224. package/src/structures/Widget.js +9 -40
  225. package/src/structures/WidgetMember.js +15 -61
  226. package/src/structures/interfaces/Application.js +10 -49
  227. package/src/structures/interfaces/Collector.js +34 -155
  228. package/src/structures/interfaces/InteractionResponses.js +25 -164
  229. package/src/structures/interfaces/TextBasedChannel.js +37 -232
  230. package/src/util/APITypes.js +183 -456
  231. package/src/util/ActivityFlagsBitField.js +3 -15
  232. package/src/util/ApplicationFlagsBitField.js +3 -15
  233. package/src/util/BitField.js +17 -82
  234. package/src/util/ChannelFlagsBitField.js +7 -30
  235. package/src/util/Channels.js +5 -35
  236. package/src/util/Colors.js +3 -38
  237. package/src/util/Components.js +21 -75
  238. package/src/util/Constants.js +17 -144
  239. package/src/util/DataResolver.js +20 -77
  240. package/src/util/Events.js +3 -81
  241. package/src/util/Formatters.js +58 -305
  242. package/src/util/GuildMemberFlagsBitField.js +7 -30
  243. package/src/util/IntentsBitField.js +4 -23
  244. package/src/util/LimitedCollection.js +4 -21
  245. package/src/util/MessageFlagsBitField.js +5 -21
  246. package/src/util/Options.js +24 -137
  247. package/src/util/Partials.js +3 -30
  248. package/src/util/PermissionsBitField.js +12 -67
  249. package/src/util/ShardEvents.js +3 -15
  250. package/src/util/Status.js +3 -17
  251. package/src/util/Sweepers.js +35 -184
  252. package/src/util/SystemChannelFlagsBitField.js +7 -32
  253. package/src/util/ThreadMemberFlagsBitField.js +5 -21
  254. package/src/util/Transformers.js +2 -11
  255. package/src/util/UserFlagsBitField.js +5 -21
  256. package/src/util/Util.js +30 -169
  257. package/src/util/WebSocketShardEvents.js +3 -14
@@ -3,38 +3,18 @@
3
3
  const Collector = require('./interfaces/Collector');
4
4
  const Events = require('../util/Events');
5
5
 
6
- /**
7
- * @typedef {CollectorOptions} MessageCollectorOptions
8
- * @property {number} max The maximum amount of messages to collect
9
- * @property {number} maxProcessed The maximum amount of messages to process
10
- */
11
-
12
- /**
13
- * Collects messages on a channel.
14
- * Will automatically stop if the channel ({@link Client#event:channelDelete channelDelete}),
15
- * thread ({@link Client#event:threadDelete threadDelete}), or
16
- * guild ({@link Client#event:guildDelete guildDelete}) is deleted.
17
- * @extends {Collector}
18
- */
6
+
7
+
8
+
19
9
  class MessageCollector extends Collector {
20
- /**
21
- * @param {TextBasedChannels} channel The channel
22
- * @param {MessageCollectorOptions} options The options to be applied to this collector
23
- * @emits MessageCollector#message
24
- */
10
+
25
11
  constructor(channel, options = {}) {
26
12
  super(channel.client, options);
27
13
 
28
- /**
29
- * The channel
30
- * @type {TextBasedChannels}
31
- */
14
+
32
15
  this.channel = channel;
33
16
 
34
- /**
35
- * Total number of messages that were received in the channel during message collection
36
- * @type {number}
37
- */
17
+
38
18
  this.received = 0;
39
19
 
40
20
  const bulkDeleteListener = messages => {
@@ -64,78 +44,42 @@ class MessageCollector extends Collector {
64
44
  });
65
45
  }
66
46
 
67
- /**
68
- * Handles a message for possible collection.
69
- * @param {Message} message The message that could be collected
70
- * @returns {?Snowflake}
71
- * @private
72
- */
47
+
73
48
  collect(message) {
74
- /**
75
- * Emitted whenever a message is collected.
76
- * @event MessageCollector#collect
77
- * @param {Message} message The message that was collected
78
- */
49
+
79
50
  if (message.channelId !== this.channel.id) return null;
80
51
  this.received++;
81
52
  return message.id;
82
53
  }
83
54
 
84
- /**
85
- * Handles a message for possible disposal.
86
- * @param {Message} message The message that could be disposed of
87
- * @returns {?Snowflake}
88
- */
55
+
89
56
  dispose(message) {
90
- /**
91
- * Emitted whenever a message is disposed of.
92
- * @event MessageCollector#dispose
93
- * @param {Message} message The message that was disposed of
94
- */
57
+
95
58
  return message.channelId === this.channel.id ? message.id : null;
96
59
  }
97
60
 
98
- /**
99
- * The reason this collector has ended with, or null if it hasn't ended yet
100
- * @type {?string}
101
- * @readonly
102
- */
61
+
103
62
  get endReason() {
104
63
  if (this.options.max && this.collected.size >= this.options.max) return 'limit';
105
64
  if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit';
106
65
  return super.endReason;
107
66
  }
108
67
 
109
- /**
110
- * Handles checking if the channel has been deleted, and if so, stops the collector with the reason 'channelDelete'.
111
- * @private
112
- * @param {GuildChannel} channel The channel that was deleted
113
- * @returns {void}
114
- */
68
+
115
69
  _handleChannelDeletion(channel) {
116
70
  if (channel.id === this.channel.id || channel.id === this.channel.parentId) {
117
71
  this.stop('channelDelete');
118
72
  }
119
73
  }
120
74
 
121
- /**
122
- * Handles checking if the thread has been deleted, and if so, stops the collector with the reason 'threadDelete'.
123
- * @private
124
- * @param {ThreadChannel} thread The thread that was deleted
125
- * @returns {void}
126
- */
75
+
127
76
  _handleThreadDeletion(thread) {
128
77
  if (thread.id === this.channel.id) {
129
78
  this.stop('threadDelete');
130
79
  }
131
80
  }
132
81
 
133
- /**
134
- * Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
135
- * @private
136
- * @param {Guild} guild The guild that was deleted
137
- * @returns {void}
138
- */
82
+
139
83
  _handleGuildDeletion(guild) {
140
84
  if (guild.id === this.channel.guild?.id) {
141
85
  this.stop('guildDelete');
@@ -7,89 +7,46 @@ const InteractionResponses = require('./interfaces/InteractionResponses');
7
7
 
8
8
  const getMessage = lazy(() => require('./Message').Message);
9
9
 
10
- /**
11
- * Represents a message component interaction.
12
- * @extends {BaseInteraction}
13
- * @implements {InteractionResponses}
14
- */
10
+
15
11
  class MessageComponentInteraction extends BaseInteraction {
16
12
  constructor(client, data) {
17
13
  super(client, data);
18
14
 
19
- /**
20
- * The id of the channel this interaction was sent in
21
- * @type {Snowflake}
22
- * @name MessageComponentInteraction#channelId
23
- */
15
+
24
16
 
25
- /**
26
- * The message to which the component was attached
27
- * @type {Message}
28
- */
17
+
29
18
  this.message = this.channel?.messages._add(data.message) ?? new (getMessage())(client, data.message);
30
19
 
31
- /**
32
- * The custom id of the component which was interacted with
33
- * @type {string}
34
- */
20
+
35
21
  this.customId = data.data.custom_id;
36
22
 
37
- /**
38
- * The type of component which was interacted with
39
- * @type {ComponentType}
40
- */
23
+
41
24
  this.componentType = data.data.component_type;
42
25
 
43
- /**
44
- * Whether the reply to this interaction has been deferred
45
- * @type {boolean}
46
- */
26
+
47
27
  this.deferred = false;
48
28
 
49
- /**
50
- * Whether the reply to this interaction is ephemeral
51
- * @type {?boolean}
52
- */
29
+
53
30
  this.ephemeral = null;
54
31
 
55
- /**
56
- * Whether this interaction has already been replied to
57
- * @type {boolean}
58
- */
32
+
59
33
  this.replied = false;
60
34
 
61
- /**
62
- * An associated interaction webhook, can be used to further interact with this interaction
63
- * @type {InteractionWebhook}
64
- */
35
+
65
36
  this.webhook = new InteractionWebhook(this.client, this.applicationId, this.token);
66
37
  }
67
38
 
68
- /**
69
- * Components that can be placed in an action row for messages.
70
- * * ButtonComponent
71
- * * StringSelectMenuComponent
72
- * * UserSelectMenuComponent
73
- * * RoleSelectMenuComponent
74
- * * MentionableSelectMenuComponent
75
- * * ChannelSelectMenuComponent
76
- * @typedef {ButtonComponent|StringSelectMenuComponent|UserSelectMenuComponent|
77
- * RoleSelectMenuComponent|MentionableSelectMenuComponent|ChannelSelectMenuComponent} MessageActionRowComponent
78
- */
79
-
80
- /**
81
- * The component which was interacted with
82
- * @type {MessageActionRowComponent|APIMessageActionRowComponent}
83
- * @readonly
84
- */
39
+
40
+
41
+
85
42
  get component() {
86
43
  return this.message.components
87
44
  .flatMap(row => row.components)
88
45
  .find(component => (component.customId ?? component.custom_id) === this.customId);
89
46
  }
90
47
 
91
- // These are here only for documentation purposes - they are implemented by InteractionResponses
92
- /* eslint-disable no-empty-function */
48
+
49
+
93
50
  deferReply() {}
94
51
  reply() {}
95
52
  fetchReply() {}
@@ -2,16 +2,9 @@
2
2
 
3
3
  const ContextMenuCommandInteraction = require('./ContextMenuCommandInteraction');
4
4
 
5
- /**
6
- * Represents a message context menu interaction.
7
- * @extends {ContextMenuCommandInteraction}
8
- */
5
+
9
6
  class MessageContextMenuCommandInteraction extends ContextMenuCommandInteraction {
10
- /**
11
- * The message this interaction was sent from
12
- * @type {Message|APIMessage}
13
- * @readonly
14
- */
7
+
15
8
  get targetMessage() {
16
9
  return this.options.getMessage('message');
17
10
  }
@@ -4,94 +4,42 @@ const { Collection } = require('@discordjs/collection');
4
4
  const { FormattingPatterns } = require('discord-api-types/v10');
5
5
  const { flatten } = require('../util/Util');
6
6
 
7
- /**
8
- * Keeps track of mentions in a {@link Message}.
9
- */
7
+
10
8
  class MessageMentions {
11
- /**
12
- * A regular expression that matches `@everyone` and `@here`.
13
- * The `mention` group property is present on the `exec` result of this expression.
14
- * @type {RegExp}
15
- * @memberof MessageMentions
16
- */
9
+
17
10
  static EveryonePattern = /@(?<mention>everyone|here)/;
18
11
 
19
- /**
20
- * A regular expression that matches user mentions like `<@81440962496172032>`.
21
- * The `id` group property is present on the `exec` result of this expression.
22
- * @type {RegExp}
23
- * @memberof MessageMentions
24
- */
12
+
25
13
  static UsersPattern = FormattingPatterns.UserWithOptionalNickname;
26
14
 
27
- /**
28
- * A regular expression that matches role mentions like `<@&297577916114403338>`.
29
- * The `id` group property is present on the `exec` result of this expression.
30
- * @type {RegExp}
31
- * @memberof MessageMentions
32
- */
15
+
33
16
  static RolesPattern = FormattingPatterns.Role;
34
17
 
35
- /**
36
- * A regular expression that matches channel mentions like `<#222079895583457280>`.
37
- * The `id` group property is present on the `exec` result of this expression.
38
- * @type {RegExp}
39
- * @memberof MessageMentions
40
- */
18
+
41
19
  static ChannelsPattern = FormattingPatterns.Channel;
42
20
 
43
- /**
44
- * A global regular expression variant of {@link MessageMentions.ChannelsPattern}.
45
- * @type {RegExp}
46
- * @memberof MessageMentions
47
- * @private
48
- */
21
+
49
22
  static GlobalChannelsPattern = new RegExp(this.ChannelsPattern.source, 'g');
50
23
 
51
- /**
52
- * A global regular expression variant of {@link MessageMentions.UsersPattern}.
53
- * @type {RegExp}
54
- * @memberof MessageMentions
55
- * @private
56
- */
24
+
57
25
  static GlobalUsersPattern = new RegExp(this.UsersPattern.source, 'g');
58
26
 
59
27
  constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
60
- /**
61
- * The client the message is from
62
- * @type {Client}
63
- * @readonly
64
- */
28
+
65
29
  Object.defineProperty(this, 'client', { value: message.client });
66
30
 
67
- /**
68
- * The guild the message is in
69
- * @type {?Guild}
70
- * @readonly
71
- */
31
+
72
32
  Object.defineProperty(this, 'guild', { value: message.guild });
73
33
 
74
- /**
75
- * The initial message content
76
- * @type {string}
77
- * @readonly
78
- * @private
79
- */
34
+
80
35
  Object.defineProperty(this, '_content', { value: message.content });
81
36
 
82
- /**
83
- * Whether `@everyone` or `@here` were mentioned
84
- * @type {boolean}
85
- */
37
+
86
38
  this.everyone = Boolean(everyone);
87
39
 
88
40
  if (users) {
89
41
  if (users instanceof Collection) {
90
- /**
91
- * Any users that were mentioned
92
- * <info>Order as received from the API, not as they appear in the message content</info>
93
- * @type {Collection<Snowflake, User>}
94
- */
42
+
95
43
  this.users = new Collection(users);
96
44
  } else {
97
45
  this.users = new Collection();
@@ -108,11 +56,7 @@ class MessageMentions {
108
56
  }
109
57
 
110
58
  if (roles instanceof Collection) {
111
- /**
112
- * Any roles that were mentioned
113
- * <info>Order as received from the API, not as they appear in the message content</info>
114
- * @type {Collection<Snowflake, Role>}
115
- */
59
+
116
60
  this.roles = new Collection(roles);
117
61
  } else if (roles) {
118
62
  this.roles = new Collection();
@@ -127,43 +71,20 @@ class MessageMentions {
127
71
  this.roles = new Collection();
128
72
  }
129
73
 
130
- /**
131
- * Cached members for {@link MessageMentions#members}
132
- * @type {?Collection<Snowflake, GuildMember>}
133
- * @private
134
- */
74
+
135
75
  this._members = null;
136
76
 
137
- /**
138
- * Cached channels for {@link MessageMentions#channels}
139
- * @type {?Collection<Snowflake, BaseChannel>}
140
- * @private
141
- */
77
+
142
78
  this._channels = null;
143
79
 
144
- /**
145
- * Cached users for {@link MessageMentions#parsedUsers}
146
- * @type {?Collection<Snowflake, User>}
147
- * @private
148
- */
80
+
149
81
  this._parsedUsers = null;
150
82
 
151
- /**
152
- * Crossposted channel data.
153
- * @typedef {Object} CrosspostedChannel
154
- * @property {Snowflake} channelId The mentioned channel's id
155
- * @property {Snowflake} guildId The id of the guild that has the channel
156
- * @property {ChannelType} type The channel's type
157
- * @property {string} name The channel's name
158
- */
83
+
159
84
 
160
85
  if (crosspostedChannels) {
161
86
  if (crosspostedChannels instanceof Collection) {
162
- /**
163
- * A collection of crossposted channels
164
- * <info>Order as received from the API, not as they appear in the message content</info>
165
- * @type {Collection<Snowflake, CrosspostedChannel>}
166
- */
87
+
167
88
  this.crosspostedChannels = new Collection(crosspostedChannels);
168
89
  } else {
169
90
  this.crosspostedChannels = new Collection();
@@ -180,19 +101,11 @@ class MessageMentions {
180
101
  this.crosspostedChannels = new Collection();
181
102
  }
182
103
 
183
- /**
184
- * The author of the message that this message is a reply to
185
- * @type {?User}
186
- */
104
+
187
105
  this.repliedUser = repliedUser ? this.client.users._add(repliedUser) : null;
188
106
  }
189
107
 
190
- /**
191
- * Any members that were mentioned (only in {@link Guild}s)
192
- * <info>Order as received from the API, not as they appear in the message content</info>
193
- * @type {?Collection<Snowflake, GuildMember>}
194
- * @readonly
195
- */
108
+
196
109
  get members() {
197
110
  if (this._members) return this._members;
198
111
  if (!this.guild) return null;
@@ -204,12 +117,7 @@ class MessageMentions {
204
117
  return this._members;
205
118
  }
206
119
 
207
- /**
208
- * Any channels that were mentioned
209
- * <info>Order as they appear first in the message content</info>
210
- * @type {Collection<Snowflake, BaseChannel>}
211
- * @readonly
212
- */
120
+
213
121
  get channels() {
214
122
  if (this._channels) return this._channels;
215
123
  this._channels = new Collection();
@@ -223,12 +131,7 @@ class MessageMentions {
223
131
  return this._channels;
224
132
  }
225
133
 
226
- /**
227
- * Any user mentions that were included in the message content
228
- * <info>Order as they appear first in the message content</info>
229
- * @type {Collection<Snowflake, User>}
230
- * @readonly
231
- */
134
+
232
135
  get parsedUsers() {
233
136
  if (this._parsedUsers) return this._parsedUsers;
234
137
  this._parsedUsers = new Collection();
@@ -240,23 +143,9 @@ class MessageMentions {
240
143
  return this._parsedUsers;
241
144
  }
242
145
 
243
- /**
244
- * Options used to check for a mention.
245
- * @typedef {Object} MessageMentionsHasOptions
246
- * @property {boolean} [ignoreDirect=false] Whether to ignore direct mentions to the item
247
- * @property {boolean} [ignoreRoles=false] Whether to ignore role mentions to a guild member
248
- * @property {boolean} [ignoreRepliedUser=false] Whether to ignore replied user mention to an user
249
- * @property {boolean} [ignoreEveryone=false] Whether to ignore `@everyone`/`@here` mentions
250
- */
251
-
252
- /**
253
- * Checks if a user, guild member, thread member, role, or channel is mentioned.
254
- * Takes into account user mentions, role mentions, channel mentions,
255
- * replied user mention, and `@everyone`/`@here` mentions.
256
- * @param {UserResolvable|RoleResolvable|ChannelResolvable} data The User/Role/Channel to check for
257
- * @param {MessageMentionsHasOptions} [options] The options for the check
258
- * @returns {boolean}
259
- */
146
+
147
+
148
+
260
149
  has(data, { ignoreDirect = false, ignoreRoles = false, ignoreRepliedUser = false, ignoreEveryone = false } = {}) {
261
150
  const user = this.client.users.resolve(data);
262
151
 
@@ -11,97 +11,57 @@ const { basename, verifyString } = require('../util/Util');
11
11
 
12
12
  const getBaseInteraction = lazy(() => require('./BaseInteraction'));
13
13
 
14
- /**
15
- * Represents a message to be sent to the API.
16
- */
14
+
17
15
  class MessagePayload {
18
- /**
19
- * @param {MessageTarget} target The target for this message to be sent to
20
- * @param {MessagePayloadOption} options The payload of this message
21
- */
16
+
22
17
  constructor(target, options) {
23
- /**
24
- * The target for this message to be sent to
25
- * @type {MessageTarget}
26
- */
18
+
27
19
  this.target = target;
28
20
 
29
- /**
30
- * The payload of this message.
31
- * @type {MessagePayloadOption}
32
- */
21
+
33
22
  this.options = options;
34
23
 
35
- /**
36
- * Body sendable to the API
37
- * @type {?APIMessage}
38
- */
24
+
39
25
  this.body = null;
40
26
 
41
- /**
42
- * Files sendable to the API
43
- * @type {?RawFile[]}
44
- */
27
+
45
28
  this.files = null;
46
29
  }
47
30
 
48
- /**
49
- * Whether or not the target is a {@link Webhook} or a {@link WebhookClient}
50
- * @type {boolean}
51
- * @readonly
52
- */
31
+
53
32
  get isWebhook() {
54
33
  const Webhook = require('./Webhook');
55
34
  const WebhookClient = require('../client/WebhookClient');
56
35
  return this.target instanceof Webhook || this.target instanceof WebhookClient;
57
36
  }
58
37
 
59
- /**
60
- * Whether or not the target is a {@link User}
61
- * @type {boolean}
62
- * @readonly
63
- */
38
+
64
39
  get isUser() {
65
40
  const User = require('./User');
66
41
  const { GuildMember } = require('./GuildMember');
67
42
  return this.target instanceof User || this.target instanceof GuildMember;
68
43
  }
69
44
 
70
- /**
71
- * Whether or not the target is a {@link Message}
72
- * @type {boolean}
73
- * @readonly
74
- */
45
+
75
46
  get isMessage() {
76
47
  const { Message } = require('./Message');
77
48
  return this.target instanceof Message;
78
49
  }
79
50
 
80
- /**
81
- * Whether or not the target is a {@link MessageManager}
82
- * @type {boolean}
83
- * @readonly
84
- */
51
+
85
52
  get isMessageManager() {
86
53
  const MessageManager = require('../managers/MessageManager');
87
54
  return this.target instanceof MessageManager;
88
55
  }
89
56
 
90
- /**
91
- * Whether or not the target is an {@link BaseInteraction} or an {@link InteractionWebhook}
92
- * @type {boolean}
93
- * @readonly
94
- */
57
+
95
58
  get isInteraction() {
96
59
  const BaseInteraction = getBaseInteraction();
97
60
  const InteractionWebhook = require('./InteractionWebhook');
98
61
  return this.target instanceof BaseInteraction || this.target instanceof InteractionWebhook;
99
62
  }
100
63
 
101
- /**
102
- * Makes the content of this message.
103
- * @returns {?string}
104
- */
64
+
105
65
  makeContent() {
106
66
  let content;
107
67
  if (this.options.content === null) {
@@ -113,10 +73,7 @@ class MessagePayload {
113
73
  return content;
114
74
  }
115
75
 
116
- /**
117
- * Resolves the body.
118
- * @returns {MessagePayload}
119
- */
76
+
120
77
  resolveBody() {
121
78
  if (this.body) return this;
122
79
  const isInteraction = this.isInteraction;
@@ -151,7 +108,7 @@ class MessagePayload {
151
108
  this.isMessageManager
152
109
  ) {
153
110
  flags =
154
- // eslint-disable-next-line eqeqeq
111
+
155
112
  this.options.flags != null
156
113
  ? new MessageFlagsBitField(this.options.flags).bitfield
157
114
  : this.target.flags?.bitfield;
@@ -213,10 +170,7 @@ class MessagePayload {
213
170
  return this;
214
171
  }
215
172
 
216
- /**
217
- * Resolves files.
218
- * @returns {Promise<MessagePayload>}
219
- */
173
+
220
174
  async resolveFiles() {
221
175
  if (this.files) return this;
222
176
 
@@ -224,11 +178,7 @@ class MessagePayload {
224
178
  return this;
225
179
  }
226
180
 
227
- /**
228
- * Resolves a single file into an object sendable to the API.
229
- * @param {AttachmentPayload|BufferResolvable|Stream} fileLike Something that could be resolved to a file
230
- * @returns {Promise<RawFile>}
231
- */
181
+
232
182
  static async resolveFile(fileLike) {
233
183
  let attachment;
234
184
  let name;
@@ -259,13 +209,7 @@ class MessagePayload {
259
209
  return { data, name, contentType };
260
210
  }
261
211
 
262
- /**
263
- * Creates a {@link MessagePayload} from user-level arguments.
264
- * @param {MessageTarget} target Target to send to
265
- * @param {string|MessagePayloadOption} options Options or content to use
266
- * @param {MessagePayloadOption} [extra={}] Extra options to add onto specified options
267
- * @returns {MessagePayload}
268
- */
212
+
269
213
  static create(target, options, extra = {}) {
270
214
  return new this(
271
215
  target,
@@ -276,24 +220,10 @@ class MessagePayload {
276
220
 
277
221
  module.exports = MessagePayload;
278
222
 
279
- /**
280
- * A target for a message.
281
- * @typedef {TextBasedChannels|User|GuildMember|Webhook|WebhookClient|BaseInteraction|InteractionWebhook|
282
- * Message|MessageManager} MessageTarget
283
- */
284
-
285
- /**
286
- * A possible payload option.
287
- * @typedef {MessageCreateOptions|MessageEditOptions|WebhookMessageCreateOptions|WebhookMessageEditOptions|
288
- * InteractionReplyOptions|InteractionUpdateOptions} MessagePayloadOption
289
- */
290
-
291
- /**
292
- * @external APIMessage
293
- * @see {@link https://discord.com/developers/docs/resources/channel#message-object}
294
- */
295
-
296
- /**
297
- * @external RawFile
298
- * @see {@link https://discord.js.org/docs/packages/rest/stable/RawFile:Interface}
299
- */
223
+
224
+
225
+
226
+
227
+
228
+
229
+