@ovencord/discord.js 14.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +148 -0
- package/package.json +73 -0
- package/src/client/Client.ts +967 -0
- package/src/client/actions/Action.ts +141 -0
- package/src/client/actions/ActionsManager.ts +138 -0
- package/src/client/actions/ChannelCreate.ts +21 -0
- package/src/client/actions/ChannelDelete.ts +20 -0
- package/src/client/actions/ChannelUpdate.ts +38 -0
- package/src/client/actions/GuildChannelsPositionUpdate.ts +17 -0
- package/src/client/actions/GuildEmojiCreate.ts +17 -0
- package/src/client/actions/GuildEmojiDelete.ts +16 -0
- package/src/client/actions/GuildEmojiUpdate.ts +17 -0
- package/src/client/actions/GuildEmojisUpdate.ts +30 -0
- package/src/client/actions/GuildMemberRemove.ts +29 -0
- package/src/client/actions/GuildMemberUpdate.ts +41 -0
- package/src/client/actions/GuildRoleCreate.ts +23 -0
- package/src/client/actions/GuildRoleDelete.ts +26 -0
- package/src/client/actions/GuildRolesPositionUpdate.ts +17 -0
- package/src/client/actions/GuildScheduledEventDelete.ts +28 -0
- package/src/client/actions/GuildScheduledEventUserAdd.ts +29 -0
- package/src/client/actions/GuildScheduledEventUserRemove.ts +29 -0
- package/src/client/actions/GuildSoundboardSoundDelete.ts +26 -0
- package/src/client/actions/GuildStickerCreate.ts +17 -0
- package/src/client/actions/GuildStickerDelete.ts +16 -0
- package/src/client/actions/GuildStickerUpdate.ts +17 -0
- package/src/client/actions/GuildStickersUpdate.ts +30 -0
- package/src/client/actions/GuildUpdate.ts +30 -0
- package/src/client/actions/InteractionCreate.ts +104 -0
- package/src/client/actions/MessageCreate.ts +38 -0
- package/src/client/actions/MessageDelete.ts +29 -0
- package/src/client/actions/MessageDeleteBulk.ts +45 -0
- package/src/client/actions/MessagePollVoteAdd.ts +37 -0
- package/src/client/actions/MessagePollVoteRemove.ts +35 -0
- package/src/client/actions/MessageReactionAdd.ts +68 -0
- package/src/client/actions/MessageReactionRemove.ts +47 -0
- package/src/client/actions/MessageReactionRemoveAll.ts +30 -0
- package/src/client/actions/MessageReactionRemoveEmoji.ts +25 -0
- package/src/client/actions/MessageUpdate.ts +22 -0
- package/src/client/actions/StageInstanceCreate.ts +25 -0
- package/src/client/actions/StageInstanceDelete.ts +28 -0
- package/src/client/actions/StageInstanceUpdate.ts +27 -0
- package/src/client/actions/ThreadCreate.ts +22 -0
- package/src/client/actions/ThreadMembersUpdate.ts +45 -0
- package/src/client/actions/TypingStart.ts +26 -0
- package/src/client/actions/UserUpdate.ts +33 -0
- package/src/client/voice/ClientVoiceManager.ts +46 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.ts +17 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.ts +18 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.ts +21 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.ts +4 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.ts +22 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/ENTITLEMENT_CREATE.ts +14 -0
- package/src/client/websocket/handlers/ENTITLEMENT_DELETE.ts +18 -0
- package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.ts +15 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_CREATE.ts +34 -0
- package/src/client/websocket/handlers/GUILD_DELETE.ts +36 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.ts +15 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.ts +40 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.ts +17 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.ts +21 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.ts +17 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.ts +19 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.ts +24 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.ts +18 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.ts +20 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.ts +4 -0
- package/src/client/websocket/handlers/INVITE_CREATE.ts +20 -0
- package/src/client/websocket/handlers/INVITE_DELETE.ts +23 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.ts +4 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.ts +42 -0
- package/src/client/websocket/handlers/RATE_LIMITED.ts +23 -0
- package/src/client/websocket/handlers/READY.ts +29 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.ts +24 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.ts +4 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.ts +14 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.ts +16 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/THREAD_CREATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_DELETE.ts +17 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.ts +50 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.ts +25 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/TYPING_START.ts +4 -0
- package/src/client/websocket/handlers/USER_UPDATE.ts +4 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.ts +16 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.ts +5 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.ts +37 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.ts +16 -0
- package/src/client/websocket/handlers/index.ts +74 -0
- package/src/errors/DJSError.ts +50 -0
- package/src/errors/ErrorCodes.ts +277 -0
- package/src/errors/Messages.ts +155 -0
- package/src/errors/index.ts +6 -0
- package/src/index.ts +241 -0
- package/src/managers/ApplicationCommandManager.ts +303 -0
- package/src/managers/ApplicationCommandPermissionsManager.ts +453 -0
- package/src/managers/ApplicationEmojiManager.ts +149 -0
- package/src/managers/AutoModerationRuleManager.ts +307 -0
- package/src/managers/BaseManager.ts +13 -0
- package/src/managers/CachedManager.ts +56 -0
- package/src/managers/CategoryChannelChildManager.ts +81 -0
- package/src/managers/ChannelManager.ts +194 -0
- package/src/managers/DMMessageManager.ts +15 -0
- package/src/managers/DataManager.ts +38 -0
- package/src/managers/EntitlementManager.ts +182 -0
- package/src/managers/GuildApplicationCommandManager.ts +29 -0
- package/src/managers/GuildBanManager.ts +221 -0
- package/src/managers/GuildChannelManager.ts +552 -0
- package/src/managers/GuildEmojiManager.ts +262 -0
- package/src/managers/GuildEmojiRoleManager.ts +134 -0
- package/src/managers/GuildForumThreadManager.ts +84 -0
- package/src/managers/GuildInviteManager.ts +236 -0
- package/src/managers/GuildManager.ts +265 -0
- package/src/managers/GuildMemberManager.ts +619 -0
- package/src/managers/GuildMemberRoleManager.ts +230 -0
- package/src/managers/GuildMessageManager.ts +31 -0
- package/src/managers/GuildScheduledEventManager.ts +330 -0
- package/src/managers/GuildSoundboardSoundManager.ts +157 -0
- package/src/managers/GuildStickerManager.ts +192 -0
- package/src/managers/GuildTextThreadManager.ts +91 -0
- package/src/managers/MessageManager.ts +352 -0
- package/src/managers/PartialGroupDMMessageManager.ts +15 -0
- package/src/managers/PermissionOverwriteManager.ts +174 -0
- package/src/managers/PollAnswerVoterManager.ts +59 -0
- package/src/managers/PresenceManager.ts +60 -0
- package/src/managers/ReactionManager.ts +72 -0
- package/src/managers/ReactionUserManager.ts +82 -0
- package/src/managers/RoleManager.ts +432 -0
- package/src/managers/StageInstanceManager.ts +166 -0
- package/src/managers/SubscriptionManager.ts +83 -0
- package/src/managers/ThreadManager.ts +210 -0
- package/src/managers/ThreadMemberManager.ts +194 -0
- package/src/managers/UserManager.ts +139 -0
- package/src/managers/VoiceStateManager.ts +61 -0
- package/src/sharding/Shard.ts +513 -0
- package/src/sharding/ShardClientUtil.ts +293 -0
- package/src/sharding/ShardingManager.ts +374 -0
- package/src/structures/ActionRow.ts +31 -0
- package/src/structures/AnnouncementChannel.ts +25 -0
- package/src/structures/AnonymousGuild.ts +110 -0
- package/src/structures/ApplicationCommand.ts +675 -0
- package/src/structures/ApplicationEmoji.ts +189 -0
- package/src/structures/ApplicationRoleConnectionMetadata.ts +54 -0
- package/src/structures/Attachment.ts +189 -0
- package/src/structures/AuthorizingIntegrationOwners.ts +63 -0
- package/src/structures/AutoModerationActionExecution.ts +138 -0
- package/src/structures/AutoModerationRule.ts +325 -0
- package/src/structures/AutocompleteInteraction.ts +115 -0
- package/src/structures/Base.ts +37 -0
- package/src/structures/BaseChannel.ts +188 -0
- package/src/structures/BaseGuild.ts +134 -0
- package/src/structures/BaseGuildEmoji.ts +113 -0
- package/src/structures/BaseGuildTextChannel.ts +230 -0
- package/src/structures/BaseGuildVoiceChannel.ts +270 -0
- package/src/structures/BaseInteraction.ts +393 -0
- package/src/structures/BaseInvite.ts +192 -0
- package/src/structures/BaseSelectMenuComponent.ts +58 -0
- package/src/structures/ButtonComponent.ts +68 -0
- package/src/structures/ButtonInteraction.ts +8 -0
- package/src/structures/CategoryChannel.ts +46 -0
- package/src/structures/ChannelSelectMenuComponent.ts +18 -0
- package/src/structures/ChannelSelectMenuInteraction.ts +34 -0
- package/src/structures/ChatInputCommandInteraction.ts +43 -0
- package/src/structures/ClientApplication.ts +470 -0
- package/src/structures/ClientPresence.ts +87 -0
- package/src/structures/ClientUser.ts +219 -0
- package/src/structures/CommandInteraction.ts +193 -0
- package/src/structures/CommandInteractionOptionResolver.ts +336 -0
- package/src/structures/Component.ts +59 -0
- package/src/structures/ContainerComponent.ts +63 -0
- package/src/structures/ContextMenuCommandInteraction.ts +68 -0
- package/src/structures/DMChannel.ts +148 -0
- package/src/structures/DirectoryChannel.ts +40 -0
- package/src/structures/Embed.ts +251 -0
- package/src/structures/Emoji.ts +61 -0
- package/src/structures/Entitlement.ts +206 -0
- package/src/structures/FileComponent.ts +41 -0
- package/src/structures/ForumChannel.ts +31 -0
- package/src/structures/GroupDMInvite.ts +34 -0
- package/src/structures/Guild.ts +1605 -0
- package/src/structures/GuildAuditLogs.ts +99 -0
- package/src/structures/GuildAuditLogsEntry.ts +557 -0
- package/src/structures/GuildBan.ts +65 -0
- package/src/structures/GuildChannel.ts +515 -0
- package/src/structures/GuildEmoji.ts +159 -0
- package/src/structures/GuildInvite.ts +233 -0
- package/src/structures/GuildMember.ts +643 -0
- package/src/structures/GuildOnboarding.ts +73 -0
- package/src/structures/GuildOnboardingPrompt.ts +93 -0
- package/src/structures/GuildOnboardingPromptOption.ts +100 -0
- package/src/structures/GuildPreview.ts +218 -0
- package/src/structures/GuildPreviewEmoji.ts +28 -0
- package/src/structures/GuildScheduledEvent.ts +593 -0
- package/src/structures/GuildTemplate.ts +229 -0
- package/src/structures/Integration.ts +257 -0
- package/src/structures/IntegrationApplication.ts +84 -0
- package/src/structures/InteractionCallback.ts +86 -0
- package/src/structures/InteractionCallbackResource.ts +57 -0
- package/src/structures/InteractionCallbackResponse.ts +35 -0
- package/src/structures/InteractionCollector.ts +260 -0
- package/src/structures/InteractionWebhook.ts +65 -0
- package/src/structures/InviteGuild.ts +22 -0
- package/src/structures/LabelComponent.ts +51 -0
- package/src/structures/MediaChannel.ts +8 -0
- package/src/structures/MediaGalleryComponent.ts +31 -0
- package/src/structures/MediaGalleryItem.ts +54 -0
- package/src/structures/MentionableSelectMenuComponent.ts +8 -0
- package/src/structures/MentionableSelectMenuInteraction.ts +76 -0
- package/src/structures/Message.ts +1202 -0
- package/src/structures/MessageCollector.ts +155 -0
- package/src/structures/MessageComponentInteraction.ts +132 -0
- package/src/structures/MessageContextMenuCommandInteraction.ts +18 -0
- package/src/structures/MessageMentions.ts +327 -0
- package/src/structures/MessagePayload.ts +325 -0
- package/src/structures/MessageReaction.ts +219 -0
- package/src/structures/ModalComponentResolver.ts +237 -0
- package/src/structures/ModalSubmitInteraction.ts +260 -0
- package/src/structures/OAuth2Guild.ts +30 -0
- package/src/structures/PartialGroupDMChannel.ts +151 -0
- package/src/structures/PermissionOverwrites.ts +222 -0
- package/src/structures/Poll.ts +195 -0
- package/src/structures/PollAnswer.ts +100 -0
- package/src/structures/Presence.ts +448 -0
- package/src/structures/PrimaryEntryPointCommandInteraction.ts +8 -0
- package/src/structures/ReactionCollector.ts +245 -0
- package/src/structures/ReactionEmoji.ts +30 -0
- package/src/structures/Role.ts +543 -0
- package/src/structures/RoleSelectMenuComponent.ts +8 -0
- package/src/structures/RoleSelectMenuInteraction.ts +34 -0
- package/src/structures/SKU.ts +62 -0
- package/src/structures/SectionComponent.ts +44 -0
- package/src/structures/SeparatorComponent.ts +29 -0
- package/src/structures/SoundboardSound.ts +176 -0
- package/src/structures/StageChannel.ts +118 -0
- package/src/structures/StageInstance.ts +173 -0
- package/src/structures/Sticker.ts +300 -0
- package/src/structures/StickerPack.ts +111 -0
- package/src/structures/StringSelectMenuComponent.ts +18 -0
- package/src/structures/StringSelectMenuInteraction.ts +21 -0
- package/src/structures/Subscription.ts +138 -0
- package/src/structures/Team.ts +131 -0
- package/src/structures/TeamMember.ts +77 -0
- package/src/structures/TextChannel.ts +33 -0
- package/src/structures/TextDisplayComponent.ts +18 -0
- package/src/structures/TextInputComponent.ts +28 -0
- package/src/structures/ThreadChannel.ts +680 -0
- package/src/structures/ThreadMember.ts +125 -0
- package/src/structures/ThreadOnlyChannel.ts +276 -0
- package/src/structures/ThumbnailComponent.ts +51 -0
- package/src/structures/Typing.ts +81 -0
- package/src/structures/UnfurledMediaItem.ts +33 -0
- package/src/structures/User.ts +511 -0
- package/src/structures/UserContextMenuCommandInteraction.ts +28 -0
- package/src/structures/UserSelectMenuComponent.ts +8 -0
- package/src/structures/UserSelectMenuInteraction.ts +54 -0
- package/src/structures/VoiceChannel.ts +119 -0
- package/src/structures/VoiceChannelEffect.ts +92 -0
- package/src/structures/VoiceRegion.ts +52 -0
- package/src/structures/VoiceState.ts +346 -0
- package/src/structures/Webhook.ts +526 -0
- package/src/structures/WelcomeChannel.ts +67 -0
- package/src/structures/WelcomeScreen.ts +53 -0
- package/src/structures/Widget.ts +110 -0
- package/src/structures/WidgetMember.ts +124 -0
- package/src/structures/interfaces/Application.ts +179 -0
- package/src/structures/interfaces/Collector.ts +372 -0
- package/src/structures/interfaces/InteractionResponses.ts +384 -0
- package/src/structures/interfaces/TextBasedChannel.ts +430 -0
- package/src/util/APITypes.ts +690 -0
- package/src/util/ActivityFlagsBitField.ts +26 -0
- package/src/util/ApplicationFlagsBitField.ts +43 -0
- package/src/util/AttachmentFlagsBitField.ts +26 -0
- package/src/util/BitField.ts +178 -0
- package/src/util/ChannelFlagsBitField.ts +43 -0
- package/src/util/Channels.ts +165 -0
- package/src/util/Colors.ts +72 -0
- package/src/util/Components.ts +285 -0
- package/src/util/Constants.ts +251 -0
- package/src/util/DataResolver.ts +146 -0
- package/src/util/Enums.ts +10 -0
- package/src/util/Events.ts +178 -0
- package/src/util/GuildMemberFlagsBitField.ts +43 -0
- package/src/util/IntentsBitField.ts +35 -0
- package/src/util/InviteFlagsBitField.ts +26 -0
- package/src/util/Invites.ts +27 -0
- package/src/util/LimitedCollection.ts +73 -0
- package/src/util/MessageFlagsBitField.ts +43 -0
- package/src/util/Options.ts +215 -0
- package/src/util/Partials.ts +50 -0
- package/src/util/PermissionsBitField.ts +113 -0
- package/src/util/RoleFlagsBitField.ts +26 -0
- package/src/util/SKUFlagsBitField.ts +26 -0
- package/src/util/ShardEvents.ts +26 -0
- package/src/util/Status.ts +16 -0
- package/src/util/Sweepers.ts +532 -0
- package/src/util/Symbols.ts +1 -0
- package/src/util/SystemChannelFlagsBitField.ts +45 -0
- package/src/util/ThreadMemberFlagsBitField.ts +33 -0
- package/src/util/Transformers.ts +123 -0
- package/src/util/UserFlagsBitField.ts +33 -0
- package/src/util/Util.ts +519 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { isJSONEncodable, lazy } from '@ovencord/util';
|
|
3
|
+
import { DiscordSnowflake } from '@sapphire/snowflake';
|
|
4
|
+
import { DiscordjsError, DiscordjsRangeError, ErrorCodes } from '../errors/index.js';
|
|
5
|
+
import { resolveFile } from '../util/DataResolver.js';
|
|
6
|
+
import { MessageFlagsBitField } from '../util/MessageFlagsBitField.js';
|
|
7
|
+
import { findName, verifyString, resolvePartialEmoji } from '../util/Util.js';
|
|
8
|
+
|
|
9
|
+
// Fixes circular dependencies.
|
|
10
|
+
const getWebhook = lazy(() => require('./Webhook.js').Webhook);
|
|
11
|
+
const getUser = lazy(() => require('./User.js').User);
|
|
12
|
+
const getGuildMember = lazy(() => require('./GuildMember.js').GuildMember);
|
|
13
|
+
const getMessage = lazy(() => require('./Message.js').Message);
|
|
14
|
+
const getMessageManager = lazy(() => require('../managers/MessageManager.js').MessageManager);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents a message to be sent to the API.
|
|
18
|
+
*/
|
|
19
|
+
export class MessagePayload {
|
|
20
|
+
public target: any;
|
|
21
|
+
public options: any;
|
|
22
|
+
public body: any;
|
|
23
|
+
public files: any;
|
|
24
|
+
/**
|
|
25
|
+
* @param {MessageTarget} target The target for this message to be sent to
|
|
26
|
+
* @param {MessagePayloadOption} options The payload of this message
|
|
27
|
+
*/
|
|
28
|
+
constructor(target, options) {
|
|
29
|
+
/**
|
|
30
|
+
* The target for this message to be sent to
|
|
31
|
+
*
|
|
32
|
+
* @type {MessageTarget}
|
|
33
|
+
*/
|
|
34
|
+
this.target = target;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The payload of this message.
|
|
38
|
+
*
|
|
39
|
+
* @type {MessagePayloadOption}
|
|
40
|
+
*/
|
|
41
|
+
this.options = options;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Body sendable to the API
|
|
45
|
+
*
|
|
46
|
+
* @type {?APIMessage}
|
|
47
|
+
*/
|
|
48
|
+
this.body = null;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Files sendable to the API
|
|
52
|
+
*
|
|
53
|
+
* @type {?RawFile[]}
|
|
54
|
+
*/
|
|
55
|
+
this.files = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether or not the target is a {@link Webhook}
|
|
60
|
+
*
|
|
61
|
+
* @type {boolean}
|
|
62
|
+
* @readonly
|
|
63
|
+
*/
|
|
64
|
+
get isWebhook() {
|
|
65
|
+
return this.target instanceof getWebhook();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether or not the target is a {@link User}
|
|
70
|
+
*
|
|
71
|
+
* @type {boolean}
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
get isUser() {
|
|
75
|
+
return this.target instanceof getUser() || this.target instanceof getGuildMember();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether or not the target is a {@link Message}
|
|
80
|
+
*
|
|
81
|
+
* @type {boolean}
|
|
82
|
+
* @readonly
|
|
83
|
+
*/
|
|
84
|
+
get isMessage() {
|
|
85
|
+
return this.target instanceof getMessage();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Whether or not the target is a {@link MessageManager}
|
|
90
|
+
*
|
|
91
|
+
* @type {boolean}
|
|
92
|
+
* @readonly
|
|
93
|
+
*/
|
|
94
|
+
get isMessageManager() {
|
|
95
|
+
return this.target instanceof getMessageManager();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Makes the content of this message.
|
|
100
|
+
*
|
|
101
|
+
* @returns {?string}
|
|
102
|
+
*/
|
|
103
|
+
makeContent() {
|
|
104
|
+
let content;
|
|
105
|
+
if (this.options.content === null) {
|
|
106
|
+
content = '';
|
|
107
|
+
} else if (this.options.content !== undefined) {
|
|
108
|
+
content = verifyString(this.options.content, DiscordjsRangeError, ErrorCodes.MessageContentType, true);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the body.
|
|
116
|
+
*
|
|
117
|
+
* @returns {MessagePayload}
|
|
118
|
+
*/
|
|
119
|
+
resolveBody() {
|
|
120
|
+
if (this.body) return this;
|
|
121
|
+
const isWebhook = this.isWebhook;
|
|
122
|
+
|
|
123
|
+
const content = this.makeContent();
|
|
124
|
+
const tts = Boolean(this.options.tts);
|
|
125
|
+
|
|
126
|
+
let nonce;
|
|
127
|
+
if (this.options.nonce !== undefined) {
|
|
128
|
+
nonce = this.options.nonce;
|
|
129
|
+
if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') {
|
|
130
|
+
throw new DiscordjsRangeError(ErrorCodes.MessageNonceType);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let enforce_nonce = Boolean(this.options.enforceNonce);
|
|
135
|
+
|
|
136
|
+
// If `nonce` isn't provided, generate one & set `enforceNonce`
|
|
137
|
+
// Unless `enforceNonce` is explicitly set to `false`(not just falsy)
|
|
138
|
+
if (nonce === undefined) {
|
|
139
|
+
if (this.options.enforceNonce !== false && this.target.client.options.enforceNonce) {
|
|
140
|
+
nonce = DiscordSnowflake.generate().toString();
|
|
141
|
+
enforce_nonce = true;
|
|
142
|
+
} else if (enforce_nonce) {
|
|
143
|
+
throw new DiscordjsError(ErrorCodes.MessageNonceRequired);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const components = this.options.components?.map(component =>
|
|
148
|
+
isJSONEncodable(component) ? component.toJSON() : this.target.client.options.jsonTransformer(component),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
let username;
|
|
152
|
+
let avatarURL;
|
|
153
|
+
let threadName;
|
|
154
|
+
let appliedTags;
|
|
155
|
+
if (isWebhook) {
|
|
156
|
+
username = this.options.username ?? this.target.name;
|
|
157
|
+
if (this.options.avatarURL) avatarURL = this.options.avatarURL;
|
|
158
|
+
if (this.options.threadName) threadName = this.options.threadName;
|
|
159
|
+
if (this.options.appliedTags) appliedTags = this.options.appliedTags;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let flags;
|
|
163
|
+
if (
|
|
164
|
+
// eslint-disable-next-line eqeqeq
|
|
165
|
+
this.options.flags != null
|
|
166
|
+
) {
|
|
167
|
+
flags = new MessageFlagsBitField(this.options.flags).bitfield;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let allowedMentions =
|
|
171
|
+
this.options.allowedMentions === undefined
|
|
172
|
+
? this.target.client.options.allowedMentions
|
|
173
|
+
: this.options.allowedMentions;
|
|
174
|
+
|
|
175
|
+
if (allowedMentions?.repliedUser !== undefined) {
|
|
176
|
+
allowedMentions = { ...allowedMentions, replied_user: allowedMentions.repliedUser };
|
|
177
|
+
delete allowedMentions.repliedUser;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let message_reference;
|
|
181
|
+
if (this.options.messageReference) {
|
|
182
|
+
const reference = this.options.messageReference;
|
|
183
|
+
|
|
184
|
+
if (reference.messageId) {
|
|
185
|
+
message_reference = {
|
|
186
|
+
message_id: reference.messageId,
|
|
187
|
+
channel_id: reference.channelId,
|
|
188
|
+
guild_id: reference.guildId,
|
|
189
|
+
type: reference.type,
|
|
190
|
+
fail_if_not_exists: reference.failIfNotExists ?? this.target.client.options.failIfNotExists,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const attachments = this.options.files?.map((file, index) => ({
|
|
196
|
+
id: index.toString(),
|
|
197
|
+
description: file.description,
|
|
198
|
+
title: file.title,
|
|
199
|
+
waveform: file.waveform,
|
|
200
|
+
duration_secs: file.duration,
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
// Only passable during edits
|
|
204
|
+
if (Array.isArray(this.options.attachments)) {
|
|
205
|
+
attachments.push(
|
|
206
|
+
// Note how we don't check for file body encodable, since we aren't expecting file data here
|
|
207
|
+
...this.options.attachments.map(attachment => (isJSONEncodable(attachment) ? attachment.toJSON() : attachment)),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let poll;
|
|
212
|
+
if (this.options.poll) {
|
|
213
|
+
poll = isJSONEncodable(this.options.poll)
|
|
214
|
+
? this.options.poll.toJSON()
|
|
215
|
+
: {
|
|
216
|
+
question: {
|
|
217
|
+
text: this.options.poll.question.text,
|
|
218
|
+
},
|
|
219
|
+
answers: this.options.poll.answers.map(answer => ({
|
|
220
|
+
poll_media: { text: answer.text, emoji: resolvePartialEmoji(answer.emoji) },
|
|
221
|
+
})),
|
|
222
|
+
duration: this.options.poll.duration,
|
|
223
|
+
allow_multiselect: this.options.poll.allowMultiselect,
|
|
224
|
+
layout_type: this.options.poll.layoutType,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
this.body = {
|
|
229
|
+
content,
|
|
230
|
+
tts,
|
|
231
|
+
nonce,
|
|
232
|
+
enforce_nonce,
|
|
233
|
+
embeds: this.options.embeds?.map(embed =>
|
|
234
|
+
isJSONEncodable(embed) ? embed.toJSON() : this.target.client.options.jsonTransformer(embed),
|
|
235
|
+
),
|
|
236
|
+
components,
|
|
237
|
+
username,
|
|
238
|
+
avatar_url: avatarURL,
|
|
239
|
+
allowed_mentions:
|
|
240
|
+
this.isMessage && message_reference === undefined && this.target.author.id !== this.target.client.user.id
|
|
241
|
+
? undefined
|
|
242
|
+
: allowedMentions,
|
|
243
|
+
flags,
|
|
244
|
+
message_reference,
|
|
245
|
+
attachments,
|
|
246
|
+
sticker_ids: this.options.stickers?.map(sticker => sticker.id ?? sticker),
|
|
247
|
+
thread_name: threadName,
|
|
248
|
+
applied_tags: appliedTags,
|
|
249
|
+
poll,
|
|
250
|
+
};
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Resolves files.
|
|
256
|
+
*
|
|
257
|
+
* @returns {Promise<MessagePayload>}
|
|
258
|
+
*/
|
|
259
|
+
async resolveFiles() {
|
|
260
|
+
if (this.files) return this;
|
|
261
|
+
|
|
262
|
+
this.files = await Promise.all(this.options.files?.map(file => this.constructor.resolveFile(file)) ?? []);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Resolves a single file into an object sendable to the API.
|
|
268
|
+
*
|
|
269
|
+
* @param {AttachmentPayload|BufferResolvable|Stream} fileLike Something that could be resolved to a file
|
|
270
|
+
* @returns {Promise<RawFile>}
|
|
271
|
+
*/
|
|
272
|
+
static async resolveFile(fileLike) {
|
|
273
|
+
let attachment;
|
|
274
|
+
let name;
|
|
275
|
+
|
|
276
|
+
const ownAttachment =
|
|
277
|
+
typeof fileLike === 'string' || fileLike instanceof Buffer || typeof fileLike.pipe === 'function';
|
|
278
|
+
if (ownAttachment) {
|
|
279
|
+
attachment = fileLike;
|
|
280
|
+
name = findName(attachment);
|
|
281
|
+
} else {
|
|
282
|
+
attachment = fileLike.attachment;
|
|
283
|
+
name = fileLike.name ?? findName(attachment);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const { data, contentType } = await resolveFile(attachment);
|
|
287
|
+
return { data, name, contentType };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Creates a {@link MessagePayload} from user-level arguments.
|
|
292
|
+
*
|
|
293
|
+
* @param {MessageTarget} target Target to send to
|
|
294
|
+
* @param {string|MessagePayloadOption} options Options or content to use
|
|
295
|
+
* @param {MessagePayloadOption} [extra={}] Extra options to add onto specified options
|
|
296
|
+
* @returns {MessagePayload}
|
|
297
|
+
*/
|
|
298
|
+
static create(target, options, extra = {}) {
|
|
299
|
+
return new this(
|
|
300
|
+
target,
|
|
301
|
+
typeof options !== 'object' || options === null ? { content: options, ...extra } : { ...options, ...extra },
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* A target for a message.
|
|
310
|
+
*
|
|
311
|
+
* @typedef {TextBasedChannels|ChannelManager|Webhook|BaseInteraction|InteractionWebhook|
|
|
312
|
+
* Message|MessageManager} MessageTarget
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* A possible payload option.
|
|
317
|
+
*
|
|
318
|
+
* @typedef {MessageCreateOptions|MessageEditOptions|WebhookMessageCreateOptions|WebhookMessageEditOptions|
|
|
319
|
+
* InteractionReplyOptions|InteractionUpdateOptions} MessagePayloadOption
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @external RawFile
|
|
324
|
+
* @see {@link https://discord.js.org/docs/packages/rest/stable/RawFile:Interface}
|
|
325
|
+
*/
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Routes } from 'discord-api-types/v10';
|
|
2
|
+
import { ReactionUserManager } from '../managers/ReactionUserManager.js';
|
|
3
|
+
import { flatten, resolveGuildEmoji } from '../util/Util.js';
|
|
4
|
+
import { ApplicationEmoji } from './ApplicationEmoji.js';
|
|
5
|
+
import { GuildEmoji } from './GuildEmoji.js';
|
|
6
|
+
import { ReactionEmoji } from './ReactionEmoji.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a reaction to a message.
|
|
10
|
+
*/
|
|
11
|
+
export class MessageReaction {
|
|
12
|
+
public client: any;
|
|
13
|
+
public message: any;
|
|
14
|
+
public me: any;
|
|
15
|
+
public meBurst: any;
|
|
16
|
+
public users: any;
|
|
17
|
+
public _emoji: any;
|
|
18
|
+
public burstColors: any;
|
|
19
|
+
public countDetails: any;
|
|
20
|
+
public count: any;
|
|
21
|
+
constructor(client, data, message) {
|
|
22
|
+
/**
|
|
23
|
+
* The client that instantiated this message reaction
|
|
24
|
+
*
|
|
25
|
+
* @name MessageReaction#client
|
|
26
|
+
* @type {Client}
|
|
27
|
+
* @readonly
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The message that this reaction refers to
|
|
33
|
+
*
|
|
34
|
+
* @type {Message}
|
|
35
|
+
*/
|
|
36
|
+
this.message = message;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether the client has given this reaction
|
|
40
|
+
*
|
|
41
|
+
* @type {boolean}
|
|
42
|
+
*/
|
|
43
|
+
this.me = data.me;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether the client has super-reacted using this emoji
|
|
47
|
+
*
|
|
48
|
+
* @type {boolean}
|
|
49
|
+
*/
|
|
50
|
+
this.meBurst = Boolean(data.me_burst);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A manager of the users that have given this reaction
|
|
54
|
+
*
|
|
55
|
+
* @type {ReactionUserManager}
|
|
56
|
+
*/
|
|
57
|
+
this.users = new ReactionUserManager(this, this.me ? [client.user] : []);
|
|
58
|
+
|
|
59
|
+
this._emoji = new ReactionEmoji(this, data.emoji);
|
|
60
|
+
|
|
61
|
+
this.burstColors = null;
|
|
62
|
+
|
|
63
|
+
this._patch(data);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_patch(data) {
|
|
67
|
+
if (data.burst_colors) {
|
|
68
|
+
/**
|
|
69
|
+
* Hexadecimal colors used for this super reaction
|
|
70
|
+
*
|
|
71
|
+
* @type {?string[]}
|
|
72
|
+
*/
|
|
73
|
+
this.burstColors = data.burst_colors;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if ('count' in data) {
|
|
77
|
+
/**
|
|
78
|
+
* The number of people that have given the same reaction
|
|
79
|
+
*
|
|
80
|
+
* @type {?number}
|
|
81
|
+
*/
|
|
82
|
+
this.count ??= data.count;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if ('count_details' in data) {
|
|
86
|
+
/**
|
|
87
|
+
* The reaction count details object contains information about super and normal reaction counts.
|
|
88
|
+
*
|
|
89
|
+
* @typedef {Object} ReactionCountDetailsData
|
|
90
|
+
* @property {number} burst Count of super reactions
|
|
91
|
+
* @property {number} normal Count of normal reactions
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The reaction count details object contains information about super and normal reaction counts.
|
|
96
|
+
*
|
|
97
|
+
* @type {ReactionCountDetailsData}
|
|
98
|
+
*/
|
|
99
|
+
this.countDetails = {
|
|
100
|
+
burst: data.count_details.burst,
|
|
101
|
+
normal: data.count_details.normal,
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
this.countDetails ??= { burst: 0, normal: 0 };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Makes the client user react with this reaction
|
|
110
|
+
*
|
|
111
|
+
* @returns {Promise<MessageReaction>}
|
|
112
|
+
*/
|
|
113
|
+
async react() {
|
|
114
|
+
return this.message.react(this.emoji);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Removes all users from this reaction.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Promise<MessageReaction>}
|
|
121
|
+
*/
|
|
122
|
+
async remove() {
|
|
123
|
+
await this.client.rest.delete(
|
|
124
|
+
Routes.channelMessageReaction(this.message.channelId, this.message.id, this._emoji.identifier),
|
|
125
|
+
);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis,
|
|
131
|
+
* {@link ApplicationEmoji} for application emojis, or a {@link ReactionEmoji} object
|
|
132
|
+
* which has fewer properties. Whatever the prototype of the emoji, it will still have
|
|
133
|
+
* `name`, `id`, `identifier` and `toString()`
|
|
134
|
+
*
|
|
135
|
+
* @type {GuildEmoji|ReactionEmoji|ApplicationEmoji}
|
|
136
|
+
* @readonly
|
|
137
|
+
*/
|
|
138
|
+
get emoji() {
|
|
139
|
+
if (this._emoji instanceof GuildEmoji) return this._emoji;
|
|
140
|
+
if (this._emoji instanceof ApplicationEmoji) return this._emoji;
|
|
141
|
+
// Check to see if the emoji has become known to the client
|
|
142
|
+
if (this._emoji.id) {
|
|
143
|
+
const applicationEmojis = this.message.client.application.emojis.cache;
|
|
144
|
+
if (applicationEmojis.has(this._emoji.id)) {
|
|
145
|
+
const innerEmoji = applicationEmojis.get(this._emoji.id);
|
|
146
|
+
this._emoji = innerEmoji;
|
|
147
|
+
return innerEmoji;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const emoji = resolveGuildEmoji(this.client, this._emoji.id);
|
|
152
|
+
return emoji ?? this._emoji;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Whether or not this reaction is a partial
|
|
157
|
+
*
|
|
158
|
+
* @type {boolean}
|
|
159
|
+
* @readonly
|
|
160
|
+
*/
|
|
161
|
+
get partial() {
|
|
162
|
+
return this.count === null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Fetch this reaction.
|
|
167
|
+
*
|
|
168
|
+
* @returns {Promise<MessageReaction>}
|
|
169
|
+
*/
|
|
170
|
+
async fetch() {
|
|
171
|
+
const message = await this.message.fetch();
|
|
172
|
+
const existing = message.reactions.cache.get(this.emoji.id ?? this.emoji.name);
|
|
173
|
+
// The reaction won't get set when it has been completely removed
|
|
174
|
+
this._patch(existing ?? { count: 0 });
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
toJSON() {
|
|
179
|
+
return flatten(this, { emoji: 'emojiId', message: 'messageId' });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
valueOf() {
|
|
183
|
+
return this._emoji.id ?? this._emoji.name;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_add(user, burst) {
|
|
187
|
+
if (this.partial) return;
|
|
188
|
+
this.users.cache.set(user.id, user);
|
|
189
|
+
if (!this.me || user.id !== this.message.client.user.id || this.count === 0) {
|
|
190
|
+
this.count++;
|
|
191
|
+
if (burst) this.countDetails.burst++;
|
|
192
|
+
else this.countDetails.normal++;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (user.id === this.message.client.user.id) {
|
|
196
|
+
if (burst) this.meBurst = true;
|
|
197
|
+
else this.me = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_remove(user, burst) {
|
|
202
|
+
if (this.partial) return;
|
|
203
|
+
this.users.cache.delete(user.id);
|
|
204
|
+
if (!this.me || user.id !== this.message.client.user.id) {
|
|
205
|
+
this.count--;
|
|
206
|
+
if (burst) this.countDetails.burst--;
|
|
207
|
+
else this.countDetails.normal--;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (user.id === this.message.client.user.id) {
|
|
211
|
+
if (burst) this.meBurst = false;
|
|
212
|
+
else this.me = false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (this.count <= 0 && this.users.cache.size === 0) {
|
|
216
|
+
this.message.reactions.cache.delete(this.emoji.id ?? this.emoji.name);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|