@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,453 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { ApplicationCommandPermissionType, RESTJSONErrorCodes, Routes } from 'discord-api-types/v10';
|
|
3
|
+
import { DiscordjsError, DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
4
|
+
import { BaseManager } from './BaseManager.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manages API methods for permissions of Application Commands.
|
|
8
|
+
*
|
|
9
|
+
* @extends {BaseManager}
|
|
10
|
+
*/
|
|
11
|
+
export class ApplicationCommandPermissionsManager extends BaseManager {
|
|
12
|
+
public manager: any;
|
|
13
|
+
public guildId: any;
|
|
14
|
+
public commandId: any;
|
|
15
|
+
constructor(manager) {
|
|
16
|
+
super(manager.client);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The manager or command that this manager belongs to
|
|
20
|
+
*
|
|
21
|
+
* @type {ApplicationCommandManager|ApplicationCommand}
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
this.manager = manager;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The guild that this manager acts on
|
|
28
|
+
*
|
|
29
|
+
* @type {?Guild}
|
|
30
|
+
*/
|
|
31
|
+
this.guild = manager.guild ?? null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The id of the guild that this manager acts on
|
|
35
|
+
*
|
|
36
|
+
* @type {?Snowflake}
|
|
37
|
+
*/
|
|
38
|
+
this.guildId = manager.guildId ?? manager.guild?.id ?? null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The id of the command this manager acts on
|
|
42
|
+
*
|
|
43
|
+
* @type {?Snowflake}
|
|
44
|
+
*/
|
|
45
|
+
this.commandId = manager.id ?? null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The APIRouter path to the commands
|
|
50
|
+
*
|
|
51
|
+
* @param {Snowflake} guildId The guild's id to use in the path,
|
|
52
|
+
* @param {Snowflake} [commandId] The application command's id
|
|
53
|
+
* @returns {string}
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
permissionsPath(guildId, commandId) {
|
|
57
|
+
if (commandId) {
|
|
58
|
+
return Routes.applicationCommandPermissions(this.client.application.id, guildId, commandId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Routes.guildApplicationCommandsPermissions(this.client.application.id, guildId);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The object returned when fetching permissions for an application command.
|
|
66
|
+
*
|
|
67
|
+
* @typedef {Object} ApplicationCommandPermissions
|
|
68
|
+
* @property {Snowflake} id The role, user, or channel's id. Can also be a
|
|
69
|
+
* {@link https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants permission constant}.
|
|
70
|
+
* @property {ApplicationCommandPermissionType} type Whether this permission is for a role or a user
|
|
71
|
+
* @property {boolean} permission Whether the role or user has the permission to use this command
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Options for managing permissions for one or more Application Commands
|
|
76
|
+
* <warn>When passing these options to a manager where `guildId` is `null`,
|
|
77
|
+
* `guild` is a required parameter</warn>
|
|
78
|
+
*
|
|
79
|
+
* @typedef {Object} BaseApplicationCommandPermissionsOptions
|
|
80
|
+
* @property {GuildResolvable} [guild] The guild to modify / check permissions for
|
|
81
|
+
* <warn>Ignored when the manager has a non-null `guildId` property</warn>
|
|
82
|
+
* @property {ApplicationCommandResolvable} [command] The command to modify / check permissions for
|
|
83
|
+
* <warn>Ignored when the manager has a non-null `commandId` property</warn>
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Fetches the permissions for one or multiple commands. Providing the client's id as the "command id" will fetch
|
|
88
|
+
* _only_ the guild level permissions
|
|
89
|
+
*
|
|
90
|
+
* @param {BaseApplicationCommandPermissionsOptions} [options] Options used to fetch permissions
|
|
91
|
+
* @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
|
|
92
|
+
* @example
|
|
93
|
+
* // Fetch permissions for one command
|
|
94
|
+
* guild.commands.permissions.fetch({ command: '123456789012345678' })
|
|
95
|
+
* .then(perms => console.log(`Fetched ${perms.length} overwrites`))
|
|
96
|
+
* .catch(console.error);
|
|
97
|
+
* @example
|
|
98
|
+
* // Fetch permissions for all commands in a guild
|
|
99
|
+
* client.application.commands.permissions.fetch({ guild: '123456789012345678' })
|
|
100
|
+
* .then(perms => console.log(`Fetched permissions for ${perms.size} commands`))
|
|
101
|
+
* .catch(console.error);
|
|
102
|
+
* @example
|
|
103
|
+
* // Fetch guild level permissions
|
|
104
|
+
* guild.commands.permissions.fetch({ command: client.user.id })
|
|
105
|
+
* .then(perms => console.log(`Fetched ${perms.length} guild level permissions`))
|
|
106
|
+
* .catch(console.error);
|
|
107
|
+
*/
|
|
108
|
+
async fetch({ guild, command } = {}) {
|
|
109
|
+
const { guildId, commandId } = this._validateOptions(guild, command);
|
|
110
|
+
if (commandId) {
|
|
111
|
+
const innerData = await this.client.rest.get(this.permissionsPath(guildId, commandId));
|
|
112
|
+
return innerData.permissions;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const data = await this.client.rest.get(this.permissionsPath(guildId));
|
|
116
|
+
return data.reduce((coll, perm) => coll.set(perm.id, perm.permissions), new Collection());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Options used to set permissions for one or more Application Commands in a guild
|
|
121
|
+
* <warn>Omitting the `command` parameter edits the guild wide permissions
|
|
122
|
+
* when the manager's `commandId` is `null`</warn>
|
|
123
|
+
*
|
|
124
|
+
* @typedef {BaseApplicationCommandPermissionsOptions} ApplicationCommandPermissionsEditOptions
|
|
125
|
+
* @property {ApplicationCommandPermissions[]} permissions The new permissions for the guild or overwrite
|
|
126
|
+
* @property {string} token The bearer token to use that authorizes the permission edit
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Sets the permissions for the guild or a command overwrite.
|
|
131
|
+
*
|
|
132
|
+
* @param {ApplicationCommandPermissionsEditOptions} options Options used to set permissions
|
|
133
|
+
* @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
|
|
134
|
+
* @example
|
|
135
|
+
* // Set a permission overwrite for a command
|
|
136
|
+
* client.application.commands.permissions.set({
|
|
137
|
+
* guild: '892455839386304532',
|
|
138
|
+
* command: '123456789012345678',
|
|
139
|
+
* token: 'TotallyRealToken',
|
|
140
|
+
* permissions: [
|
|
141
|
+
* {
|
|
142
|
+
* id: '876543210987654321',
|
|
143
|
+
* type: ApplicationCommandPermissionType.User,
|
|
144
|
+
* permission: false,
|
|
145
|
+
* },
|
|
146
|
+
* ]})
|
|
147
|
+
* .then(console.log)
|
|
148
|
+
* .catch(console.error);
|
|
149
|
+
* @example
|
|
150
|
+
* // Set the permissions used for the guild (commands without overwrites)
|
|
151
|
+
* guild.commands.permissions.set({ token: 'TotallyRealToken', permissions: [
|
|
152
|
+
* {
|
|
153
|
+
* id: '123456789012345678',
|
|
154
|
+
* permissions: [{
|
|
155
|
+
* id: '876543210987654321',
|
|
156
|
+
* type: ApplicationCommandPermissionType.User,
|
|
157
|
+
* permission: false,
|
|
158
|
+
* }],
|
|
159
|
+
* },
|
|
160
|
+
* ]})
|
|
161
|
+
* .then(console.log)
|
|
162
|
+
* .catch(console.error);
|
|
163
|
+
*/
|
|
164
|
+
async set({ guild, command, permissions, token } = {}) {
|
|
165
|
+
if (!token) {
|
|
166
|
+
throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const options = this._validateOptions(guild, command);
|
|
170
|
+
let { commandId } = options;
|
|
171
|
+
|
|
172
|
+
if (!Array.isArray(permissions)) {
|
|
173
|
+
throw new DiscordjsTypeError(
|
|
174
|
+
ErrorCodes.InvalidType,
|
|
175
|
+
'permissions',
|
|
176
|
+
'Array of ApplicationCommandPermissions',
|
|
177
|
+
true,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
commandId ??= this.client.user.id;
|
|
182
|
+
|
|
183
|
+
const data = await this.client.rest.put(this.permissionsPath(options.guildId, commandId), {
|
|
184
|
+
body: { permissions },
|
|
185
|
+
auth: false,
|
|
186
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
187
|
+
});
|
|
188
|
+
return data.permissions;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Add permissions to a command.
|
|
193
|
+
*
|
|
194
|
+
* @param {ApplicationCommandPermissionsEditOptions} options Options used to add permissions
|
|
195
|
+
* @returns {Promise<ApplicationCommandPermissions[]>}
|
|
196
|
+
* @example
|
|
197
|
+
* // Add a rule to block a role from using a command
|
|
198
|
+
* guild.commands.permissions.add({ command: '123456789012345678', token: 'TotallyRealToken', permissions: [
|
|
199
|
+
* {
|
|
200
|
+
* id: '876543211234567890',
|
|
201
|
+
* type: ApplicationCommandPermissionType.Role,
|
|
202
|
+
* permission: false
|
|
203
|
+
* },
|
|
204
|
+
* ]})
|
|
205
|
+
* .then(console.log)
|
|
206
|
+
* .catch(console.error);
|
|
207
|
+
*/
|
|
208
|
+
async add({ guild, command, permissions, token } = {}) {
|
|
209
|
+
if (!token) {
|
|
210
|
+
throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const options = this._validateOptions(guild, command);
|
|
214
|
+
let { commandId } = options;
|
|
215
|
+
commandId ??= this.client.user.id;
|
|
216
|
+
|
|
217
|
+
if (!Array.isArray(permissions)) {
|
|
218
|
+
throw new DiscordjsTypeError(
|
|
219
|
+
ErrorCodes.InvalidType,
|
|
220
|
+
'permissions',
|
|
221
|
+
'Array of ApplicationCommandPermissions',
|
|
222
|
+
true,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let existingPermissions = [];
|
|
227
|
+
try {
|
|
228
|
+
existingPermissions = await this.fetch({ guild: options.guildId, command: commandId });
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const newPermissions = permissions.slice();
|
|
234
|
+
for (const existingPermission of existingPermissions) {
|
|
235
|
+
if (!newPermissions.some(newPermission => newPermission.id === existingPermission.id)) {
|
|
236
|
+
newPermissions.push(existingPermission);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return this.set({ guild: options.guildId, command: commandId, permissions: newPermissions, token });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* A static snowflake that identifies the everyone role for application command permissions.
|
|
245
|
+
* It is the same as the guild id
|
|
246
|
+
*
|
|
247
|
+
* @typedef {Snowflake} RolePermissionConstant
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* A static snowflake that identifies the "all channels" entity for application command permissions.
|
|
252
|
+
* It will be the result of the calculation `guildId - 1`
|
|
253
|
+
*
|
|
254
|
+
* @typedef {Snowflake} ChannelPermissionConstant
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Options used to remove permissions from a command
|
|
259
|
+
* <warn>Omitting the `command` parameter removes from the guild wide permissions
|
|
260
|
+
* when the managers `commandId` is `null`</warn>
|
|
261
|
+
* <warn>At least one of `users`, `roles`, and `channels` is required</warn>
|
|
262
|
+
*
|
|
263
|
+
* @typedef {BaseApplicationCommandPermissionsOptions} RemoveApplicationCommandPermissionsOptions
|
|
264
|
+
* @property {string} token The bearer token to use that authorizes the permission removal
|
|
265
|
+
* @property {UserResolvable[]} [users] The user(s) to remove
|
|
266
|
+
* @property {Array<RoleResolvable|RolePermissionConstant>} [roles] The role(s) to remove
|
|
267
|
+
* @property {Array<GuildChannelResolvable|ChannelPermissionConstant>} [channels] The channel(s) to remove
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Remove permissions from a command.
|
|
272
|
+
*
|
|
273
|
+
* @param {RemoveApplicationCommandPermissionsOptions} options Options used to remove permissions
|
|
274
|
+
* @returns {Promise<ApplicationCommandPermissions[]>}
|
|
275
|
+
* @example
|
|
276
|
+
* // Remove a user permission from this command
|
|
277
|
+
* guild.commands.permissions.remove({
|
|
278
|
+
* command: '123456789012345678', users: '876543210123456789', token: 'TotallyRealToken',
|
|
279
|
+
* })
|
|
280
|
+
* .then(console.log)
|
|
281
|
+
* .catch(console.error);
|
|
282
|
+
* @example
|
|
283
|
+
* // Remove multiple roles from this command
|
|
284
|
+
* guild.commands.permissions.remove({
|
|
285
|
+
* command: '123456789012345678', roles: ['876543210123456789', '765432101234567890'], token: 'TotallyRealToken',
|
|
286
|
+
* })
|
|
287
|
+
* .then(console.log)
|
|
288
|
+
* .catch(console.error);
|
|
289
|
+
*/
|
|
290
|
+
async remove({ guild, command, users, roles, channels, token } = {}) {
|
|
291
|
+
if (!token) {
|
|
292
|
+
throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const options = this._validateOptions(guild, command);
|
|
296
|
+
let { commandId } = options;
|
|
297
|
+
commandId ??= this.client.user.id;
|
|
298
|
+
|
|
299
|
+
if (!users && !roles && !channels) {
|
|
300
|
+
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'users OR roles OR channels', 'Array or Resolvable', true);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const resolvedUserIds = [];
|
|
304
|
+
if (Array.isArray(users)) {
|
|
305
|
+
for (const user of users) {
|
|
306
|
+
const userId = this.client.users.resolveId(user);
|
|
307
|
+
if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'users', user);
|
|
308
|
+
resolvedUserIds.push(userId);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const resolvedRoleIds = [];
|
|
313
|
+
if (Array.isArray(roles)) {
|
|
314
|
+
for (const role of roles) {
|
|
315
|
+
if (typeof role === 'string') {
|
|
316
|
+
resolvedRoleIds.push(role);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'roles');
|
|
321
|
+
const roleId = this.guild.roles.resolveId(role);
|
|
322
|
+
if (!roleId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'users', role);
|
|
323
|
+
resolvedRoleIds.push(roleId);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const resolvedChannelIds = [];
|
|
328
|
+
if (Array.isArray(channels)) {
|
|
329
|
+
for (const channel of channels) {
|
|
330
|
+
if (typeof channel === 'string') {
|
|
331
|
+
resolvedChannelIds.push(channel);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'channels');
|
|
336
|
+
const channelId = this.guild.channels.resolveId(channel);
|
|
337
|
+
if (!channelId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'channels', channel);
|
|
338
|
+
resolvedChannelIds.push(channelId);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
let existing = [];
|
|
343
|
+
try {
|
|
344
|
+
existing = await this.fetch({ guild: options.guildId, command: commandId });
|
|
345
|
+
} catch (error) {
|
|
346
|
+
if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const permissions = existing.filter(perm => {
|
|
350
|
+
switch (perm.type) {
|
|
351
|
+
case ApplicationCommandPermissionType.Role:
|
|
352
|
+
return !resolvedRoleIds.includes(perm.id);
|
|
353
|
+
case ApplicationCommandPermissionType.User:
|
|
354
|
+
return !resolvedUserIds.includes(perm.id);
|
|
355
|
+
case ApplicationCommandPermissionType.Channel:
|
|
356
|
+
return !resolvedChannelIds.includes(perm.id);
|
|
357
|
+
default:
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return this.set({ guild: options.guildId, command: commandId, permissions, token });
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Options used to check the existence of permissions on a command
|
|
367
|
+
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
|
|
368
|
+
*
|
|
369
|
+
* @typedef {BaseApplicationCommandPermissionsOptions} HasApplicationCommandPermissionsOptions
|
|
370
|
+
* @property {ApplicationCommandPermissionIdResolvable} permissionId The entity to check if a permission exists for
|
|
371
|
+
* on this command.
|
|
372
|
+
* @property {ApplicationCommandPermissionType} [permissionType] Check for a specific type of permission
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Check whether a permission exists for a user, role, or channel
|
|
377
|
+
*
|
|
378
|
+
* @param {HasApplicationCommandPermissionsOptions} options Options used to check permissions
|
|
379
|
+
* @returns {Promise<boolean>}
|
|
380
|
+
* @example
|
|
381
|
+
* guild.commands.permissions.has({ command: '123456789012345678', permissionId: '876543210123456789' })
|
|
382
|
+
* .then(console.log)
|
|
383
|
+
* .catch(console.error);
|
|
384
|
+
*/
|
|
385
|
+
async has({ guild, command, permissionId, permissionType }) {
|
|
386
|
+
const { guildId, commandId } = this._validateOptions(guild, command);
|
|
387
|
+
if (!commandId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'command', 'ApplicationCommandResolvable');
|
|
388
|
+
|
|
389
|
+
if (!permissionId) {
|
|
390
|
+
throw new DiscordjsTypeError(
|
|
391
|
+
ErrorCodes.InvalidType,
|
|
392
|
+
'permissionId',
|
|
393
|
+
'UserResolvable, RoleResolvable, ChannelResolvable, or Permission Constant',
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
let resolvedId = permissionId;
|
|
398
|
+
if (typeof permissionId !== 'string') {
|
|
399
|
+
resolvedId = this.client.users.resolveId(permissionId);
|
|
400
|
+
if (!resolvedId) {
|
|
401
|
+
if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'roles');
|
|
402
|
+
resolvedId = this.guild.roles.resolveId(permissionId);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
resolvedId ??= this.guild.channels.resolveId(permissionId);
|
|
406
|
+
|
|
407
|
+
if (!resolvedId) {
|
|
408
|
+
throw new DiscordjsTypeError(
|
|
409
|
+
ErrorCodes.InvalidType,
|
|
410
|
+
'permissionId',
|
|
411
|
+
'UserResolvable, RoleResolvable, ChannelResolvable, or Permission Constant',
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
let existing = [];
|
|
417
|
+
try {
|
|
418
|
+
existing = await this.fetch({ guild: guildId, command: commandId });
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Check permission type if provided for the single edge case where a channel id is the same as the everyone role id
|
|
424
|
+
return existing.some(perm => perm.id === resolvedId && (permissionType ?? perm.type) === perm.type);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
_validateOptions(guild, command) {
|
|
428
|
+
const guildId = this.guildId ?? this.client.guilds.resolveId(guild);
|
|
429
|
+
if (!guildId) throw new DiscordjsError(ErrorCodes.GlobalCommandPermissions);
|
|
430
|
+
let commandId = this.commandId;
|
|
431
|
+
if (command && !commandId) {
|
|
432
|
+
commandId = this.manager.resolveId?.(command);
|
|
433
|
+
if (!commandId && this.guild) {
|
|
434
|
+
commandId = this.guild.commands.resolveId(command);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
commandId ??= this.client.application?.commands.resolveId(command);
|
|
438
|
+
if (!commandId) {
|
|
439
|
+
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'command', 'ApplicationCommandResolvable', true);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return { guildId, commandId };
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Data that resolves to an id used for an application command permission
|
|
451
|
+
*
|
|
452
|
+
* @typedef {UserResolvable|RoleResolvable|GuildChannelResolvable|RolePermissionConstant|ChannelPermissionConstant} ApplicationCommandPermissionIdResolvable
|
|
453
|
+
*/
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { Routes } from 'discord-api-types/v10';
|
|
3
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
4
|
+
import { ApplicationEmoji } from '../structures/ApplicationEmoji.js';
|
|
5
|
+
import { resolveImage } from '../util/DataResolver.js';
|
|
6
|
+
import { CachedManager } from './CachedManager.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages API methods for ApplicationEmojis and stores their cache.
|
|
10
|
+
*
|
|
11
|
+
* @extends {CachedManager}
|
|
12
|
+
*/
|
|
13
|
+
export class ApplicationEmojiManager extends CachedManager {
|
|
14
|
+
public application: any;
|
|
15
|
+
constructor(application, iterable) {
|
|
16
|
+
super(application.client, ApplicationEmoji, iterable);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The application this manager belongs to
|
|
20
|
+
*
|
|
21
|
+
* @type {ClientApplication}
|
|
22
|
+
*/
|
|
23
|
+
this.application = application;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_add(data, cache) {
|
|
27
|
+
return super._add(data, cache, { extras: [this.application] });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Options used for creating an emoji of the application
|
|
32
|
+
*
|
|
33
|
+
* @typedef {Object} ApplicationEmojiCreateOptions
|
|
34
|
+
* @property {BufferResolvable|Base64Resolvable} attachment The image for the emoji
|
|
35
|
+
* @property {string} name The name for the emoji
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new custom emoji of the application.
|
|
40
|
+
*
|
|
41
|
+
* @param {ApplicationEmojiCreateOptions} options Options for creating the emoji
|
|
42
|
+
* @returns {Promise<Emoji>} The created emoji
|
|
43
|
+
* @example
|
|
44
|
+
* // Create a new emoji from a URL
|
|
45
|
+
* application.emojis.create({ attachment: 'https://i.imgur.com/w3duR07.png', name: 'rip' })
|
|
46
|
+
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
|
|
47
|
+
* .catch(console.error);
|
|
48
|
+
* @example
|
|
49
|
+
* // Create a new emoji from a file on your computer
|
|
50
|
+
* application.emojis.create({ attachment: './memes/banana.png', name: 'banana' })
|
|
51
|
+
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
|
|
52
|
+
* .catch(console.error);
|
|
53
|
+
*/
|
|
54
|
+
async create({ attachment, name }) {
|
|
55
|
+
const image = await resolveImage(attachment);
|
|
56
|
+
if (!image) throw new DiscordjsTypeError(ErrorCodes.ReqResourceType);
|
|
57
|
+
|
|
58
|
+
const body = { image, name };
|
|
59
|
+
|
|
60
|
+
const emoji = await this.client.rest.post(Routes.applicationEmojis(this.application.id), { body });
|
|
61
|
+
return this._add(emoji);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Obtains one or more emojis from Discord, or the emoji cache if they're already available.
|
|
66
|
+
*
|
|
67
|
+
* @param {Snowflake} [id] The emoji's id
|
|
68
|
+
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
|
69
|
+
* @returns {Promise<ApplicationEmoji|Collection<Snowflake, ApplicationEmoji>>}
|
|
70
|
+
* @example
|
|
71
|
+
* // Fetch all emojis from the application
|
|
72
|
+
* application.emojis.fetch()
|
|
73
|
+
* .then(emojis => console.log(`There are ${emojis.size} emojis.`))
|
|
74
|
+
* .catch(console.error);
|
|
75
|
+
* @example
|
|
76
|
+
* // Fetch a single emoji
|
|
77
|
+
* application.emojis.fetch('222078108977594368')
|
|
78
|
+
* .then(emoji => console.log(`The emoji name is: ${emoji.name}`))
|
|
79
|
+
* .catch(console.error);
|
|
80
|
+
*/
|
|
81
|
+
async fetch(id, { cache = true, force = false } = {}) {
|
|
82
|
+
if (id) {
|
|
83
|
+
if (!force) {
|
|
84
|
+
const existing = this.cache.get(id);
|
|
85
|
+
if (existing) return existing;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const emoji = await this.client.rest.get(Routes.applicationEmoji(this.application.id, id));
|
|
89
|
+
return this._add(emoji, cache);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { items: data } = await this.client.rest.get(Routes.applicationEmojis(this.application.id));
|
|
93
|
+
const emojis = new Collection();
|
|
94
|
+
for (const emoji of data) emojis.set(emoji.id, this._add(emoji, cache));
|
|
95
|
+
return emojis;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Deletes an emoji.
|
|
100
|
+
*
|
|
101
|
+
* @param {EmojiResolvable} emoji The Emoji resolvable to delete
|
|
102
|
+
* @returns {Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
async delete(emoji) {
|
|
105
|
+
const id = this.resolveId(emoji);
|
|
106
|
+
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
|
|
107
|
+
await this.client.rest.delete(Routes.applicationEmoji(this.application.id, id));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Edits an emoji.
|
|
112
|
+
*
|
|
113
|
+
* @param {EmojiResolvable} emoji The Emoji resolvable to edit
|
|
114
|
+
* @param {ApplicationEmojiEditOptions} options The options to provide
|
|
115
|
+
* @returns {Promise<ApplicationEmoji>}
|
|
116
|
+
*/
|
|
117
|
+
async edit(emoji, options) {
|
|
118
|
+
const id = this.resolveId(emoji);
|
|
119
|
+
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
|
|
120
|
+
|
|
121
|
+
const newData = await this.client.rest.patch(Routes.applicationEmoji(this.application.id, id), {
|
|
122
|
+
body: {
|
|
123
|
+
name: options.name,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const existing = this.cache.get(id);
|
|
127
|
+
if (existing) {
|
|
128
|
+
existing._patch(newData);
|
|
129
|
+
return existing;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this._add(newData);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Fetches the author for this emoji
|
|
137
|
+
*
|
|
138
|
+
* @param {EmojiResolvable} emoji The emoji to fetch the author of
|
|
139
|
+
* @returns {Promise<User>}
|
|
140
|
+
*/
|
|
141
|
+
async fetchAuthor(emoji) {
|
|
142
|
+
const id = this.resolveId(emoji);
|
|
143
|
+
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
|
|
144
|
+
|
|
145
|
+
const data = await this.client.rest.get(Routes.applicationEmoji(this.application.id, id));
|
|
146
|
+
|
|
147
|
+
return this._add(data).author;
|
|
148
|
+
}
|
|
149
|
+
}
|