@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,157 @@
|
|
|
1
|
+
import { Routes, type Snowflake } from 'discord-api-types/v10';
|
|
2
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
3
|
+
import { SoundboardSound } from '../structures/SoundboardSound.js';
|
|
4
|
+
import { resolveBase64, resolveFile } from '../util/DataResolver.js';
|
|
5
|
+
import { CachedManager } from './CachedManager.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Detects the MIME type of a buffer by checking its magic bytes.
|
|
9
|
+
*
|
|
10
|
+
* @param {Buffer} data The data to check
|
|
11
|
+
* @returns {string[]}
|
|
12
|
+
*/
|
|
13
|
+
export function detectAudioMime(data: Buffer): string[] {
|
|
14
|
+
if (data[0] === 0x49 && data[1] === 0x44 && data[2] === 0x33) return ['audio/mpeg']; // ID3
|
|
15
|
+
if (data[0] === 0xff && (data[1] & 0xe0) === 0xe0) return ['audio/mpeg']; // MP3 Frame
|
|
16
|
+
if (data[0] === 0x52 && data[1] === 0x49 && data[2] === 0x46 && data[3] === 0x46) return ['audio/wav']; // RIFF/WAV
|
|
17
|
+
if (data[0] === 0x4f && data[1] === 0x67 && data[2] === 0x67 && data[3] === 0x53) return ['audio/ogg']; // OggS
|
|
18
|
+
if (data[0] === 0x66 && data[1] === 0x4c && data[2] === 0x61 && data[3] === 0x43) return ['audio/flac']; // fLaC
|
|
19
|
+
return ['application/octet-stream'];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Manages API methods for Soundboard Sounds and stores their cache.
|
|
24
|
+
*
|
|
25
|
+
* @extends {CachedManager}
|
|
26
|
+
*/
|
|
27
|
+
export class GuildSoundboardSoundManager extends CachedManager {
|
|
28
|
+
public guild: any;
|
|
29
|
+
|
|
30
|
+
constructor(guild: any, iterable: any) {
|
|
31
|
+
super(guild.client, SoundboardSound, iterable);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The guild this manager belongs to
|
|
35
|
+
*
|
|
36
|
+
* @type {Guild}
|
|
37
|
+
*/
|
|
38
|
+
this.guild = guild;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override _add(data: any, cache: boolean) {
|
|
42
|
+
return super._add(data, cache, { extras: [this.guild], id: data.sound_id });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a {@link SoundboardSoundResolvable} to a {@link SoundboardSound} id.
|
|
47
|
+
*
|
|
48
|
+
* @param {any} soundboardSound The soundboard sound resolvable to resolve
|
|
49
|
+
* @returns {?Snowflake}
|
|
50
|
+
*/
|
|
51
|
+
resolveId(soundboardSound: any): Snowflake | null {
|
|
52
|
+
if (soundboardSound instanceof (this as any).holds) return (soundboardSound as any).soundId;
|
|
53
|
+
if (typeof soundboardSound === 'string') return soundboardSound;
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new guild soundboard sound.
|
|
59
|
+
*
|
|
60
|
+
* @param {any} options Options for creating a guild soundboard sound
|
|
61
|
+
* @returns {Promise<SoundboardSound>} The created soundboard sound
|
|
62
|
+
*/
|
|
63
|
+
async create({ contentType, emojiId, emojiName, file, name, reason, volume }: any): Promise<any> {
|
|
64
|
+
const resolvedFile = await resolveFile(file);
|
|
65
|
+
|
|
66
|
+
const resolvedContentType = contentType ?? resolvedFile.contentType ?? detectAudioMime(resolvedFile.data)[0];
|
|
67
|
+
|
|
68
|
+
const sound = resolveBase64(resolvedFile.data, resolvedContentType);
|
|
69
|
+
|
|
70
|
+
const body = { emoji_id: emojiId, emoji_name: emojiName, name, sound, volume };
|
|
71
|
+
|
|
72
|
+
const soundboardSound = await (this as any).client.rest.post(Routes.guildSoundboardSounds(this.guild.id), {
|
|
73
|
+
body,
|
|
74
|
+
reason,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return this._add(soundboardSound, true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Edits a soundboard sound.
|
|
82
|
+
*
|
|
83
|
+
* @param {any} soundboardSound The soundboard sound to edit
|
|
84
|
+
* @param {any} [options={}] The new data for the soundboard sound
|
|
85
|
+
* @returns {Promise<SoundboardSound>}
|
|
86
|
+
*/
|
|
87
|
+
async edit(soundboardSound: any, options: any = {}): Promise<any> {
|
|
88
|
+
const soundId = this.resolveId(soundboardSound);
|
|
89
|
+
|
|
90
|
+
if (!soundId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'soundboardSound', 'SoundboardSoundResolvable');
|
|
91
|
+
|
|
92
|
+
const { emojiId, emojiName, name, reason, volume } = options;
|
|
93
|
+
|
|
94
|
+
const body = { emoji_id: emojiId, emoji_name: emojiName, name, volume };
|
|
95
|
+
|
|
96
|
+
const data = await (this as any).client.rest.patch(Routes.guildSoundboardSound(this.guild.id, soundId), {
|
|
97
|
+
body,
|
|
98
|
+
reason,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const existing = (this as any).cache.get(soundId);
|
|
102
|
+
|
|
103
|
+
if (existing) {
|
|
104
|
+
const clone = existing._clone();
|
|
105
|
+
|
|
106
|
+
clone._patch(data);
|
|
107
|
+
return clone;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this._add(data, true);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Deletes a soundboard sound.
|
|
115
|
+
*
|
|
116
|
+
* @param {any} soundboardSound The soundboard sound to delete
|
|
117
|
+
* @param {string} [reason] Reason for deleting this soundboard sound
|
|
118
|
+
* @returns {Promise<void>}
|
|
119
|
+
*/
|
|
120
|
+
async delete(soundboardSound: any, reason: string): Promise<void> {
|
|
121
|
+
const soundId = this.resolveId(soundboardSound);
|
|
122
|
+
|
|
123
|
+
if (!soundId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'soundboardSound', 'SoundboardSoundResolvable');
|
|
124
|
+
|
|
125
|
+
await (this as any).client.rest.delete(Routes.guildSoundboardSound(this.guild.id, soundId), { reason });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Obtains one or more soundboard sounds from Discord, or the soundboard sound cache if they're already available.
|
|
130
|
+
*
|
|
131
|
+
* @param {any} [options] Options for fetching soundboard sound(s)
|
|
132
|
+
* @returns {Promise<any>}
|
|
133
|
+
*/
|
|
134
|
+
async fetch(options: any): Promise<any> {
|
|
135
|
+
if (!options) return this._fetchMany();
|
|
136
|
+
const { cache, force, soundboardSound } = options;
|
|
137
|
+
const resolvedSoundboardSound = this.resolveId(soundboardSound ?? options);
|
|
138
|
+
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });
|
|
139
|
+
return this._fetchMany({ cache });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async _fetchSingle({ cache, force, soundboardSound }: any = {}): Promise<any> {
|
|
143
|
+
if (!force) {
|
|
144
|
+
const existing = (this as any).cache.get(soundboardSound);
|
|
145
|
+
if (existing) return existing;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const data = await (this as any).client.rest.get(Routes.guildSoundboardSound(this.guild.id, soundboardSound));
|
|
149
|
+
return this._add(data, cache);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async _fetchMany({ cache }: any = {}): Promise<any> {
|
|
153
|
+
const data = await (this as any).client.rest.get(Routes.guildSoundboardSounds(this.guild.id));
|
|
154
|
+
|
|
155
|
+
return (data as any).items.reduce((coll: any, sound: any) => coll.set(sound.sound_id, this._add(sound, cache)), new (this as any).client.options.makeCache());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Collection } from '@ovencord/collection';
|
|
2
|
+
import { Routes } from 'discord-api-types/v10';
|
|
3
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
4
|
+
import { MessagePayload } from '../structures/MessagePayload.js';
|
|
5
|
+
import { Sticker } from '../structures/Sticker.js';
|
|
6
|
+
import { CachedManager } from './CachedManager.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages API methods for Guild Stickers and stores their cache.
|
|
10
|
+
*
|
|
11
|
+
* @extends {CachedManager}
|
|
12
|
+
*/
|
|
13
|
+
export class GuildStickerManager extends CachedManager {
|
|
14
|
+
public guild: any;
|
|
15
|
+
constructor(guild, iterable) {
|
|
16
|
+
super(guild.client, Sticker, iterable);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The guild this manager belongs to
|
|
20
|
+
*
|
|
21
|
+
* @type {Guild}
|
|
22
|
+
*/
|
|
23
|
+
this.guild = guild;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The cache of Guild Stickers
|
|
28
|
+
*
|
|
29
|
+
* @type {Collection<Snowflake, Sticker>}
|
|
30
|
+
* @name GuildStickerManager#cache
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
_add(data, cache) {
|
|
34
|
+
return super._add(data, cache, { extras: [this.guild] });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options used to create a guild sticker.
|
|
39
|
+
*
|
|
40
|
+
* @typedef {Object} GuildStickerCreateOptions
|
|
41
|
+
* @property {AttachmentPayload|BufferResolvable|Stream} file The file for the sticker
|
|
42
|
+
* @property {string} name The name for the sticker
|
|
43
|
+
* @property {string} tags The Discord name of a unicode emoji representing the sticker's expression
|
|
44
|
+
* @property {?string} [description] The description for the sticker
|
|
45
|
+
* @property {string} [reason] Reason for creating the sticker
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new custom sticker in the guild.
|
|
50
|
+
*
|
|
51
|
+
* @param {GuildStickerCreateOptions} options Options for creating a guild sticker
|
|
52
|
+
* @returns {Promise<Sticker>} The created sticker
|
|
53
|
+
* @example
|
|
54
|
+
* // Create a new sticker from a URL
|
|
55
|
+
* guild.stickers.create({ file: 'https://i.imgur.com/w3duR07.png', name: 'rip', tags: 'headstone' })
|
|
56
|
+
* .then(sticker => console.log(`Created new sticker with name ${sticker.name}!`))
|
|
57
|
+
* .catch(console.error);
|
|
58
|
+
* @example
|
|
59
|
+
* // Create a new sticker from a file on your computer
|
|
60
|
+
* guild.stickers.create({ file: './memes/banana.png', name: 'banana', tags: 'banana' })
|
|
61
|
+
* .then(sticker => console.log(`Created new sticker with name ${sticker.name}!`))
|
|
62
|
+
* .catch(console.error);
|
|
63
|
+
*/
|
|
64
|
+
async create({ file, name, tags, description, reason } = {}) {
|
|
65
|
+
const resolvedFile = await MessagePayload.resolveFile(file);
|
|
66
|
+
resolvedFile.key = 'file';
|
|
67
|
+
|
|
68
|
+
const body = { name, tags, description: description ?? '' };
|
|
69
|
+
|
|
70
|
+
const sticker = await this.client.rest.post(Routes.guildStickers(this.guild.id), {
|
|
71
|
+
appendToFormData: true,
|
|
72
|
+
body,
|
|
73
|
+
files: [resolvedFile],
|
|
74
|
+
reason,
|
|
75
|
+
});
|
|
76
|
+
return this.client.actions.GuildStickerCreate.handle(this.guild, sticker).sticker;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Data that resolves to give a Sticker object. This can be:
|
|
81
|
+
* - A Sticker object
|
|
82
|
+
* - A Snowflake
|
|
83
|
+
*
|
|
84
|
+
* @typedef {Sticker|Snowflake} StickerResolvable
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Resolves a StickerResolvable to a Sticker object.
|
|
89
|
+
*
|
|
90
|
+
* @method resolve
|
|
91
|
+
* @memberof GuildStickerManager
|
|
92
|
+
* @instance
|
|
93
|
+
* @param {StickerResolvable} sticker The Sticker resolvable to identify
|
|
94
|
+
* @returns {?Sticker}
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolves a StickerResolvable to a Sticker id string.
|
|
99
|
+
*
|
|
100
|
+
* @method resolveId
|
|
101
|
+
* @memberof GuildStickerManager
|
|
102
|
+
* @instance
|
|
103
|
+
* @param {StickerResolvable} sticker The Sticker resolvable to identify
|
|
104
|
+
* @returns {?Snowflake}
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Edits a sticker.
|
|
109
|
+
*
|
|
110
|
+
* @param {StickerResolvable} sticker The sticker to edit
|
|
111
|
+
* @param {GuildStickerEditOptions} [options={}] The new data for the sticker
|
|
112
|
+
* @returns {Promise<Sticker>}
|
|
113
|
+
*/
|
|
114
|
+
async edit(sticker, options = {}) {
|
|
115
|
+
const stickerId = this.resolveId(sticker);
|
|
116
|
+
if (!stickerId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sticker', 'StickerResolvable');
|
|
117
|
+
|
|
118
|
+
const data = await this.client.rest.patch(Routes.guildSticker(this.guild.id, stickerId), {
|
|
119
|
+
body: options,
|
|
120
|
+
reason: options.reason,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const existing = this.cache.get(stickerId);
|
|
124
|
+
if (existing) {
|
|
125
|
+
const clone = existing._clone();
|
|
126
|
+
clone._patch(data);
|
|
127
|
+
return clone;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this._add(data);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Deletes a sticker.
|
|
135
|
+
*
|
|
136
|
+
* @param {StickerResolvable} sticker The sticker to delete
|
|
137
|
+
* @param {string} [reason] Reason for deleting this sticker
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*/
|
|
140
|
+
async delete(sticker, reason) {
|
|
141
|
+
const resolvedStickerId = this.resolveId(sticker);
|
|
142
|
+
if (!resolvedStickerId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sticker', 'StickerResolvable');
|
|
143
|
+
|
|
144
|
+
await this.client.rest.delete(Routes.guildSticker(this.guild.id, resolvedStickerId), { reason });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Obtains one or more stickers from Discord, or the sticker cache if they're already available.
|
|
149
|
+
*
|
|
150
|
+
* @param {Snowflake} [id] The Sticker's id
|
|
151
|
+
* @param {BaseFetchOptions} [options] Additional options for this fetch
|
|
152
|
+
* @returns {Promise<Sticker|Collection<Snowflake, Sticker>>}
|
|
153
|
+
* @example
|
|
154
|
+
* // Fetch all stickers from the guild
|
|
155
|
+
* message.guild.stickers.fetch()
|
|
156
|
+
* .then(stickers => console.log(`There are ${stickers.size} stickers.`))
|
|
157
|
+
* .catch(console.error);
|
|
158
|
+
* @example
|
|
159
|
+
* // Fetch a single sticker
|
|
160
|
+
* message.guild.stickers.fetch('222078108977594368')
|
|
161
|
+
* .then(sticker => console.log(`The sticker name is: ${sticker.name}`))
|
|
162
|
+
* .catch(console.error);
|
|
163
|
+
*/
|
|
164
|
+
async fetch(id, { cache = true, force = false } = {}) {
|
|
165
|
+
if (id) {
|
|
166
|
+
if (!force) {
|
|
167
|
+
const existing = this.cache.get(id);
|
|
168
|
+
if (existing) return existing;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const sticker = await this.client.rest.get(Routes.guildSticker(this.guild.id, id));
|
|
172
|
+
return this._add(sticker, cache);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const data = await this.client.rest.get(Routes.guildStickers(this.guild.id));
|
|
176
|
+
return new Collection(data.map(sticker => [sticker.id, this._add(sticker, cache)]));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Fetches the user who uploaded this sticker, if this is a guild sticker.
|
|
181
|
+
*
|
|
182
|
+
* @param {StickerResolvable} sticker The sticker to fetch the user for
|
|
183
|
+
* @returns {Promise<?User>}
|
|
184
|
+
*/
|
|
185
|
+
async fetchUser(sticker) {
|
|
186
|
+
const resolvedSticker = this.resolve(sticker);
|
|
187
|
+
if (!resolvedSticker) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sticker', 'StickerResolvable');
|
|
188
|
+
const data = await this.client.rest.get(Routes.guildSticker(this.guild.id, resolvedSticker.id));
|
|
189
|
+
resolvedSticker._patch(data);
|
|
190
|
+
return resolvedSticker.user;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ChannelType, Routes } from 'discord-api-types/v10';
|
|
2
|
+
import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
|
|
3
|
+
import { ThreadManager } from './ThreadManager.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
|
|
7
|
+
*
|
|
8
|
+
* @extends {ThreadManager}
|
|
9
|
+
*/
|
|
10
|
+
export class GuildTextThreadManager extends ThreadManager {
|
|
11
|
+
/**
|
|
12
|
+
* The channel this Manager belongs to
|
|
13
|
+
*
|
|
14
|
+
* @name GuildTextThreadManager#channel
|
|
15
|
+
* @type {TextChannel|AnnouncementChannel}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for creating a thread. <warn>Only one of `startMessage` or `type` can be defined.</warn>
|
|
20
|
+
*
|
|
21
|
+
* @typedef {StartThreadOptions} GuildTextThreadCreateOptions
|
|
22
|
+
* @property {MessageResolvable} [startMessage] The message to start a thread from.
|
|
23
|
+
* <warn>If this is defined, then the `type` of thread gets inferred automatically and cannot be changed.</warn>
|
|
24
|
+
* @property {ThreadChannelTypes} [type] The type of thread to create.
|
|
25
|
+
* Defaults to {@link ChannelType.PublicThread} if created in a {@link TextChannel}
|
|
26
|
+
* <warn>When creating threads in a {@link AnnouncementChannel}, this is ignored and is always
|
|
27
|
+
* {@link ChannelType.AnnouncementThread}</warn>
|
|
28
|
+
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to the thread
|
|
29
|
+
* <info>Can only be set when type will be {@link ChannelType.PrivateThread}</info>
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new thread in the channel.
|
|
34
|
+
*
|
|
35
|
+
* @param {GuildTextThreadCreateOptions} [options] Options to create a new thread
|
|
36
|
+
* @returns {Promise<ThreadChannel>}
|
|
37
|
+
* @example
|
|
38
|
+
* // Create a new public thread
|
|
39
|
+
* channel.threads
|
|
40
|
+
* .create({
|
|
41
|
+
* name: 'food-talk',
|
|
42
|
+
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
|
43
|
+
* reason: 'Needed a separate thread for food',
|
|
44
|
+
* })
|
|
45
|
+
* .then(threadChannel => console.log(threadChannel))
|
|
46
|
+
* .catch(console.error);
|
|
47
|
+
* @example
|
|
48
|
+
* // Create a new private thread
|
|
49
|
+
* channel.threads
|
|
50
|
+
* .create({
|
|
51
|
+
* name: 'mod-talk',
|
|
52
|
+
* autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
|
53
|
+
* type: ChannelType.PrivateThread,
|
|
54
|
+
* reason: 'Needed a separate thread for moderation',
|
|
55
|
+
* })
|
|
56
|
+
* .then(threadChannel => console.log(threadChannel))
|
|
57
|
+
* .catch(console.error);
|
|
58
|
+
*/
|
|
59
|
+
async create({
|
|
60
|
+
name,
|
|
61
|
+
autoArchiveDuration = this.channel.defaultAutoArchiveDuration,
|
|
62
|
+
startMessage,
|
|
63
|
+
type,
|
|
64
|
+
invitable,
|
|
65
|
+
reason,
|
|
66
|
+
rateLimitPerUser,
|
|
67
|
+
} = {}) {
|
|
68
|
+
let resolvedType =
|
|
69
|
+
this.channel.type === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread;
|
|
70
|
+
let startMessageId;
|
|
71
|
+
if (startMessage) {
|
|
72
|
+
startMessageId = this.channel.messages.resolveId(startMessage);
|
|
73
|
+
if (!startMessageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'startMessage', 'MessageResolvable');
|
|
74
|
+
} else if (this.channel.type !== ChannelType.GuildAnnouncement) {
|
|
75
|
+
resolvedType = type ?? resolvedType;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const data = await this.client.rest.post(Routes.threads(this.channel.id, startMessageId), {
|
|
79
|
+
body: {
|
|
80
|
+
name,
|
|
81
|
+
auto_archive_duration: autoArchiveDuration,
|
|
82
|
+
type: resolvedType,
|
|
83
|
+
invitable: resolvedType === ChannelType.PrivateThread ? invitable : undefined,
|
|
84
|
+
rate_limit_per_user: rateLimitPerUser,
|
|
85
|
+
},
|
|
86
|
+
reason,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return this.client.actions.ThreadCreate.handle(data).thread;
|
|
90
|
+
}
|
|
91
|
+
}
|