discord.js-seflbot-v13 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord.js-seflbot-v13 might be problematic. Click here for more details.
- package/LICENSE +674 -0
- package/README.md +128 -0
- package/package.json +103 -0
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +87 -0
- package/src/client/Client.js +1102 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +120 -0
- package/src/client/actions/ActionsManager.js +78 -0
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +26 -0
- package/src/client/actions/AutoModerationRuleCreate.js +27 -0
- package/src/client/actions/AutoModerationRuleDelete.js +31 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +29 -0
- package/src/client/actions/ChannelCreate.js +23 -0
- package/src/client/actions/ChannelDelete.js +39 -0
- package/src/client/actions/ChannelUpdate.js +43 -0
- package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
- package/src/client/actions/GuildBanAdd.js +20 -0
- package/src/client/actions/GuildBanRemove.js +25 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
- package/src/client/actions/GuildDelete.js +65 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +21 -0
- package/src/client/actions/GuildEmojiUpdate.js +20 -0
- package/src/client/actions/GuildEmojisUpdate.js +34 -0
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +33 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +31 -0
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +31 -0
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
- package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
- package/src/client/actions/GuildStickerCreate.js +20 -0
- package/src/client/actions/GuildStickerDelete.js +21 -0
- package/src/client/actions/GuildStickerUpdate.js +20 -0
- package/src/client/actions/GuildStickersUpdate.js +34 -0
- package/src/client/actions/GuildUpdate.js +33 -0
- package/src/client/actions/InteractionCreate.js +115 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +61 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +46 -0
- package/src/client/actions/MessageReactionAdd.js +56 -0
- package/src/client/actions/MessageReactionRemove.js +45 -0
- package/src/client/actions/MessageReactionRemoveAll.js +33 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
- package/src/client/actions/MessageUpdate.js +26 -0
- package/src/client/actions/PresenceUpdate.js +45 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +33 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +32 -0
- package/src/client/actions/ThreadListSync.js +59 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +34 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +35 -0
- package/src/client/actions/VoiceStateUpdate.js +57 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +51 -0
- package/src/client/websocket/WebSocketManager.js +412 -0
- package/src/client/websocket/WebSocketShard.js +905 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
- package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
- package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_CREATE.js +53 -0
- package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
- package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
- package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +11 -0
- package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
- package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/READY.js +171 -0
- package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +17 -0
- package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +15 -0
- package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +18 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +12 -0
- package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +9 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +87 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +228 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +194 -0
- package/src/main.js +1 -0
- package/src/managers/ApplicationCommandManager.js +267 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +425 -0
- package/src/managers/AutoModerationRuleManager.js +296 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/BillingManager.js +66 -0
- package/src/managers/CachedManager.js +71 -0
- package/src/managers/ChannelManager.js +139 -0
- package/src/managers/ClientUserSettingManager.js +490 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/DeveloperPortalManager.js +104 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +504 -0
- package/src/managers/GuildEmojiManager.js +171 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildFolderManager.js +24 -0
- package/src/managers/GuildForumThreadManager.js +114 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +304 -0
- package/src/managers/GuildMemberManager.js +772 -0
- package/src/managers/GuildMemberRoleManager.js +191 -0
- package/src/managers/GuildScheduledEventManager.js +296 -0
- package/src/managers/GuildSettingManager.js +148 -0
- package/src/managers/GuildStickerManager.js +179 -0
- package/src/managers/GuildTextThreadManager.js +98 -0
- package/src/managers/InteractionManager.js +39 -0
- package/src/managers/MessageManager.js +393 -0
- package/src/managers/PermissionOverwriteManager.js +166 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +71 -0
- package/src/managers/RelationshipManager.js +258 -0
- package/src/managers/RoleManager.js +352 -0
- package/src/managers/SessionManager.js +57 -0
- package/src/managers/StageInstanceManager.js +162 -0
- package/src/managers/ThreadManager.js +207 -0
- package/src/managers/ThreadMemberManager.js +186 -0
- package/src/managers/UserManager.js +150 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/rest/APIRequest.js +133 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/CaptchaSolver.js +139 -0
- package/src/rest/DiscordAPIError.js +103 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +82 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +430 -0
- package/src/sharding/Shard.js +443 -0
- package/src/sharding/ShardClientUtil.js +275 -0
- package/src/sharding/ShardingManager.js +318 -0
- package/src/structures/AnonymousGuild.js +98 -0
- package/src/structures/ApplicationCommand.js +1030 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +45 -0
- package/src/structures/AutoModerationActionExecution.js +89 -0
- package/src/structures/AutoModerationRule.js +294 -0
- package/src/structures/AutocompleteInteraction.js +106 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseCommandInteraction.js +211 -0
- package/src/structures/BaseGuild.js +116 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +203 -0
- package/src/structures/BaseGuildVoiceChannel.js +243 -0
- package/src/structures/BaseMessageComponent.js +114 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/Call.js +58 -0
- package/src/structures/CategoryChannel.js +85 -0
- package/src/structures/Channel.js +271 -0
- package/src/structures/ClientApplication.js +233 -0
- package/src/structures/ClientPresence.js +92 -0
- package/src/structures/ClientUser.js +635 -0
- package/src/structures/CommandInteraction.js +41 -0
- package/src/structures/CommandInteractionOptionResolver.js +276 -0
- package/src/structures/ContextMenuInteraction.js +65 -0
- package/src/structures/DMChannel.js +289 -0
- package/src/structures/DeveloperPortalApplication.js +520 -0
- package/src/structures/DirectoryChannel.js +20 -0
- package/src/structures/Emoji.js +148 -0
- package/src/structures/ForumChannel.js +271 -0
- package/src/structures/Guild.js +1744 -0
- package/src/structures/GuildAuditLogs.js +734 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildBoost.js +108 -0
- package/src/structures/GuildChannel.js +468 -0
- package/src/structures/GuildEmoji.js +161 -0
- package/src/structures/GuildFolder.js +75 -0
- package/src/structures/GuildMember.js +686 -0
- package/src/structures/GuildPreview.js +191 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +441 -0
- package/src/structures/GuildTemplate.js +236 -0
- package/src/structures/Integration.js +188 -0
- package/src/structures/IntegrationApplication.js +96 -0
- package/src/structures/Interaction.js +351 -0
- package/src/structures/InteractionCollector.js +248 -0
- package/src/structures/InteractionResponse.js +114 -0
- package/src/structures/InteractionWebhook.js +43 -0
- package/src/structures/Invite.js +375 -0
- package/src/structures/InviteGuild.js +23 -0
- package/src/structures/InviteStageInstance.js +86 -0
- package/src/structures/Message.js +1188 -0
- package/src/structures/MessageActionRow.js +103 -0
- package/src/structures/MessageAttachment.js +204 -0
- package/src/structures/MessageButton.js +231 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +120 -0
- package/src/structures/MessageContextMenuInteraction.js +20 -0
- package/src/structures/MessageEmbed.js +586 -0
- package/src/structures/MessageMentions.js +272 -0
- package/src/structures/MessagePayload.js +358 -0
- package/src/structures/MessageReaction.js +171 -0
- package/src/structures/MessageSelectMenu.js +391 -0
- package/src/structures/Modal.js +279 -0
- package/src/structures/ModalSubmitFieldsResolver.js +53 -0
- package/src/structures/ModalSubmitInteraction.js +119 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +449 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +443 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/RichPresence.js +722 -0
- package/src/structures/Role.js +531 -0
- package/src/structures/SelectMenuInteraction.js +170 -0
- package/src/structures/Session.js +81 -0
- package/src/structures/StageChannel.js +104 -0
- package/src/structures/StageInstance.js +208 -0
- package/src/structures/Sticker.js +310 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StoreChannel.js +56 -0
- package/src/structures/Team.js +167 -0
- package/src/structures/TeamMember.js +71 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputComponent.js +201 -0
- package/src/structures/ThreadChannel.js +626 -0
- package/src/structures/ThreadMember.js +105 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +730 -0
- package/src/structures/UserContextMenuInteraction.js +29 -0
- package/src/structures/VoiceChannel.js +110 -0
- package/src/structures/VoiceRegion.js +53 -0
- package/src/structures/VoiceState.js +353 -0
- package/src/structures/WebEmbed.js +412 -0
- package/src/structures/Webhook.js +461 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +48 -0
- package/src/structures/Widget.js +87 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +190 -0
- package/src/structures/interfaces/Collector.js +300 -0
- package/src/structures/interfaces/InteractionResponses.js +313 -0
- package/src/structures/interfaces/TextBasedChannel.js +566 -0
- package/src/util/ActivityFlags.js +44 -0
- package/src/util/ApplicationFlags.js +76 -0
- package/src/util/AttachmentFlags.js +38 -0
- package/src/util/BitField.js +170 -0
- package/src/util/ChannelFlags.js +45 -0
- package/src/util/Constants.js +1940 -0
- package/src/util/DataResolver.js +145 -0
- package/src/util/Formatters.js +214 -0
- package/src/util/GuildMemberFlags.js +43 -0
- package/src/util/Intents.js +74 -0
- package/src/util/LimitedCollection.js +131 -0
- package/src/util/MessageFlags.js +54 -0
- package/src/util/Options.js +364 -0
- package/src/util/Permissions.js +187 -0
- package/src/util/PremiumUsageFlags.js +31 -0
- package/src/util/PurchasedFlags.js +31 -0
- package/src/util/RemoteAuth.js +514 -0
- package/src/util/RoleFlags.js +37 -0
- package/src/util/SnowflakeUtil.js +92 -0
- package/src/util/Sweepers.js +466 -0
- package/src/util/SystemChannelFlags.js +55 -0
- package/src/util/ThreadMemberFlags.js +30 -0
- package/src/util/UserFlags.js +104 -0
- package/src/util/Util.js +882 -0
- package/src/util/Voice.js +1456 -0
- package/src/util/arRPC/index.js +229 -0
- package/src/util/arRPC/process/detectable.json +1 -0
- package/src/util/arRPC/process/index.js +102 -0
- package/src/util/arRPC/process/native/index.js +5 -0
- package/src/util/arRPC/process/native/linux.js +37 -0
- package/src/util/arRPC/process/native/win32.js +25 -0
- package/src/util/arRPC/transports/ipc.js +281 -0
- package/src/util/arRPC/transports/websocket.js +128 -0
- package/typings/enums.d.ts +346 -0
- package/typings/index.d.ts +7776 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +283 -0
@@ -0,0 +1,272 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
4
|
+
const { ChannelTypes } = require('../util/Constants');
|
5
|
+
const Util = require('../util/Util');
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Keeps track of mentions in a {@link Message}.
|
9
|
+
*/
|
10
|
+
class MessageMentions {
|
11
|
+
constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
|
12
|
+
/**
|
13
|
+
* The client the message is from
|
14
|
+
* @type {Client}
|
15
|
+
* @readonly
|
16
|
+
*/
|
17
|
+
Object.defineProperty(this, 'client', { value: message.client });
|
18
|
+
|
19
|
+
/**
|
20
|
+
* The guild the message is in
|
21
|
+
* @type {?Guild}
|
22
|
+
* @readonly
|
23
|
+
*/
|
24
|
+
Object.defineProperty(this, 'guild', { value: message.guild });
|
25
|
+
|
26
|
+
/**
|
27
|
+
* The initial message content
|
28
|
+
* @type {string}
|
29
|
+
* @readonly
|
30
|
+
* @private
|
31
|
+
*/
|
32
|
+
Object.defineProperty(this, '_content', { value: message.content });
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Whether `@everyone` or `@here` were mentioned
|
36
|
+
* @type {boolean}
|
37
|
+
*/
|
38
|
+
this.everyone = Boolean(everyone);
|
39
|
+
|
40
|
+
if (users) {
|
41
|
+
if (users instanceof Collection) {
|
42
|
+
/**
|
43
|
+
* Any users that were mentioned
|
44
|
+
* <info>Order as received from the API, not as they appear in the message content</info>
|
45
|
+
* @type {Collection<Snowflake, User>}
|
46
|
+
*/
|
47
|
+
this.users = new Collection(users);
|
48
|
+
} else {
|
49
|
+
this.users = new Collection();
|
50
|
+
for (const mention of users) {
|
51
|
+
if (mention.member && message.guild) {
|
52
|
+
message.guild.members._add(Object.assign(mention.member, { user: mention }));
|
53
|
+
}
|
54
|
+
const user = message.client.users._add(mention);
|
55
|
+
this.users.set(user.id, user);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
this.users = new Collection();
|
60
|
+
}
|
61
|
+
|
62
|
+
if (roles instanceof Collection) {
|
63
|
+
/**
|
64
|
+
* Any roles that were mentioned
|
65
|
+
* <info>Order as received from the API, not as they appear in the message content</info>
|
66
|
+
* @type {Collection<Snowflake, Role>}
|
67
|
+
*/
|
68
|
+
this.roles = new Collection(roles);
|
69
|
+
} else if (roles) {
|
70
|
+
this.roles = new Collection();
|
71
|
+
const guild = message.guild;
|
72
|
+
if (guild) {
|
73
|
+
for (const mention of roles) {
|
74
|
+
const role = guild.roles.cache.get(mention);
|
75
|
+
if (role) this.roles.set(role.id, role);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
} else {
|
79
|
+
this.roles = new Collection();
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Cached members for {@link MessageMentions#members}
|
84
|
+
* @type {?Collection<Snowflake, GuildMember>}
|
85
|
+
* @private
|
86
|
+
*/
|
87
|
+
this._members = null;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Cached channels for {@link MessageMentions#channels}
|
91
|
+
* @type {?Collection<Snowflake, Channel>}
|
92
|
+
* @private
|
93
|
+
*/
|
94
|
+
this._channels = null;
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Cached users for {@link MessageMentions#parsedUsers}
|
98
|
+
* @type {?Collection<Snowflake, User>}
|
99
|
+
* @private
|
100
|
+
*/
|
101
|
+
this._parsedUsers = null;
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Crossposted channel data.
|
105
|
+
* @typedef {Object} CrosspostedChannel
|
106
|
+
* @property {Snowflake} channelId The mentioned channel's id
|
107
|
+
* @property {Snowflake} guildId The id of the guild that has the channel
|
108
|
+
* @property {ChannelType} type The channel's type
|
109
|
+
* @property {string} name The channel's name
|
110
|
+
*/
|
111
|
+
|
112
|
+
if (crosspostedChannels) {
|
113
|
+
if (crosspostedChannels instanceof Collection) {
|
114
|
+
/**
|
115
|
+
* A collection of crossposted channels
|
116
|
+
* <info>Order as received from the API, not as they appear in the message content</info>
|
117
|
+
* @type {Collection<Snowflake, CrosspostedChannel>}
|
118
|
+
*/
|
119
|
+
this.crosspostedChannels = new Collection(crosspostedChannels);
|
120
|
+
} else {
|
121
|
+
this.crosspostedChannels = new Collection();
|
122
|
+
const channelTypes = Object.keys(ChannelTypes);
|
123
|
+
for (const d of crosspostedChannels) {
|
124
|
+
const type = channelTypes[d.type];
|
125
|
+
this.crosspostedChannels.set(d.id, {
|
126
|
+
channelId: d.id,
|
127
|
+
guildId: d.guild_id,
|
128
|
+
type: type ?? 'UNKNOWN',
|
129
|
+
name: d.name,
|
130
|
+
});
|
131
|
+
}
|
132
|
+
}
|
133
|
+
} else {
|
134
|
+
this.crosspostedChannels = new Collection();
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* The author of the message that this message is a reply to
|
139
|
+
* @type {?User}
|
140
|
+
*/
|
141
|
+
this.repliedUser = repliedUser ? this.client.users._add(repliedUser) : null;
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Any members that were mentioned (only in {@link Guild}s)
|
146
|
+
* <info>Order as received from the API, not as they appear in the message content</info>
|
147
|
+
* @type {?Collection<Snowflake, GuildMember>}
|
148
|
+
* @readonly
|
149
|
+
*/
|
150
|
+
get members() {
|
151
|
+
if (this._members) return this._members;
|
152
|
+
if (!this.guild) return null;
|
153
|
+
this._members = new Collection();
|
154
|
+
this.users.forEach(user => {
|
155
|
+
const member = this.guild.members.resolve(user);
|
156
|
+
if (member) this._members.set(member.user.id, member);
|
157
|
+
});
|
158
|
+
return this._members;
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Any channels that were mentioned
|
163
|
+
* <info>Order as they appear first in the message content</info>
|
164
|
+
* @type {Collection<Snowflake, Channel>}
|
165
|
+
* @readonly
|
166
|
+
*/
|
167
|
+
get channels() {
|
168
|
+
if (this._channels) return this._channels;
|
169
|
+
this._channels = new Collection();
|
170
|
+
let matches;
|
171
|
+
while ((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) {
|
172
|
+
const chan = this.client.channels.cache.get(matches[1]);
|
173
|
+
if (chan) this._channels.set(chan.id, chan);
|
174
|
+
}
|
175
|
+
return this._channels;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Any user mentions that were included in the message content
|
180
|
+
* <info>Order as they appear first in the message content</info>
|
181
|
+
* @type {Collection<Snowflake, User>}
|
182
|
+
* @readonly
|
183
|
+
*/
|
184
|
+
get parsedUsers() {
|
185
|
+
if (this._parsedUsers) return this._parsedUsers;
|
186
|
+
this._parsedUsers = new Collection();
|
187
|
+
let matches;
|
188
|
+
while ((matches = this.constructor.USERS_PATTERN.exec(this._content)) !== null) {
|
189
|
+
const user = this.client.users.cache.get(matches[1]);
|
190
|
+
if (user) this._parsedUsers.set(user.id, user);
|
191
|
+
}
|
192
|
+
return this._parsedUsers;
|
193
|
+
}
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Options used to check for a mention.
|
197
|
+
* @typedef {Object} MessageMentionsHasOptions
|
198
|
+
* @property {boolean} [ignoreDirect=false] Whether to ignore direct mentions to the item
|
199
|
+
* @property {boolean} [ignoreRoles=false] Whether to ignore role mentions to a guild member
|
200
|
+
* @property {boolean} [ignoreRepliedUser=false] Whether to ignore replied user mention to an user
|
201
|
+
* @property {boolean} [ignoreEveryone=false] Whether to ignore `@everyone`/`@here` mentions
|
202
|
+
*/
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Checks if a user, guild member, thread member, role, or channel is mentioned.
|
206
|
+
* Takes into account user mentions, role mentions, channel mentions,
|
207
|
+
* replied user mention, and `@everyone`/`@here` mentions.
|
208
|
+
* @param {UserResolvable|RoleResolvable|ChannelResolvable} data The User/Role/Channel to check for
|
209
|
+
* @param {MessageMentionsHasOptions} [options] The options for the check
|
210
|
+
* @returns {boolean}
|
211
|
+
*/
|
212
|
+
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreRepliedUser = false, ignoreEveryone = false } = {}) {
|
213
|
+
const user = this.client.users.resolve(data);
|
214
|
+
if (!ignoreEveryone && user && this.everyone) return true;
|
215
|
+
|
216
|
+
const userWasRepliedTo = user && this.repliedUser?.id === user.id;
|
217
|
+
|
218
|
+
if (!ignoreRepliedUser && userWasRepliedTo && this.users.has(user.id)) return true;
|
219
|
+
if (!ignoreRepliedUser && this.users.has(this.repliedUser?.id) && this.repliedUser?.id === user?.id) return true;
|
220
|
+
if (!ignoreDirect) {
|
221
|
+
if (user && (!ignoreRepliedUser || this.parsedUsers.has(user.id)) && this.users.has(user.id)) return true;
|
222
|
+
|
223
|
+
const role = this.guild?.roles.resolve(data);
|
224
|
+
if (role && this.roles.has(role.id)) return true;
|
225
|
+
|
226
|
+
const channel = this.client.channels.resolve(data);
|
227
|
+
if (channel && this.channels.has(channel.id)) return true;
|
228
|
+
}
|
229
|
+
if (user && !ignoreEveryone && this.everyone) return true;
|
230
|
+
if (!ignoreRoles) {
|
231
|
+
const member = this.guild?.members.resolve(data);
|
232
|
+
if (member) {
|
233
|
+
for (const mentionedRole of this.roles.values()) if (member.roles.cache.has(mentionedRole.id)) return true;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
return false;
|
238
|
+
}
|
239
|
+
|
240
|
+
toJSON() {
|
241
|
+
return Util.flatten(this, {
|
242
|
+
members: true,
|
243
|
+
channels: true,
|
244
|
+
});
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Regular expression that globally matches `@everyone` and `@here`
|
250
|
+
* @type {RegExp}
|
251
|
+
*/
|
252
|
+
MessageMentions.EVERYONE_PATTERN = /@(everyone|here)/g;
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Regular expression that globally matches user mentions like `<@81440962496172032>`
|
256
|
+
* @type {RegExp}
|
257
|
+
*/
|
258
|
+
MessageMentions.USERS_PATTERN = /<@!?(\d{17,19})>/g;
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Regular expression that globally matches role mentions like `<@&297577916114403338>`
|
262
|
+
* @type {RegExp}
|
263
|
+
*/
|
264
|
+
MessageMentions.ROLES_PATTERN = /<@&(\d{17,19})>/g;
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Regular expression that globally matches channel mentions like `<#222079895583457280>`
|
268
|
+
* @type {RegExp}
|
269
|
+
*/
|
270
|
+
MessageMentions.CHANNELS_PATTERN = /<#(\d{17,19})>/g;
|
271
|
+
|
272
|
+
module.exports = MessageMentions;
|
@@ -0,0 +1,358 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Buffer } = require('node:buffer');
|
4
|
+
const BaseMessageComponent = require('./BaseMessageComponent');
|
5
|
+
const MessageEmbed = require('./MessageEmbed');
|
6
|
+
const WebEmbed = require('./WebEmbed');
|
7
|
+
const { RangeError } = require('../errors');
|
8
|
+
const ActivityFlags = require('../util/ActivityFlags');
|
9
|
+
const DataResolver = require('../util/DataResolver');
|
10
|
+
const MessageFlags = require('../util/MessageFlags');
|
11
|
+
const Util = require('../util/Util');
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Represents a message to be sent to the API.
|
15
|
+
*/
|
16
|
+
class MessagePayload {
|
17
|
+
/**
|
18
|
+
* @param {MessageTarget} target The target for this message to be sent to
|
19
|
+
* @param {MessageOptions|WebhookMessageOptions} options Options passed in from send
|
20
|
+
*/
|
21
|
+
constructor(target, options) {
|
22
|
+
/**
|
23
|
+
* The target for this message to be sent to
|
24
|
+
* @type {MessageTarget}
|
25
|
+
*/
|
26
|
+
this.target = target;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Options passed in from send
|
30
|
+
* @type {MessageOptions|WebhookMessageOptions}
|
31
|
+
*/
|
32
|
+
this.options = options;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Data sendable to the API
|
36
|
+
* @type {?APIMessage}
|
37
|
+
*/
|
38
|
+
this.data = null;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @typedef {Object} MessageFile
|
42
|
+
* @property {Buffer|string|Stream} attachment The original attachment that generated this file
|
43
|
+
* @property {string} name The name of this file
|
44
|
+
* @property {Buffer|Stream} file The file to be sent to the API
|
45
|
+
* @extends {APIAttachment}
|
46
|
+
*/
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Files sendable to the API
|
50
|
+
* @type {?MessageFile[]}
|
51
|
+
*/
|
52
|
+
this.files = null;
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Whether or not using new API to upload files
|
57
|
+
* @type {boolean}
|
58
|
+
* @readonly
|
59
|
+
*/
|
60
|
+
get usingNewAttachmentAPI() {
|
61
|
+
return Boolean(this.options?.usingNewAttachmentAPI);
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Whether or not the target is a {@link Webhook} or a {@link WebhookClient}
|
66
|
+
* @type {boolean}
|
67
|
+
* @readonly
|
68
|
+
*/
|
69
|
+
get isWebhook() {
|
70
|
+
const Webhook = require('./Webhook');
|
71
|
+
const WebhookClient = require('../client/WebhookClient');
|
72
|
+
return this.target instanceof Webhook || this.target instanceof WebhookClient;
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Whether or not the target is a {@link User}
|
77
|
+
* @type {boolean}
|
78
|
+
* @readonly
|
79
|
+
*/
|
80
|
+
get isUser() {
|
81
|
+
const User = require('./User');
|
82
|
+
const { GuildMember } = require('./GuildMember');
|
83
|
+
return this.target instanceof User || this.target instanceof GuildMember;
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Whether or not the target is a {@link Message}
|
88
|
+
* @type {boolean}
|
89
|
+
* @readonly
|
90
|
+
*/
|
91
|
+
get isMessage() {
|
92
|
+
const { Message } = require('./Message');
|
93
|
+
return this.target instanceof Message;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Whether or not the target is a {@link MessageManager}
|
98
|
+
* @type {boolean}
|
99
|
+
* @readonly
|
100
|
+
*/
|
101
|
+
get isMessageManager() {
|
102
|
+
const MessageManager = require('../managers/MessageManager');
|
103
|
+
return this.target instanceof MessageManager;
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Whether or not the target is an {@link Interaction} or an {@link InteractionWebhook}
|
108
|
+
* @type {boolean}
|
109
|
+
* @readonly
|
110
|
+
*/
|
111
|
+
get isInteraction() {
|
112
|
+
const Interaction = require('./Interaction');
|
113
|
+
const InteractionWebhook = require('./InteractionWebhook');
|
114
|
+
return this.target instanceof Interaction || this.target instanceof InteractionWebhook;
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Makes the content of this message.
|
119
|
+
* @returns {?string}
|
120
|
+
*/
|
121
|
+
makeContent() {
|
122
|
+
let content;
|
123
|
+
if (this.options.content === null) {
|
124
|
+
content = '';
|
125
|
+
} else if (typeof this.options.content !== 'undefined') {
|
126
|
+
content = Util.verifyString(this.options.content, RangeError, 'MESSAGE_CONTENT_TYPE', false);
|
127
|
+
}
|
128
|
+
|
129
|
+
return content;
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Resolves data.
|
134
|
+
* @returns {MessagePayload}
|
135
|
+
*/
|
136
|
+
async resolveData() {
|
137
|
+
if (this.data) return this;
|
138
|
+
const isInteraction = this.isInteraction;
|
139
|
+
const isWebhook = this.isWebhook;
|
140
|
+
|
141
|
+
let content = this.makeContent();
|
142
|
+
const tts = Boolean(this.options.tts);
|
143
|
+
|
144
|
+
let nonce;
|
145
|
+
if (typeof this.options.nonce !== 'undefined') {
|
146
|
+
nonce = this.options.nonce;
|
147
|
+
// eslint-disable-next-line max-len
|
148
|
+
if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') {
|
149
|
+
throw new RangeError('MESSAGE_NONCE_TYPE');
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
const components = this.options.components?.map(c => BaseMessageComponent.create(c).toJSON());
|
154
|
+
|
155
|
+
let username;
|
156
|
+
let avatarURL;
|
157
|
+
let threadName;
|
158
|
+
if (isWebhook) {
|
159
|
+
username = this.options.username ?? this.target.name;
|
160
|
+
if (this.options.avatarURL) avatarURL = this.options.avatarURL;
|
161
|
+
if (this.options.threadName) threadName = this.options.threadName;
|
162
|
+
}
|
163
|
+
|
164
|
+
let flags;
|
165
|
+
if (
|
166
|
+
typeof this.options.flags !== 'undefined' ||
|
167
|
+
(this.isMessage && typeof this.options.reply === 'undefined') ||
|
168
|
+
this.isMessageManager
|
169
|
+
) {
|
170
|
+
// eslint-disable-next-line eqeqeq
|
171
|
+
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags?.bitfield;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (isInteraction && this.options.ephemeral) {
|
175
|
+
flags |= MessageFlags.FLAGS.EPHEMERAL;
|
176
|
+
}
|
177
|
+
|
178
|
+
let allowedMentions =
|
179
|
+
typeof this.options.allowedMentions === 'undefined'
|
180
|
+
? this.target.client.options.allowedMentions
|
181
|
+
: this.options.allowedMentions;
|
182
|
+
|
183
|
+
if (allowedMentions) {
|
184
|
+
allowedMentions = Util.cloneObject(allowedMentions);
|
185
|
+
allowedMentions.replied_user = allowedMentions.repliedUser;
|
186
|
+
delete allowedMentions.repliedUser;
|
187
|
+
}
|
188
|
+
|
189
|
+
let message_reference;
|
190
|
+
if (typeof this.options.reply === 'object') {
|
191
|
+
const reference = this.options.reply.messageReference;
|
192
|
+
const message_id = this.isMessage ? reference.id ?? reference : this.target.messages.resolveId(reference);
|
193
|
+
if (message_id) {
|
194
|
+
message_reference = {
|
195
|
+
message_id,
|
196
|
+
fail_if_not_exists: this.options.reply.failIfNotExists ?? this.target.client.options.failIfNotExists,
|
197
|
+
};
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
const attachments = this.options.files?.map((file, index) => ({
|
202
|
+
id: index.toString(),
|
203
|
+
description: file.description,
|
204
|
+
}));
|
205
|
+
if (Array.isArray(this.options.attachments)) {
|
206
|
+
this.options.attachments.push(...(attachments ?? []));
|
207
|
+
} else {
|
208
|
+
this.options.attachments = attachments;
|
209
|
+
}
|
210
|
+
|
211
|
+
if (this.options.embeds) {
|
212
|
+
if (!Array.isArray(this.options.embeds)) {
|
213
|
+
this.options.embeds = [this.options.embeds];
|
214
|
+
}
|
215
|
+
|
216
|
+
const webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
|
217
|
+
this.options.embeds = this.options.embeds.filter(e => !(e instanceof WebEmbed));
|
218
|
+
|
219
|
+
if (webembeds.length > 0) {
|
220
|
+
if (!content) content = '';
|
221
|
+
// Add hidden embed link
|
222
|
+
content += `\n${WebEmbed.hiddenEmbed} \n`;
|
223
|
+
if (webembeds.length > 1) {
|
224
|
+
console.warn('[WARN] Multiple webembeds are not supported, this will be ignored.');
|
225
|
+
}
|
226
|
+
// Const embed = webembeds[0];
|
227
|
+
for (const webE of webembeds) {
|
228
|
+
const data = await webE.toMessage();
|
229
|
+
content += `\n${data}`;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
// Check content
|
233
|
+
if (typeof content == 'string' && content.length > 2000) {
|
234
|
+
console.warn('[WARN] Content is longer than 2000 characters.');
|
235
|
+
}
|
236
|
+
if (typeof content == 'string' && content.length > 4000) {
|
237
|
+
// Max length if user has nitro boost
|
238
|
+
throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
// Activity
|
243
|
+
let activity;
|
244
|
+
if (
|
245
|
+
this.options.activity instanceof Object &&
|
246
|
+
typeof this.options.activity.partyId == 'string' &&
|
247
|
+
this.options.activity.type
|
248
|
+
) {
|
249
|
+
const type = ActivityFlags.resolve(this.options.activity.type);
|
250
|
+
const sessionId = this.target.client.sessionId;
|
251
|
+
const partyId = this.options.activity.partyId;
|
252
|
+
activity = {
|
253
|
+
type,
|
254
|
+
party_id: partyId,
|
255
|
+
session_id: sessionId,
|
256
|
+
};
|
257
|
+
}
|
258
|
+
|
259
|
+
this.data = {
|
260
|
+
activity,
|
261
|
+
content,
|
262
|
+
tts,
|
263
|
+
nonce,
|
264
|
+
embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()),
|
265
|
+
components,
|
266
|
+
username,
|
267
|
+
avatar_url: avatarURL,
|
268
|
+
allowed_mentions:
|
269
|
+
typeof content === 'undefined' && typeof message_reference === 'undefined' ? undefined : allowedMentions,
|
270
|
+
flags,
|
271
|
+
message_reference,
|
272
|
+
attachments: this.options.attachments,
|
273
|
+
sticker_ids: this.options.stickers?.map(sticker => sticker.id ?? sticker),
|
274
|
+
thread_name: threadName,
|
275
|
+
};
|
276
|
+
return this;
|
277
|
+
}
|
278
|
+
|
279
|
+
/**
|
280
|
+
* Resolves files.
|
281
|
+
* @returns {Promise<MessagePayload>}
|
282
|
+
*/
|
283
|
+
async resolveFiles() {
|
284
|
+
if (this.files) return this;
|
285
|
+
|
286
|
+
this.files = await Promise.all(this.options.files?.map(file => this.constructor.resolveFile(file)) ?? []);
|
287
|
+
return this;
|
288
|
+
}
|
289
|
+
|
290
|
+
/**
|
291
|
+
* Resolves a single file into an object sendable to the API.
|
292
|
+
* @param {BufferResolvable|Stream|FileOptions|MessageAttachment} fileLike Something that could be resolved to a file
|
293
|
+
* @returns {Promise<MessageFile>}
|
294
|
+
*/
|
295
|
+
static async resolveFile(fileLike) {
|
296
|
+
let attachment;
|
297
|
+
let name;
|
298
|
+
|
299
|
+
const findName = thing => {
|
300
|
+
if (typeof thing === 'string') {
|
301
|
+
return Util.basename(thing);
|
302
|
+
}
|
303
|
+
|
304
|
+
if (thing.path) {
|
305
|
+
return Util.basename(thing.path);
|
306
|
+
}
|
307
|
+
|
308
|
+
return 'file.jpg';
|
309
|
+
};
|
310
|
+
|
311
|
+
const ownAttachment =
|
312
|
+
typeof fileLike === 'string' || fileLike instanceof Buffer || typeof fileLike.pipe === 'function';
|
313
|
+
if (ownAttachment) {
|
314
|
+
attachment = fileLike;
|
315
|
+
name = findName(attachment);
|
316
|
+
} else {
|
317
|
+
attachment = fileLike.attachment;
|
318
|
+
name = fileLike.name ?? findName(attachment);
|
319
|
+
}
|
320
|
+
|
321
|
+
const resource = await DataResolver.resolveFile(attachment);
|
322
|
+
return {
|
323
|
+
attachment,
|
324
|
+
name,
|
325
|
+
file: resource,
|
326
|
+
description: fileLike.description,
|
327
|
+
duration_secs: fileLike.duration,
|
328
|
+
waveform: fileLike.waveform,
|
329
|
+
};
|
330
|
+
}
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Creates a {@link MessagePayload} from user-level arguments.
|
334
|
+
* @param {MessageTarget} target Target to send to
|
335
|
+
* @param {string|MessageOptions|WebhookMessageOptions} options Options or content to use
|
336
|
+
* @param {MessageOptions|WebhookMessageOptions} [extra={}] Extra options to add onto specified options
|
337
|
+
* @returns {MessagePayload}
|
338
|
+
*/
|
339
|
+
static create(target, options, extra = {}) {
|
340
|
+
return new this(
|
341
|
+
target,
|
342
|
+
typeof options !== 'object' || options === null ? { content: options, ...extra } : { ...options, ...extra },
|
343
|
+
);
|
344
|
+
}
|
345
|
+
}
|
346
|
+
|
347
|
+
module.exports = MessagePayload;
|
348
|
+
|
349
|
+
/**
|
350
|
+
* A target for a message.
|
351
|
+
* @typedef {TextBasedChannels|DMChannel|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook|
|
352
|
+
* Message|MessageManager} MessageTarget
|
353
|
+
*/
|
354
|
+
|
355
|
+
/**
|
356
|
+
* @external APIMessage
|
357
|
+
* @see {@link https://discord.com/developers/docs/resources/channel#message-object}
|
358
|
+
*/
|