@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,307 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { Routes } from 'discord-api-types/v10';
|
|
3
|
+
import { AutoModerationRule } from '../structures/AutoModerationRule.js';
|
|
4
|
+
import { CachedManager } from './CachedManager.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manages API methods for auto moderation rules and stores their cache.
|
|
8
|
+
*
|
|
9
|
+
* @extends {CachedManager}
|
|
10
|
+
*/
|
|
11
|
+
export class AutoModerationRuleManager extends CachedManager {
|
|
12
|
+
public guild: any;
|
|
13
|
+
constructor(guild, iterable) {
|
|
14
|
+
super(guild.client, AutoModerationRule, iterable);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The guild this manager belongs to.
|
|
18
|
+
*
|
|
19
|
+
* @type {Guild}
|
|
20
|
+
*/
|
|
21
|
+
this.guild = guild;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The cache of this manager
|
|
26
|
+
*
|
|
27
|
+
* @type {Collection<Snowflake, AutoModerationRule>}
|
|
28
|
+
* @name AutoModerationRuleManager#cache
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolves an {@link AutoModerationRuleResolvable} to an {@link AutoModerationRule} object.
|
|
33
|
+
*
|
|
34
|
+
* @method resolve
|
|
35
|
+
* @memberof AutoModerationRuleManager
|
|
36
|
+
* @instance
|
|
37
|
+
* @param {AutoModerationRuleResolvable} autoModerationRule The AutoModerationRule resolvable to resolve
|
|
38
|
+
* @returns {?AutoModerationRule}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolves an {@link AutoModerationRuleResolvable} to a {@link AutoModerationRule} id.
|
|
43
|
+
*
|
|
44
|
+
* @method resolveId
|
|
45
|
+
* @memberof AutoModerationRuleManager
|
|
46
|
+
* @instance
|
|
47
|
+
* @param {AutoModerationRuleResolvable} autoModerationRule The AutoModerationRule resolvable to resolve
|
|
48
|
+
* @returns {?Snowflake}
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
_add(data, cache) {
|
|
52
|
+
return super._add(data, cache, { extras: [this.guild] });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Options used to set the trigger metadata of an auto moderation rule.
|
|
57
|
+
*
|
|
58
|
+
* @typedef {Object} AutoModerationTriggerMetadataOptions
|
|
59
|
+
* @property {string[]} [keywordFilter] The substrings that will be searched for in the content
|
|
60
|
+
* @property {string[]} [regexPatterns] The regular expression patterns which will be matched against the content
|
|
61
|
+
* <info>Only Rust-flavored regular expressions are supported.</info>
|
|
62
|
+
* @property {AutoModerationRuleKeywordPresetType[]} [presets]
|
|
63
|
+
* The internally pre-defined wordsets which will be searched for in the content
|
|
64
|
+
* @property {string[]} [allowList] The substrings that will be exempt from triggering
|
|
65
|
+
* {@link AutoModerationRuleTriggerType.Keyword},
|
|
66
|
+
* {@link AutoModerationRuleTriggerType.KeywordPreset},
|
|
67
|
+
* and {@link AutoModerationRuleTriggerType.MemberProfile}
|
|
68
|
+
* @property {?number} [mentionTotalLimit] The total number of role & user mentions allowed per message
|
|
69
|
+
* @property {boolean} [mentionRaidProtectionEnabled] Whether to automatically detect mention raids
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Options used to set the actions of an auto moderation rule.
|
|
74
|
+
*
|
|
75
|
+
* @typedef {Object} AutoModerationActionOptions
|
|
76
|
+
* @property {AutoModerationActionType} type The type of this auto moderation rule action
|
|
77
|
+
* @property {AutoModerationActionMetadataOptions} [metadata] Additional metadata needed during execution
|
|
78
|
+
* <info>This property is required if using a `type` of
|
|
79
|
+
* {@link AutoModerationActionType.SendAlertMessage} or {@link AutoModerationActionType.Timeout}.</info>
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Options used to set the metadata of an auto moderation rule action.
|
|
84
|
+
*
|
|
85
|
+
* @typedef {Object} AutoModerationActionMetadataOptions
|
|
86
|
+
* @property {GuildTextChannelResolvable|ThreadChannel} [channel] The channel to which content will be logged
|
|
87
|
+
* @property {number} [durationSeconds] The timeout duration in seconds
|
|
88
|
+
* @property {string} [customMessage] The custom message that is shown whenever a message is blocked
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Options used to create an auto moderation rule.
|
|
93
|
+
*
|
|
94
|
+
* @typedef {Object} AutoModerationRuleCreateOptions
|
|
95
|
+
* @property {string} name The name of the auto moderation rule
|
|
96
|
+
* @property {AutoModerationRuleEventType} eventType The event type of the auto moderation rule
|
|
97
|
+
* @property {AutoModerationRuleTriggerType} triggerType The trigger type of the auto moderation rule
|
|
98
|
+
* @property {AutoModerationTriggerMetadataOptions} [triggerMetadata] The trigger metadata of the auto moderation rule
|
|
99
|
+
* <info>This property is required if using a `triggerType` of
|
|
100
|
+
* {@link AutoModerationRuleTriggerType.Keyword},
|
|
101
|
+
* {@link AutoModerationRuleTriggerType.KeywordPreset},
|
|
102
|
+
* {@link AutoModerationRuleTriggerType.MentionSpam},
|
|
103
|
+
* or {@link AutoModerationRuleTriggerType.MemberProfile}.</info>
|
|
104
|
+
* @property {AutoModerationActionOptions[]} actions
|
|
105
|
+
* The actions that will execute when the auto moderation rule is triggered
|
|
106
|
+
* @property {boolean} [enabled] Whether the auto moderation rule should be enabled
|
|
107
|
+
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [exemptRoles]
|
|
108
|
+
* The roles that should not be affected by the auto moderation rule
|
|
109
|
+
* @property {Collection<Snowflake, GuildChannel|ThreadChannel>|GuildChannelResolvable[]} [exemptChannels]
|
|
110
|
+
* The channels that should not be affected by the auto moderation rule
|
|
111
|
+
* @property {string} [reason] The reason for creating the auto moderation rule
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new auto moderation rule.
|
|
116
|
+
*
|
|
117
|
+
* @param {AutoModerationRuleCreateOptions} options Options for creating the auto moderation rule
|
|
118
|
+
* @returns {Promise<AutoModerationRule>}
|
|
119
|
+
*/
|
|
120
|
+
async create({
|
|
121
|
+
name,
|
|
122
|
+
eventType,
|
|
123
|
+
triggerType,
|
|
124
|
+
triggerMetadata,
|
|
125
|
+
actions,
|
|
126
|
+
enabled,
|
|
127
|
+
exemptRoles,
|
|
128
|
+
exemptChannels,
|
|
129
|
+
reason,
|
|
130
|
+
}) {
|
|
131
|
+
const data = await this.client.rest.post(Routes.guildAutoModerationRules(this.guild.id), {
|
|
132
|
+
body: {
|
|
133
|
+
name,
|
|
134
|
+
event_type: eventType,
|
|
135
|
+
trigger_type: triggerType,
|
|
136
|
+
trigger_metadata: triggerMetadata && {
|
|
137
|
+
keyword_filter: triggerMetadata.keywordFilter,
|
|
138
|
+
regex_patterns: triggerMetadata.regexPatterns,
|
|
139
|
+
presets: triggerMetadata.presets,
|
|
140
|
+
allow_list: triggerMetadata.allowList,
|
|
141
|
+
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
|
142
|
+
mention_raid_protection_enabled: triggerMetadata.mentionRaidProtectionEnabled,
|
|
143
|
+
},
|
|
144
|
+
actions: actions.map(action => ({
|
|
145
|
+
type: action.type,
|
|
146
|
+
metadata: {
|
|
147
|
+
duration_seconds: action.metadata?.durationSeconds,
|
|
148
|
+
channel_id: action.metadata?.channel && this.guild.channels.resolveId(action.metadata.channel),
|
|
149
|
+
custom_message: action.metadata?.customMessage,
|
|
150
|
+
},
|
|
151
|
+
})),
|
|
152
|
+
enabled,
|
|
153
|
+
exempt_roles: exemptRoles?.map(exemptRole => this.guild.roles.resolveId(exemptRole)),
|
|
154
|
+
exempt_channels: exemptChannels?.map(exemptChannel => this.guild.channels.resolveId(exemptChannel)),
|
|
155
|
+
},
|
|
156
|
+
reason,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return this._add(data);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Options used to edit an auto moderation rule.
|
|
164
|
+
*
|
|
165
|
+
* @typedef {Object} AutoModerationRuleEditOptions
|
|
166
|
+
* @property {string} [name] The name of the auto moderation rule
|
|
167
|
+
* @property {AutoModerationRuleEventType} [eventType] The event type of the auto moderation rule
|
|
168
|
+
* @property {AutoModerationTriggerMetadataOptions} [triggerMetadata] The trigger metadata of the auto moderation rule
|
|
169
|
+
* @property {AutoModerationActionOptions[]} [actions]
|
|
170
|
+
* The actions that will execute when the auto moderation rule is triggered
|
|
171
|
+
* @property {boolean} [enabled] Whether the auto moderation rule should be enabled
|
|
172
|
+
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [exemptRoles]
|
|
173
|
+
* The roles that should not be affected by the auto moderation rule
|
|
174
|
+
* @property {Collection<Snowflake, GuildChannel|ThreadChannel>|GuildChannelResolvable[]} [exemptChannels]
|
|
175
|
+
* The channels that should not be affected by the auto moderation rule
|
|
176
|
+
* @property {string} [reason] The reason for creating the auto moderation rule
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Edits an auto moderation rule.
|
|
181
|
+
*
|
|
182
|
+
* @param {AutoModerationRuleResolvable} autoModerationRule The auto moderation rule to edit
|
|
183
|
+
* @param {AutoModerationRuleEditOptions} options Options for editing the auto moderation rule
|
|
184
|
+
* @returns {Promise<AutoModerationRule>}
|
|
185
|
+
*/
|
|
186
|
+
async edit(
|
|
187
|
+
autoModerationRule,
|
|
188
|
+
{ name, eventType, triggerMetadata, actions, enabled, exemptRoles, exemptChannels, reason },
|
|
189
|
+
) {
|
|
190
|
+
const autoModerationRuleId = this.resolveId(autoModerationRule);
|
|
191
|
+
|
|
192
|
+
const data = await this.client.rest.patch(Routes.guildAutoModerationRule(this.guild.id, autoModerationRuleId), {
|
|
193
|
+
body: {
|
|
194
|
+
name,
|
|
195
|
+
event_type: eventType,
|
|
196
|
+
trigger_metadata: triggerMetadata && {
|
|
197
|
+
keyword_filter: triggerMetadata.keywordFilter,
|
|
198
|
+
regex_patterns: triggerMetadata.regexPatterns,
|
|
199
|
+
presets: triggerMetadata.presets,
|
|
200
|
+
allow_list: triggerMetadata.allowList,
|
|
201
|
+
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
|
202
|
+
mention_raid_protection_enabled: triggerMetadata.mentionRaidProtectionEnabled,
|
|
203
|
+
},
|
|
204
|
+
actions: actions?.map(action => ({
|
|
205
|
+
type: action.type,
|
|
206
|
+
metadata: {
|
|
207
|
+
duration_seconds: action.metadata?.durationSeconds,
|
|
208
|
+
channel_id: action.metadata?.channel && this.guild.channels.resolveId(action.metadata.channel),
|
|
209
|
+
custom_message: action.metadata?.customMessage,
|
|
210
|
+
},
|
|
211
|
+
})),
|
|
212
|
+
enabled,
|
|
213
|
+
exempt_roles: exemptRoles?.map(exemptRole => this.guild.roles.resolveId(exemptRole)),
|
|
214
|
+
exempt_channels: exemptChannels?.map(exemptChannel => this.guild.channels.resolveId(exemptChannel)),
|
|
215
|
+
},
|
|
216
|
+
reason,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return this._add(data);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Data that can be resolved to give an AutoModerationRule object. This can be:
|
|
224
|
+
* - An AutoModerationRule
|
|
225
|
+
* - A Snowflake
|
|
226
|
+
*
|
|
227
|
+
* @typedef {AutoModerationRule|Snowflake} AutoModerationRuleResolvable
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Options used to fetch a single auto moderation rule from a guild.
|
|
232
|
+
*
|
|
233
|
+
* @typedef {BaseFetchOptions} FetchAutoModerationRuleOptions
|
|
234
|
+
* @property {AutoModerationRuleResolvable} autoModerationRule The auto moderation rule to fetch
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Options used to fetch all auto moderation rules from a guild.
|
|
239
|
+
*
|
|
240
|
+
* @typedef {Object} FetchAutoModerationRulesOptions
|
|
241
|
+
* @property {boolean} [cache] Whether to cache the fetched auto moderation rules
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Fetches auto moderation rules from Discord.
|
|
246
|
+
*
|
|
247
|
+
* @param {AutoModerationRuleResolvable|FetchAutoModerationRuleOptions|FetchAutoModerationRulesOptions} [options]
|
|
248
|
+
* Options for fetching auto moderation rule(s)
|
|
249
|
+
* @returns {Promise<AutoModerationRule|Collection<Snowflake, AutoModerationRule>>}
|
|
250
|
+
* @example
|
|
251
|
+
* // Fetch all auto moderation rules from a guild without caching
|
|
252
|
+
* guild.autoModerationRules.fetch({ cache: false })
|
|
253
|
+
* .then(console.log)
|
|
254
|
+
* .catch(console.error);
|
|
255
|
+
* @example
|
|
256
|
+
* // Fetch a single auto moderation rule
|
|
257
|
+
* guild.autoModerationRules.fetch('979083472868098119')
|
|
258
|
+
* .then(console.log)
|
|
259
|
+
* .catch(console.error);
|
|
260
|
+
* @example
|
|
261
|
+
* // Fetch a single auto moderation rule without checking cache and without caching
|
|
262
|
+
* guild.autoModerationRules.fetch({ autoModerationRule: '979083472868098119', cache: false, force: true })
|
|
263
|
+
* .then(console.log)
|
|
264
|
+
* .catch(console.error)
|
|
265
|
+
*/
|
|
266
|
+
async fetch(options) {
|
|
267
|
+
if (!options) return this._fetchMany();
|
|
268
|
+
const { autoModerationRule, cache, force } = options;
|
|
269
|
+
const resolvedAutoModerationRule = this.resolveId(autoModerationRule ?? options);
|
|
270
|
+
if (resolvedAutoModerationRule) {
|
|
271
|
+
return this._fetchSingle({ autoModerationRule: resolvedAutoModerationRule, cache, force });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return this._fetchMany(options);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async _fetchSingle({ autoModerationRule, cache, force = false }) {
|
|
278
|
+
if (!force) {
|
|
279
|
+
const existing = this.cache.get(autoModerationRule);
|
|
280
|
+
if (existing) return existing;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const data = await this.client.rest.get(Routes.guildAutoModerationRule(this.guild.id, autoModerationRule));
|
|
284
|
+
return this._add(data, cache);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async _fetchMany(options = {}) {
|
|
288
|
+
const data = await this.client.rest.get(Routes.guildAutoModerationRules(this.guild.id));
|
|
289
|
+
|
|
290
|
+
return data.reduce(
|
|
291
|
+
(col, autoModerationRule) => col.set(autoModerationRule.id, this._add(autoModerationRule, options.cache)),
|
|
292
|
+
new Collection(),
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Deletes an auto moderation rule.
|
|
298
|
+
*
|
|
299
|
+
* @param {AutoModerationRuleResolvable} autoModerationRule The auto moderation rule to delete
|
|
300
|
+
* @param {string} [reason] The reason for deleting the auto moderation rule
|
|
301
|
+
* @returns {Promise<void>}
|
|
302
|
+
*/
|
|
303
|
+
async delete(autoModerationRule, reason) {
|
|
304
|
+
const autoModerationRuleId = this.resolveId(autoModerationRule);
|
|
305
|
+
await this.client.rest.delete(Routes.guildAutoModerationRule(this.guild.id, autoModerationRuleId), { reason });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
import { MakeCacheOverrideSymbol } from '../util/Symbols.js';
|
|
3
|
+
import { DataManager } from './DataManager.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages the API methods of a data model with a mutable cache of instances.
|
|
7
|
+
*
|
|
8
|
+
* @extends {DataManager}
|
|
9
|
+
* @abstract
|
|
10
|
+
*/
|
|
11
|
+
export abstract class CachedManager extends DataManager {
|
|
12
|
+
public _cache: any;
|
|
13
|
+
public holds: any;
|
|
14
|
+
|
|
15
|
+
constructor(client: any, holds: any, iterable?: any) {
|
|
16
|
+
super(client, holds);
|
|
17
|
+
|
|
18
|
+
this.holds = holds;
|
|
19
|
+
|
|
20
|
+
Object.defineProperty(this, '_cache', {
|
|
21
|
+
value: (this.client as any).options.makeCache({
|
|
22
|
+
holds: this.holds,
|
|
23
|
+
manager: this.constructor,
|
|
24
|
+
managerType: (this.constructor as any)[MakeCacheOverrideSymbol] ?? this.constructor,
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (iterable) {
|
|
29
|
+
for (const item of iterable) {
|
|
30
|
+
this._add(item);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override get cache(): any {
|
|
36
|
+
return this._cache;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_add(data: any, cache = true, { id, extras = [] as any[] }: { id?: string; extras?: any[] } = {}) {
|
|
40
|
+
const existing = (this.cache as any).get(id ?? data.id);
|
|
41
|
+
if (existing) {
|
|
42
|
+
if (cache) {
|
|
43
|
+
if (typeof existing._patch === 'function') existing._patch(data);
|
|
44
|
+
return existing;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const clone = typeof existing._clone === 'function' ? existing._clone() : existing;
|
|
48
|
+
if (typeof clone._patch === 'function') clone._patch(data);
|
|
49
|
+
return clone;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const entry = this.holds ? new this.holds(this.client, data, ...extras) : data;
|
|
53
|
+
if (cache) (this.cache as any).set(id ?? entry.id, entry);
|
|
54
|
+
return entry;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { GuildChannel } from '../structures/GuildChannel.js';
|
|
2
|
+
import { DataManager } from './DataManager.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Manages API methods for CategoryChannels' children.
|
|
6
|
+
*
|
|
7
|
+
* @extends {DataManager}
|
|
8
|
+
*/
|
|
9
|
+
export class CategoryChannelChildManager extends DataManager {
|
|
10
|
+
constructor(channel) {
|
|
11
|
+
super(channel.client, GuildChannel);
|
|
12
|
+
/**
|
|
13
|
+
* The category channel this manager belongs to
|
|
14
|
+
*
|
|
15
|
+
* @type {CategoryChannel}
|
|
16
|
+
*/
|
|
17
|
+
this.channel = channel;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The channels that are a part of this category
|
|
22
|
+
*
|
|
23
|
+
* @type {Collection<Snowflake, GuildChannel>}
|
|
24
|
+
* @readonly
|
|
25
|
+
*/
|
|
26
|
+
get cache() {
|
|
27
|
+
return this.guild.channels.cache.filter(channel => channel.parentId === this.channel.id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The guild this manager belongs to
|
|
32
|
+
*
|
|
33
|
+
* @type {Guild}
|
|
34
|
+
* @readonly
|
|
35
|
+
*/
|
|
36
|
+
get guild() {
|
|
37
|
+
return this.channel.guild;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for creating a channel using {@link CategoryChannelChildManager#create}.
|
|
42
|
+
*
|
|
43
|
+
* @typedef {Object} CategoryCreateChannelOptions
|
|
44
|
+
* @property {string} name The name for the new channel
|
|
45
|
+
* @property {ChannelType} [type=ChannelType.GuildText] The type of the new channel.
|
|
46
|
+
* @property {string} [topic] The topic for the new channel
|
|
47
|
+
* @property {boolean} [nsfw] Whether the new channel is NSFW
|
|
48
|
+
* @property {number} [bitrate] Bitrate of the new channel in bits (only voice)
|
|
49
|
+
* @property {number} [userLimit] Maximum amount of users allowed in the new channel (only voice)
|
|
50
|
+
* @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
|
|
51
|
+
* Permission overwrites of the new channel
|
|
52
|
+
* @property {number} [position] Position of the new channel
|
|
53
|
+
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the new channel in seconds
|
|
54
|
+
* @property {string} [rtcRegion] The specific region of the new channel.
|
|
55
|
+
* @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the voice channel
|
|
56
|
+
* @property {number} [defaultThreadRateLimitPerUser] The initial rate limit per user (slowmode)
|
|
57
|
+
* to set on newly created threads in a channel.
|
|
58
|
+
* @property {GuildForumTagData[]} [availableTags] The tags that can be used in this channel (forum only).
|
|
59
|
+
* @property {DefaultReactionEmoji} [defaultReactionEmoji]
|
|
60
|
+
* The emoji to show in the add reaction button on a thread in a guild forum channel.
|
|
61
|
+
* @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration]
|
|
62
|
+
* The default auto archive duration for all new threads in this channel
|
|
63
|
+
* @property {SortOrderType} [defaultSortOrder] The default sort order mode used to order posts (forum only).
|
|
64
|
+
* @property {ForumLayoutType} [defaultForumLayout] The default layout used to display posts (forum only).
|
|
65
|
+
* @property {string} [reason] Reason for creating the new channel
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new channel within this category.
|
|
70
|
+
* <info>You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel.</info>
|
|
71
|
+
*
|
|
72
|
+
* @param {CategoryCreateChannelOptions} options Options for creating the new channel
|
|
73
|
+
* @returns {Promise<GuildChannel>}
|
|
74
|
+
*/
|
|
75
|
+
async create(options) {
|
|
76
|
+
return this.guild.channels.create({
|
|
77
|
+
...options,
|
|
78
|
+
parent: this.channel.id,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { lazy, isFileBodyEncodable, isJSONEncodable } from '@ovencord/util';
|
|
3
|
+
import { Routes } from 'discord-api-types/v10';
|
|
4
|
+
import { BaseChannel } from '../structures/BaseChannel.js';
|
|
5
|
+
import { MessagePayload } from '../structures/MessagePayload.js';
|
|
6
|
+
import { createChannel } from '../util/Channels.js';
|
|
7
|
+
import { ThreadChannelTypes } from '../util/Constants.js';
|
|
8
|
+
import { Events } from '../util/Events.js';
|
|
9
|
+
import { CachedManager } from './CachedManager.js';
|
|
10
|
+
|
|
11
|
+
const getMessage = lazy(() => require('../structures/Message.js').Message);
|
|
12
|
+
|
|
13
|
+
let cacheWarningEmitted = false;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A manager of channels belonging to a client
|
|
17
|
+
*
|
|
18
|
+
* @extends {CachedManager}
|
|
19
|
+
*/
|
|
20
|
+
export class ChannelManager extends CachedManager {
|
|
21
|
+
public client: any;
|
|
22
|
+
constructor(client, iterable) {
|
|
23
|
+
super(client, BaseChannel, iterable);
|
|
24
|
+
const defaultCaching =
|
|
25
|
+
this._cache.constructor.name === 'Collection' ||
|
|
26
|
+
this._cache.maxSize === undefined ||
|
|
27
|
+
this._cache.maxSize === Infinity;
|
|
28
|
+
if (!cacheWarningEmitted && !defaultCaching) {
|
|
29
|
+
cacheWarningEmitted = true;
|
|
30
|
+
process.emitWarning(
|
|
31
|
+
`Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
|
|
32
|
+
'UnsupportedCacheOverwriteWarning',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The cache of Channels
|
|
39
|
+
*
|
|
40
|
+
* @type {Collection<Snowflake, BaseChannel>}
|
|
41
|
+
* @name ChannelManager#cache
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
|
|
45
|
+
const existing = this.cache.get(data.id);
|
|
46
|
+
if (existing) {
|
|
47
|
+
if (cache) existing._patch(data);
|
|
48
|
+
guild?.channels?._add(existing);
|
|
49
|
+
if (ThreadChannelTypes.includes(existing.type)) {
|
|
50
|
+
existing.parent?.threads?._add(existing);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return existing;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const channel = createChannel(this.client, data, guild, { allowUnknownGuild });
|
|
57
|
+
|
|
58
|
+
if (!channel) {
|
|
59
|
+
this.client.emit(Events.Debug, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (cache && !allowUnknownGuild) this.cache.set(channel.id, channel);
|
|
64
|
+
|
|
65
|
+
return channel;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_remove(id) {
|
|
69
|
+
const channel = this.cache.get(id);
|
|
70
|
+
channel?.guild?.channels.cache.delete(id);
|
|
71
|
+
|
|
72
|
+
for (const [code, invite] of channel?.guild?.invites.cache ?? []) {
|
|
73
|
+
if (invite.channelId === id) channel.guild.invites.cache.delete(code);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
channel?.parent?.threads?.cache.delete(id);
|
|
77
|
+
this.cache.delete(id);
|
|
78
|
+
|
|
79
|
+
if (channel?.threads) {
|
|
80
|
+
for (const threadId of channel.threads.cache.keys()) {
|
|
81
|
+
this.cache.delete(threadId);
|
|
82
|
+
channel.guild?.channels.cache.delete(threadId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Data that can be resolved to give a Channel object. This can be:
|
|
89
|
+
* - A Channel object
|
|
90
|
+
* - A Snowflake
|
|
91
|
+
*
|
|
92
|
+
* @typedef {BaseChannel|Snowflake} ChannelResolvable
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Resolves a ChannelResolvable to a Channel object.
|
|
97
|
+
*
|
|
98
|
+
* @method resolve
|
|
99
|
+
* @memberof ChannelManager
|
|
100
|
+
* @instance
|
|
101
|
+
* @param {ChannelResolvable} channel The channel resolvable to resolve
|
|
102
|
+
* @returns {?BaseChannel}
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Resolves a ChannelResolvable to a channel id string.
|
|
107
|
+
*
|
|
108
|
+
* @method resolveId
|
|
109
|
+
* @memberof ChannelManager
|
|
110
|
+
* @instance
|
|
111
|
+
* @param {ChannelResolvable} channel The channel resolvable to resolve
|
|
112
|
+
* @returns {?Snowflake}
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Options for fetching a channel from Discord
|
|
117
|
+
*
|
|
118
|
+
* @typedef {BaseFetchOptions} FetchChannelOptions
|
|
119
|
+
* @property {boolean} [allowUnknownGuild=false] Allows the channel to be returned even if the guild is not in cache,
|
|
120
|
+
* it will not be cached. <warn>Many of the properties and methods on the returned channel will throw errors</warn>
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Obtains a channel from Discord, or the channel cache if it's already available.
|
|
125
|
+
*
|
|
126
|
+
* @param {Snowflake} id The channel's id
|
|
127
|
+
* @param {FetchChannelOptions} [options] Additional options for this fetch
|
|
128
|
+
* @returns {Promise<?BaseChannel>}
|
|
129
|
+
* @example
|
|
130
|
+
* // Fetch a channel by its id
|
|
131
|
+
* client.channels.fetch('222109930545610754')
|
|
132
|
+
* .then(channel => console.log(channel.name))
|
|
133
|
+
* .catch(console.error);
|
|
134
|
+
*/
|
|
135
|
+
async fetch(id, { allowUnknownGuild = false, cache = true, force = false } = {}) {
|
|
136
|
+
if (!force) {
|
|
137
|
+
const existing = this.cache.get(id);
|
|
138
|
+
if (existing && !existing.partial) return existing;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const data = await this.client.rest.get(Routes.channel(id));
|
|
142
|
+
return this._add(data, null, { cache, allowUnknownGuild });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Creates a message in a channel.
|
|
147
|
+
*
|
|
148
|
+
* @param {TextChannelResolvable} channel The channel to send the message to
|
|
149
|
+
* @param {string|MessagePayload|MessageCreateOptions|JSONEncodable<RESTPostAPIChannelMessageJSONBody>|FileBodyEncodable<RESTPostAPIChannelMessageJSONBody>} options The options to provide
|
|
150
|
+
* @returns {Promise<Message>}
|
|
151
|
+
* @example
|
|
152
|
+
* // Send a basic message
|
|
153
|
+
* client.channels.createMessage(channel, 'hello!')
|
|
154
|
+
* .then(message => console.log(`Sent message: ${message.content}`))
|
|
155
|
+
* .catch(console.error);
|
|
156
|
+
* @example
|
|
157
|
+
* // Send a remote file
|
|
158
|
+
* client.channels.createMessage(channel, {
|
|
159
|
+
* files: ['https://github.com/discordjs.png']
|
|
160
|
+
* })
|
|
161
|
+
* .then(console.log)
|
|
162
|
+
* .catch(console.error);
|
|
163
|
+
* @example
|
|
164
|
+
* // Send a local file
|
|
165
|
+
* client.channels.createMessage(channel, {
|
|
166
|
+
* files: [{
|
|
167
|
+
* attachment: 'entire/path/to/file.jpg',
|
|
168
|
+
* name: 'file.jpg',
|
|
169
|
+
* description: 'A description of the file'
|
|
170
|
+
* }]
|
|
171
|
+
* })
|
|
172
|
+
* .then(console.log)
|
|
173
|
+
* .catch(console.error);
|
|
174
|
+
*/
|
|
175
|
+
async createMessage(channel, options) {
|
|
176
|
+
let payload;
|
|
177
|
+
|
|
178
|
+
if (options instanceof MessagePayload) {
|
|
179
|
+
payload = await options.resolveBody().resolveFiles();
|
|
180
|
+
} else if (isFileBodyEncodable(options)) {
|
|
181
|
+
payload = options.toFileBody();
|
|
182
|
+
} else if (isJSONEncodable(options)) {
|
|
183
|
+
payload = { body: options.toJSON() };
|
|
184
|
+
} else {
|
|
185
|
+
payload = await MessagePayload.create(this, options).resolveBody().resolveFiles();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const resolvedChannelId = this.resolveId(channel);
|
|
189
|
+
const resolvedChannel = this.resolve(channel);
|
|
190
|
+
const data = await this.client.rest.post(Routes.channelMessages(resolvedChannelId), payload);
|
|
191
|
+
|
|
192
|
+
return resolvedChannel?.messages._add(data) ?? new (getMessage())(this.client, data);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MessageManager } from './MessageManager.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Manages API methods for messages in direct message channels and holds their cache.
|
|
5
|
+
*
|
|
6
|
+
* @extends {MessageManager}
|
|
7
|
+
*/
|
|
8
|
+
export class DMMessageManager extends MessageManager {
|
|
9
|
+
/**
|
|
10
|
+
* The channel that the messages belong to
|
|
11
|
+
*
|
|
12
|
+
* @name DMMessageManager#channel
|
|
13
|
+
* @type {DMChannel}
|
|
14
|
+
*/
|
|
15
|
+
}
|