@velliajs/discord 1.0.0
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 +133 -0
- package/package.json +82 -0
- package/src/client/BaseClient.js +83 -0
- package/src/client/Client.js +591 -0
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +119 -0
- package/src/client/actions/ActionsManager.js +79 -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 +23 -0
- package/src/client/actions/ChannelUpdate.js +33 -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 +44 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +19 -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 +31 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +29 -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 +19 -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 +101 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +37 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +47 -0
- package/src/client/actions/MessageReactionAdd.js +55 -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 +42 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +31 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +26 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +47 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +36 -0
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +44 -0
- package/src/client/websocket/WebSocketManager.js +393 -0
- package/src/client/websocket/WebSocketShard.js +231 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -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/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_UPDATE.js +16 -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 +26 -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_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_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -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_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 +27 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -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_UPDATE.js +5 -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 +64 -0
- package/src/errors/DJSError.js +48 -0
- package/src/errors/ErrorCodes.js +319 -0
- package/src/errors/Messages.js +170 -0
- package/src/errors/index.js +5 -0
- package/src/index.js +213 -0
- package/src/managers/ApplicationCommandManager.js +263 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +434 -0
- package/src/managers/AutoModerationRuleManager.js +288 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/CachedManager.js +57 -0
- package/src/managers/CategoryChannelChildManager.js +77 -0
- package/src/managers/ChannelManager.js +128 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +494 -0
- package/src/managers/GuildEmojiManager.js +174 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +83 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +283 -0
- package/src/managers/GuildMemberManager.js +540 -0
- package/src/managers/GuildMemberRoleManager.js +204 -0
- package/src/managers/GuildScheduledEventManager.js +297 -0
- package/src/managers/GuildStickerManager.js +182 -0
- package/src/managers/GuildTextThreadManager.js +91 -0
- package/src/managers/MessageManager.js +259 -0
- package/src/managers/PermissionOverwriteManager.js +168 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +68 -0
- package/src/managers/ReactionUserManager.js +77 -0
- package/src/managers/RoleManager.js +360 -0
- package/src/managers/StageInstanceManager.js +154 -0
- package/src/managers/ThreadManager.js +204 -0
- package/src/managers/ThreadMemberManager.js +182 -0
- package/src/managers/UserManager.js +139 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/sharding/Shard.js +457 -0
- package/src/sharding/ShardClientUtil.js +285 -0
- package/src/sharding/ShardingManager.js +326 -0
- package/src/structures/ActionRow.js +46 -0
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +97 -0
- package/src/structures/ApplicationCommand.js +606 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +46 -0
- package/src/structures/Attachment.js +140 -0
- package/src/structures/AttachmentBuilder.js +116 -0
- package/src/structures/AutoModerationActionExecution.js +116 -0
- package/src/structures/AutoModerationRule.js +284 -0
- package/src/structures/AutocompleteInteraction.js +97 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseChannel.js +160 -0
- package/src/structures/BaseGuild.js +119 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +186 -0
- package/src/structures/BaseGuildVoiceChannel.js +234 -0
- package/src/structures/BaseInteraction.js +344 -0
- package/src/structures/BaseSelectMenuComponent.js +56 -0
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +65 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CategoryChannel.js +45 -0
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +20 -0
- package/src/structures/ChannelSelectMenuInteraction.js +33 -0
- package/src/structures/ChatInputCommandInteraction.js +41 -0
- package/src/structures/ClientApplication.js +193 -0
- package/src/structures/ClientPresence.js +82 -0
- package/src/structures/ClientUser.js +185 -0
- package/src/structures/CommandInteraction.js +224 -0
- package/src/structures/CommandInteractionOptionResolver.js +308 -0
- package/src/structures/Component.js +47 -0
- package/src/structures/ContextMenuCommandInteraction.js +64 -0
- package/src/structures/DMChannel.js +129 -0
- package/src/structures/DirectoryChannel.js +36 -0
- package/src/structures/Embed.js +220 -0
- package/src/structures/EmbedBuilder.js +41 -0
- package/src/structures/Emoji.js +108 -0
- package/src/structures/ForumChannel.js +264 -0
- package/src/structures/Guild.js +1361 -0
- package/src/structures/GuildAuditLogs.js +91 -0
- package/src/structures/GuildAuditLogsEntry.js +527 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildChannel.js +457 -0
- package/src/structures/GuildEmoji.js +148 -0
- package/src/structures/GuildMember.js +518 -0
- package/src/structures/GuildPreview.js +193 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +439 -0
- package/src/structures/GuildTemplate.js +241 -0
- package/src/structures/Integration.js +220 -0
- package/src/structures/IntegrationApplication.js +85 -0
- package/src/structures/InteractionCollector.js +263 -0
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +59 -0
- package/src/structures/Invite.js +322 -0
- package/src/structures/InviteGuild.js +22 -0
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +11 -0
- package/src/structures/MentionableSelectMenuInteraction.js +71 -0
- package/src/structures/Message.js +997 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +107 -0
- package/src/structures/MessageContextMenuCommandInteraction.js +20 -0
- package/src/structures/MessageMentions.js +297 -0
- package/src/structures/MessagePayload.js +299 -0
- package/src/structures/MessageReaction.js +142 -0
- package/src/structures/ModalBuilder.js +34 -0
- package/src/structures/ModalSubmitFields.js +55 -0
- package/src/structures/ModalSubmitInteraction.js +121 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +60 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +372 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +458 -0
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +11 -0
- package/src/structures/RoleSelectMenuInteraction.js +33 -0
- package/src/structures/SelectMenuBuilder.js +26 -0
- package/src/structures/SelectMenuComponent.js +26 -0
- package/src/structures/SelectMenuInteraction.js +26 -0
- package/src/structures/SelectMenuOptionBuilder.js +26 -0
- package/src/structures/StageChannel.js +112 -0
- package/src/structures/StageInstance.js +167 -0
- package/src/structures/Sticker.js +272 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +20 -0
- package/src/structures/StringSelectMenuInteraction.js +21 -0
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Team.js +117 -0
- package/src/structures/TeamMember.js +70 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +29 -0
- package/src/structures/ThreadChannel.js +606 -0
- package/src/structures/ThreadMember.js +113 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +331 -0
- package/src/structures/UserContextMenuCommandInteraction.js +29 -0
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +11 -0
- package/src/structures/UserSelectMenuInteraction.js +51 -0
- package/src/structures/VoiceChannel.js +96 -0
- package/src/structures/VoiceRegion.js +46 -0
- package/src/structures/VoiceState.js +303 -0
- package/src/structures/Webhook.js +481 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +49 -0
- package/src/structures/Widget.js +88 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +108 -0
- package/src/structures/interfaces/Collector.js +335 -0
- package/src/structures/interfaces/InteractionResponses.js +320 -0
- package/src/structures/interfaces/TextBasedChannel.js +413 -0
- package/src/util/APITypes.js +456 -0
- package/src/util/ActivityFlagsBitField.js +26 -0
- package/src/util/ApplicationFlagsBitField.js +26 -0
- package/src/util/BitField.js +176 -0
- package/src/util/ChannelFlagsBitField.js +41 -0
- package/src/util/Channels.js +150 -0
- package/src/util/Colors.js +73 -0
- package/src/util/Components.js +152 -0
- package/src/util/Constants.js +230 -0
- package/src/util/DataResolver.js +140 -0
- package/src/util/Enums.js +13 -0
- package/src/util/Events.js +160 -0
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +41 -0
- package/src/util/IntentsBitField.js +34 -0
- package/src/util/LimitedCollection.js +68 -0
- package/src/util/MessageFlagsBitField.js +32 -0
- package/src/util/Options.js +216 -0
- package/src/util/Partials.js +44 -0
- package/src/util/PermissionsBitField.js +104 -0
- package/src/util/ShardEvents.js +27 -0
- package/src/util/Status.js +33 -0
- package/src/util/Sweepers.js +467 -0
- package/src/util/SystemChannelFlagsBitField.js +43 -0
- package/src/util/ThreadMemberFlagsBitField.js +31 -0
- package/src/util/Transformers.js +36 -0
- package/src/util/UserFlagsBitField.js +32 -0
- package/src/util/Util.js +394 -0
- package/src/util/WebSocketShardEvents.js +25 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { ChannelType, Routes } = require('discord-api-types/v10');
|
|
4
|
+
const ThreadManager = require('./ThreadManager');
|
|
5
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
|
|
9
|
+
* @extends {ThreadManager}
|
|
10
|
+
*/
|
|
11
|
+
class GuildTextThreadManager extends ThreadManager {
|
|
12
|
+
/**
|
|
13
|
+
* The channel this Manager belongs to
|
|
14
|
+
* @name GuildTextThreadManager#channel
|
|
15
|
+
* @type {TextChannel|NewsChannel}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for creating a thread. <warn>Only one of `startMessage` or `type` can be defined.</warn>
|
|
20
|
+
* @typedef {StartThreadOptions} ThreadCreateOptions
|
|
21
|
+
* @property {MessageResolvable} [startMessage] The message to start a thread from.
|
|
22
|
+
* <warn>If this is defined, then the `type` of thread gets inferred automatically and cannot be changed.</warn>
|
|
23
|
+
* @property {ThreadChannelTypes} [type] The type of thread to create.
|
|
24
|
+
* Defaults to {@link ChannelType.PublicThread} if created in a {@link TextChannel}
|
|
25
|
+
* <warn>When creating threads in a {@link NewsChannel}, this is ignored and is always
|
|
26
|
+
* {@link ChannelType.AnnouncementThread}</warn>
|
|
27
|
+
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to the thread
|
|
28
|
+
* <info>Can only be set when type will be {@link ChannelType.PrivateThread}</info>
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new thread in the channel.
|
|
33
|
+
* @param {ThreadCreateOptions} [options] Options to create a new thread
|
|
34
|
+
* @returns {Promise<ThreadChannel>}
|
|
35
|
+
* @example
|
|
36
|
+
* // Create a new public thread
|
|
37
|
+
* channel.threads
|
|
38
|
+
* .create({
|
|
39
|
+
* name: 'food-talk',
|
|
40
|
+
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
|
41
|
+
* reason: 'Needed a separate thread for food',
|
|
42
|
+
* })
|
|
43
|
+
* .then(threadChannel => console.log(threadChannel))
|
|
44
|
+
* .catch(console.error);
|
|
45
|
+
* @example
|
|
46
|
+
* // Create a new private thread
|
|
47
|
+
* channel.threads
|
|
48
|
+
* .create({
|
|
49
|
+
* name: 'mod-talk',
|
|
50
|
+
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
|
51
|
+
* type: ChannelType.PrivateThread,
|
|
52
|
+
* reason: 'Needed a separate thread for moderation',
|
|
53
|
+
* })
|
|
54
|
+
* .then(threadChannel => console.log(threadChannel))
|
|
55
|
+
* .catch(console.error);
|
|
56
|
+
*/
|
|
57
|
+
async create({
|
|
58
|
+
name,
|
|
59
|
+
autoArchiveDuration = this.channel.defaultAutoArchiveDuration,
|
|
60
|
+
startMessage,
|
|
61
|
+
type,
|
|
62
|
+
invitable,
|
|
63
|
+
reason,
|
|
64
|
+
rateLimitPerUser,
|
|
65
|
+
} = {}) {
|
|
66
|
+
let resolvedType =
|
|
67
|
+
this.channel.type === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread;
|
|
68
|
+
let startMessageId;
|
|
69
|
+
if (startMessage) {
|
|
70
|
+
startMessageId = this.channel.messages.resolveId(startMessage);
|
|
71
|
+
if (!startMessageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'startMessage', 'MessageResolvable');
|
|
72
|
+
} else if (this.channel.type !== ChannelType.GuildAnnouncement) {
|
|
73
|
+
resolvedType = type ?? resolvedType;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const data = await this.client.rest.post(Routes.threads(this.channel.id, startMessageId), {
|
|
77
|
+
body: {
|
|
78
|
+
name,
|
|
79
|
+
auto_archive_duration: autoArchiveDuration,
|
|
80
|
+
type: resolvedType,
|
|
81
|
+
invitable: resolvedType === ChannelType.PrivateThread ? invitable : undefined,
|
|
82
|
+
rate_limit_per_user: rateLimitPerUser,
|
|
83
|
+
},
|
|
84
|
+
reason,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return this.client.actions.ThreadCreate.handle(data).thread;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = GuildTextThreadManager;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
5
|
+
const { Routes } = require('discord-api-types/v10');
|
|
6
|
+
const CachedManager = require('./CachedManager');
|
|
7
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
|
8
|
+
const { Message } = require('../structures/Message');
|
|
9
|
+
const MessagePayload = require('../structures/MessagePayload');
|
|
10
|
+
const { resolvePartialEmoji } = require('../util/Util');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Manages API methods for Messages and holds their cache.
|
|
14
|
+
* @extends {CachedManager}
|
|
15
|
+
*/
|
|
16
|
+
class MessageManager extends CachedManager {
|
|
17
|
+
constructor(channel, iterable) {
|
|
18
|
+
super(channel.client, Message, iterable);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The channel that the messages belong to
|
|
22
|
+
* @type {TextBasedChannels}
|
|
23
|
+
*/
|
|
24
|
+
this.channel = channel;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The cache of Messages
|
|
29
|
+
* @type {Collection<Snowflake, Message>}
|
|
30
|
+
* @name MessageManager#cache
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
_add(data, cache) {
|
|
34
|
+
return super._add(data, cache);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Data that can be resolved to a Message object. This can be:
|
|
39
|
+
* * A Message
|
|
40
|
+
* * A Snowflake
|
|
41
|
+
* @typedef {Message|Snowflake} MessageResolvable
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Options used to fetch a message.
|
|
46
|
+
* @typedef {BaseFetchOptions} FetchMessageOptions
|
|
47
|
+
* @property {MessageResolvable} message The message to fetch
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Options used to fetch multiple messages.
|
|
52
|
+
* <info>The `before`, `after`, and `around` parameters are mutually exclusive.</info>
|
|
53
|
+
* @typedef {Object} FetchMessagesOptions
|
|
54
|
+
* @property {number} [limit] The maximum number of messages to return
|
|
55
|
+
* @property {Snowflake} [before] Consider only messages before this id
|
|
56
|
+
* @property {Snowflake} [after] Consider only messages after this id
|
|
57
|
+
* @property {Snowflake} [around] Consider only messages around this id
|
|
58
|
+
* @property {boolean} [cache] Whether to cache the fetched messages
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Fetches message(s) from a channel.
|
|
63
|
+
* <info>The returned Collection does not contain reaction users of the messages if they were not cached.
|
|
64
|
+
* Those need to be fetched separately in such a case.</info>
|
|
65
|
+
* @param {MessageResolvable|FetchMessageOptions|FetchMessagesOptions} [options] Options for fetching message(s)
|
|
66
|
+
* @returns {Promise<Message|Collection<Snowflake, Message>>}
|
|
67
|
+
* @example
|
|
68
|
+
* // Fetch a message
|
|
69
|
+
* channel.messages.fetch('99539446449315840')
|
|
70
|
+
* .then(message => console.log(message.content))
|
|
71
|
+
* .catch(console.error);
|
|
72
|
+
* @example
|
|
73
|
+
* // Fetch a maximum of 10 messages without caching
|
|
74
|
+
* channel.messages.fetch({ limit: 10, cache: false })
|
|
75
|
+
* .then(messages => console.log(`Received ${messages.size} messages`))
|
|
76
|
+
* .catch(console.error);
|
|
77
|
+
* @example
|
|
78
|
+
* // Fetch a maximum of 10 messages without caching around a message id
|
|
79
|
+
* channel.messages.fetch({ limit: 10, cache: false, around: '99539446449315840' })
|
|
80
|
+
* .then(messages => console.log(`Received ${messages.size} messages`))
|
|
81
|
+
* .catch(console.error);
|
|
82
|
+
* @example
|
|
83
|
+
* // Fetch messages and filter by a user id
|
|
84
|
+
* channel.messages.fetch()
|
|
85
|
+
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
|
|
86
|
+
* .catch(console.error);
|
|
87
|
+
*/
|
|
88
|
+
fetch(options) {
|
|
89
|
+
if (!options) return this._fetchMany();
|
|
90
|
+
const { message, cache, force } = options;
|
|
91
|
+
const resolvedMessage = this.resolveId(message ?? options);
|
|
92
|
+
if (resolvedMessage) return this._fetchSingle({ message: resolvedMessage, cache, force });
|
|
93
|
+
return this._fetchMany(options);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async _fetchSingle({ message, cache, force = false }) {
|
|
97
|
+
if (!force) {
|
|
98
|
+
const existing = this.cache.get(message);
|
|
99
|
+
if (existing && !existing.partial) return existing;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const data = await this.client.rest.get(Routes.channelMessage(this.channel.id, message));
|
|
103
|
+
return this._add(data, cache);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async _fetchMany(options = {}) {
|
|
107
|
+
const data = await this.client.rest.get(Routes.channelMessages(this.channel.id), {
|
|
108
|
+
query: makeURLSearchParams(options),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return data.reduce((_data, message) => _data.set(message.id, this._add(message, options.cache)), new Collection());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Fetches the pinned messages of this channel and returns a collection of them.
|
|
116
|
+
* <info>The returned Collection does not contain any reaction data of the messages.
|
|
117
|
+
* Those need to be fetched separately.</info>
|
|
118
|
+
* @param {boolean} [cache=true] Whether to cache the message(s)
|
|
119
|
+
* @returns {Promise<Collection<Snowflake, Message>>}
|
|
120
|
+
* @example
|
|
121
|
+
* // Get pinned messages
|
|
122
|
+
* channel.messages.fetchPinned()
|
|
123
|
+
* .then(messages => console.log(`Received ${messages.size} messages`))
|
|
124
|
+
* .catch(console.error);
|
|
125
|
+
*/
|
|
126
|
+
async fetchPinned(cache = true) {
|
|
127
|
+
const data = await this.client.rest.get(Routes.channelPins(this.channel.id));
|
|
128
|
+
const messages = new Collection();
|
|
129
|
+
for (const message of data) messages.set(message.id, this._add(message, cache));
|
|
130
|
+
return messages;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Resolves a {@link MessageResolvable} to a {@link Message} object.
|
|
135
|
+
* @method resolve
|
|
136
|
+
* @memberof MessageManager
|
|
137
|
+
* @instance
|
|
138
|
+
* @param {MessageResolvable} message The message resolvable to resolve
|
|
139
|
+
* @returns {?Message}
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Resolves a {@link MessageResolvable} to a {@link Message} id.
|
|
144
|
+
* @method resolveId
|
|
145
|
+
* @memberof MessageManager
|
|
146
|
+
* @instance
|
|
147
|
+
* @param {MessageResolvable} message The message resolvable to resolve
|
|
148
|
+
* @returns {?Snowflake}
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Options that can be passed to edit a message.
|
|
153
|
+
* @typedef {BaseMessageOptions} MessageEditOptions
|
|
154
|
+
* @property {AttachmentPayload[]} [attachments] An array of attachments to keep,
|
|
155
|
+
* all attachments will be kept if omitted
|
|
156
|
+
* @property {MessageFlags} [flags] Which flags to set for the message
|
|
157
|
+
* <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be modified.</info>
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Edits a message, even if it's not cached.
|
|
162
|
+
* @param {MessageResolvable} message The message to edit
|
|
163
|
+
* @param {string|MessageEditOptions|MessagePayload} options The options to edit the message
|
|
164
|
+
* @returns {Promise<Message>}
|
|
165
|
+
*/
|
|
166
|
+
async edit(message, options) {
|
|
167
|
+
const messageId = this.resolveId(message);
|
|
168
|
+
if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
169
|
+
|
|
170
|
+
const { body, files } = await (options instanceof MessagePayload
|
|
171
|
+
? options
|
|
172
|
+
: MessagePayload.create(message instanceof Message ? message : this, options)
|
|
173
|
+
)
|
|
174
|
+
.resolveBody()
|
|
175
|
+
.resolveFiles();
|
|
176
|
+
const d = await this.client.rest.patch(Routes.channelMessage(this.channel.id, messageId), { body, files });
|
|
177
|
+
|
|
178
|
+
const existing = this.cache.get(messageId);
|
|
179
|
+
if (existing) {
|
|
180
|
+
const clone = existing._clone();
|
|
181
|
+
clone._patch(d);
|
|
182
|
+
return clone;
|
|
183
|
+
}
|
|
184
|
+
return this._add(d);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Publishes a message in an announcement channel to all channels following it, even if it's not cached.
|
|
189
|
+
* @param {MessageResolvable} message The message to publish
|
|
190
|
+
* @returns {Promise<Message>}
|
|
191
|
+
*/
|
|
192
|
+
async crosspost(message) {
|
|
193
|
+
message = this.resolveId(message);
|
|
194
|
+
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
195
|
+
|
|
196
|
+
const data = await this.client.rest.post(Routes.channelMessageCrosspost(this.channel.id, message));
|
|
197
|
+
return this.cache.get(data.id) ?? this._add(data);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Pins a message to the channel's pinned messages, even if it's not cached.
|
|
202
|
+
* @param {MessageResolvable} message The message to pin
|
|
203
|
+
* @param {string} [reason] Reason for pinning
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*/
|
|
206
|
+
async pin(message, reason) {
|
|
207
|
+
message = this.resolveId(message);
|
|
208
|
+
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
209
|
+
|
|
210
|
+
await this.client.rest.put(Routes.channelPin(this.channel.id, message), { reason });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Unpins a message from the channel's pinned messages, even if it's not cached.
|
|
215
|
+
* @param {MessageResolvable} message The message to unpin
|
|
216
|
+
* @param {string} [reason] Reason for unpinning
|
|
217
|
+
* @returns {Promise<void>}
|
|
218
|
+
*/
|
|
219
|
+
async unpin(message, reason) {
|
|
220
|
+
message = this.resolveId(message);
|
|
221
|
+
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
222
|
+
|
|
223
|
+
await this.client.rest.delete(Routes.channelPin(this.channel.id, message), { reason });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Adds a reaction to a message, even if it's not cached.
|
|
228
|
+
* @param {MessageResolvable} message The message to react to
|
|
229
|
+
* @param {EmojiIdentifierResolvable} emoji The emoji to react with
|
|
230
|
+
* @returns {Promise<void>}
|
|
231
|
+
*/
|
|
232
|
+
async react(message, emoji) {
|
|
233
|
+
message = this.resolveId(message);
|
|
234
|
+
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
235
|
+
|
|
236
|
+
emoji = resolvePartialEmoji(emoji);
|
|
237
|
+
if (!emoji) throw new DiscordjsTypeError(ErrorCodes.EmojiType, 'emoji', 'EmojiIdentifierResolvable');
|
|
238
|
+
|
|
239
|
+
const emojiId = emoji.id
|
|
240
|
+
? `${emoji.animated ? 'a:' : ''}${emoji.name}:${emoji.id}`
|
|
241
|
+
: encodeURIComponent(emoji.name);
|
|
242
|
+
|
|
243
|
+
await this.client.rest.put(Routes.channelMessageOwnReaction(this.channel.id, message, emojiId));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Deletes a message, even if it's not cached.
|
|
248
|
+
* @param {MessageResolvable} message The message to delete
|
|
249
|
+
* @returns {Promise<void>}
|
|
250
|
+
*/
|
|
251
|
+
async delete(message) {
|
|
252
|
+
message = this.resolveId(message);
|
|
253
|
+
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');
|
|
254
|
+
|
|
255
|
+
await this.client.rest.delete(Routes.channelMessage(this.channel.id, message));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
module.exports = MessageManager;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const { Collection } = require('@discordjs/collection');
|
|
5
|
+
const { OverwriteType, Routes } = require('discord-api-types/v10');
|
|
6
|
+
const CachedManager = require('./CachedManager');
|
|
7
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
|
8
|
+
const PermissionOverwrites = require('../structures/PermissionOverwrites');
|
|
9
|
+
const { Role } = require('../structures/Role');
|
|
10
|
+
|
|
11
|
+
let cacheWarningEmitted = false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Manages API methods for guild channel permission overwrites and stores their cache.
|
|
15
|
+
* @extends {CachedManager}
|
|
16
|
+
*/
|
|
17
|
+
class PermissionOverwriteManager extends CachedManager {
|
|
18
|
+
constructor(channel, iterable) {
|
|
19
|
+
super(channel.client, PermissionOverwrites);
|
|
20
|
+
if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') {
|
|
21
|
+
cacheWarningEmitted = true;
|
|
22
|
+
process.emitWarning(
|
|
23
|
+
`Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
|
|
24
|
+
'UnsupportedCacheOverwriteWarning',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The channel of the permission overwrite this manager belongs to
|
|
30
|
+
* @type {GuildChannel}
|
|
31
|
+
*/
|
|
32
|
+
this.channel = channel;
|
|
33
|
+
|
|
34
|
+
if (iterable) {
|
|
35
|
+
for (const item of iterable) {
|
|
36
|
+
this._add(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The cache of this Manager
|
|
43
|
+
* @type {Collection<Snowflake, PermissionOverwrites>}
|
|
44
|
+
* @name PermissionOverwriteManager#cache
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
_add(data, cache) {
|
|
48
|
+
return super._add(data, cache, { extras: [this.channel] });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Replaces the permission overwrites in this channel.
|
|
53
|
+
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} overwrites
|
|
54
|
+
* Permission overwrites the channel gets updated with
|
|
55
|
+
* @param {string} [reason] Reason for updating the channel overwrites
|
|
56
|
+
* @returns {Promise<GuildChannel>}
|
|
57
|
+
* @example
|
|
58
|
+
* message.channel.permissionOverwrites.set([
|
|
59
|
+
* {
|
|
60
|
+
* id: message.author.id,
|
|
61
|
+
* deny: [PermissionsFlagsBit.ViewChannel],
|
|
62
|
+
* },
|
|
63
|
+
* ], 'Needed to change permissions');
|
|
64
|
+
*/
|
|
65
|
+
set(overwrites, reason) {
|
|
66
|
+
if (!Array.isArray(overwrites) && !(overwrites instanceof Collection)) {
|
|
67
|
+
return Promise.reject(
|
|
68
|
+
new DiscordjsTypeError(
|
|
69
|
+
ErrorCodes.InvalidType,
|
|
70
|
+
'overwrites',
|
|
71
|
+
'Array or Collection of Permission Overwrites',
|
|
72
|
+
true,
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return this.channel.edit({ permissionOverwrites: overwrites, reason });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Extra information about the overwrite.
|
|
81
|
+
* @typedef {Object} GuildChannelOverwriteOptions
|
|
82
|
+
* @property {string} [reason] The reason for creating/editing this overwrite
|
|
83
|
+
* @property {OverwriteType} [type] The type of overwrite. Use this to bypass automatic resolution of `type`
|
|
84
|
+
* that results in an error for an uncached structure
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates or edits permission overwrites for a user or role in this channel.
|
|
89
|
+
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
90
|
+
* @param {PermissionOverwriteOptions} options The options for the update
|
|
91
|
+
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
92
|
+
* @param {PermissionOverwrites} [existing] The existing overwrites to merge with this update
|
|
93
|
+
* @returns {Promise<GuildChannel>}
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
async upsert(userOrRole, options, overwriteOptions = {}, existing) {
|
|
97
|
+
let userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
|
|
98
|
+
let { type, reason } = overwriteOptions;
|
|
99
|
+
if (typeof type !== 'number') {
|
|
100
|
+
userOrRole = this.channel.guild.roles.resolve(userOrRole) ?? this.client.users.resolve(userOrRole);
|
|
101
|
+
if (!userOrRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
|
|
102
|
+
type = userOrRole instanceof Role ? OverwriteType.Role : OverwriteType.Member;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { allow, deny } = PermissionOverwrites.resolveOverwriteOptions(options, existing);
|
|
106
|
+
|
|
107
|
+
await this.client.rest.put(Routes.channelPermission(this.channel.id, userOrRoleId), {
|
|
108
|
+
body: { id: userOrRoleId, type, allow, deny },
|
|
109
|
+
reason,
|
|
110
|
+
});
|
|
111
|
+
return this.channel;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates permission overwrites for a user or role in this channel, or replaces them if already present.
|
|
116
|
+
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
117
|
+
* @param {PermissionOverwriteOptions} options The options for the update
|
|
118
|
+
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
119
|
+
* @returns {Promise<GuildChannel>}
|
|
120
|
+
* @example
|
|
121
|
+
* // Create or Replace permission overwrites for a message author
|
|
122
|
+
* message.channel.permissionOverwrites.create(message.author, {
|
|
123
|
+
* SendMessages: false
|
|
124
|
+
* })
|
|
125
|
+
* .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
|
|
126
|
+
* .catch(console.error);
|
|
127
|
+
*/
|
|
128
|
+
create(userOrRole, options, overwriteOptions) {
|
|
129
|
+
return this.upsert(userOrRole, options, overwriteOptions);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Edits permission overwrites for a user or role in this channel, or creates an entry if not already present.
|
|
134
|
+
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
|
135
|
+
* @param {PermissionOverwriteOptions} options The options for the update
|
|
136
|
+
* @param {GuildChannelOverwriteOptions} [overwriteOptions] The extra information for the update
|
|
137
|
+
* @returns {Promise<GuildChannel>}
|
|
138
|
+
* @example
|
|
139
|
+
* // Edit or Create permission overwrites for a message author
|
|
140
|
+
* message.channel.permissionOverwrites.edit(message.author, {
|
|
141
|
+
* SendMessages: false
|
|
142
|
+
* })
|
|
143
|
+
* .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
|
|
144
|
+
* .catch(console.error);
|
|
145
|
+
*/
|
|
146
|
+
edit(userOrRole, options, overwriteOptions) {
|
|
147
|
+
const existing = this.cache.get(
|
|
148
|
+
this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole),
|
|
149
|
+
);
|
|
150
|
+
return this.upsert(userOrRole, options, overwriteOptions, existing);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Deletes permission overwrites for a user or role in this channel.
|
|
155
|
+
* @param {UserResolvable|RoleResolvable} userOrRole The user or role to delete
|
|
156
|
+
* @param {string} [reason] The reason for deleting the overwrite
|
|
157
|
+
* @returns {Promise<GuildChannel>}
|
|
158
|
+
*/
|
|
159
|
+
async delete(userOrRole, reason) {
|
|
160
|
+
const userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
|
|
161
|
+
if (!userOrRoleId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
|
|
162
|
+
|
|
163
|
+
await this.client.rest.delete(Routes.channelPermission(this.channel.id, userOrRoleId), { reason });
|
|
164
|
+
return this.channel;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = PermissionOverwriteManager;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CachedManager = require('./CachedManager');
|
|
4
|
+
const { Presence } = require('../structures/Presence');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manages API methods for Presences and holds their cache.
|
|
8
|
+
* @extends {CachedManager}
|
|
9
|
+
*/
|
|
10
|
+
class PresenceManager extends CachedManager {
|
|
11
|
+
constructor(client, iterable) {
|
|
12
|
+
super(client, Presence, iterable);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The cache of Presences
|
|
17
|
+
* @type {Collection<Snowflake, Presence>}
|
|
18
|
+
* @name PresenceManager#cache
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
_add(data, cache) {
|
|
22
|
+
return super._add(data, cache, { id: data.user.id });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Data that can be resolved to a Presence object. This can be:
|
|
27
|
+
* * A Presence
|
|
28
|
+
* * A UserResolvable
|
|
29
|
+
* * A Snowflake
|
|
30
|
+
* @typedef {Presence|UserResolvable|Snowflake} PresenceResolvable
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolves a {@link PresenceResolvable} to a {@link Presence} object.
|
|
35
|
+
* @param {PresenceResolvable} presence The presence resolvable to resolve
|
|
36
|
+
* @returns {?Presence}
|
|
37
|
+
*/
|
|
38
|
+
resolve(presence) {
|
|
39
|
+
const presenceResolvable = super.resolve(presence);
|
|
40
|
+
if (presenceResolvable) return presenceResolvable;
|
|
41
|
+
const UserResolvable = this.client.users.resolveId(presence);
|
|
42
|
+
return super.resolve(UserResolvable);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a {@link PresenceResolvable} to a {@link Presence} id.
|
|
47
|
+
* @param {PresenceResolvable} presence The presence resolvable to resolve
|
|
48
|
+
* @returns {?Snowflake}
|
|
49
|
+
*/
|
|
50
|
+
resolveId(presence) {
|
|
51
|
+
const presenceResolvable = super.resolveId(presence);
|
|
52
|
+
if (presenceResolvable) return presenceResolvable;
|
|
53
|
+
const userResolvable = this.client.users.resolveId(presence);
|
|
54
|
+
return this.cache.has(userResolvable) ? userResolvable : null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = PresenceManager;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Routes } = require('discord-api-types/v10');
|
|
4
|
+
const CachedManager = require('./CachedManager');
|
|
5
|
+
const MessageReaction = require('../structures/MessageReaction');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Manages API methods for reactions and holds their cache.
|
|
9
|
+
* @extends {CachedManager}
|
|
10
|
+
*/
|
|
11
|
+
class ReactionManager extends CachedManager {
|
|
12
|
+
constructor(message, iterable) {
|
|
13
|
+
super(message.client, MessageReaction, iterable);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The message that this manager belongs to
|
|
17
|
+
* @type {Message}
|
|
18
|
+
*/
|
|
19
|
+
this.message = message;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_add(data, cache) {
|
|
23
|
+
return super._add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The reaction cache of this manager
|
|
28
|
+
* @type {Collection<string|Snowflake, MessageReaction>}
|
|
29
|
+
* @name ReactionManager#cache
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Data that can be resolved to a MessageReaction object. This can be:
|
|
34
|
+
* * A MessageReaction
|
|
35
|
+
* * A Snowflake
|
|
36
|
+
* * The Unicode representation of an emoji
|
|
37
|
+
* @typedef {MessageReaction|Snowflake} MessageReactionResolvable
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} object.
|
|
42
|
+
* @method resolve
|
|
43
|
+
* @memberof ReactionManager
|
|
44
|
+
* @instance
|
|
45
|
+
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
|
|
46
|
+
* @returns {?MessageReaction}
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} id.
|
|
51
|
+
* @method resolveId
|
|
52
|
+
* @memberof ReactionManager
|
|
53
|
+
* @instance
|
|
54
|
+
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve
|
|
55
|
+
* @returns {?Snowflake}
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Removes all reactions from a message.
|
|
60
|
+
* @returns {Promise<Message>}
|
|
61
|
+
*/
|
|
62
|
+
async removeAll() {
|
|
63
|
+
await this.client.rest.delete(Routes.channelMessageAllReactions(this.message.channelId, this.message.id));
|
|
64
|
+
return this.message;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = ReactionManager;
|