@velliajs/discord 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +133 -0
- package/package.json +82 -0
- package/src/client/BaseClient.js +83 -0
- package/src/client/Client.js +591 -0
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +119 -0
- package/src/client/actions/ActionsManager.js +79 -0
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +26 -0
- package/src/client/actions/AutoModerationRuleCreate.js +27 -0
- package/src/client/actions/AutoModerationRuleDelete.js +31 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +29 -0
- package/src/client/actions/ChannelCreate.js +23 -0
- package/src/client/actions/ChannelDelete.js +23 -0
- package/src/client/actions/ChannelUpdate.js +33 -0
- package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
- package/src/client/actions/GuildBanAdd.js +20 -0
- package/src/client/actions/GuildBanRemove.js +25 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
- package/src/client/actions/GuildDelete.js +44 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +19 -0
- package/src/client/actions/GuildEmojiUpdate.js +20 -0
- package/src/client/actions/GuildEmojisUpdate.js +34 -0
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +31 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +29 -0
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +31 -0
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
- package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
- package/src/client/actions/GuildStickerCreate.js +20 -0
- package/src/client/actions/GuildStickerDelete.js +19 -0
- package/src/client/actions/GuildStickerUpdate.js +20 -0
- package/src/client/actions/GuildStickersUpdate.js +34 -0
- package/src/client/actions/GuildUpdate.js +33 -0
- package/src/client/actions/InteractionCreate.js +101 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +37 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +47 -0
- package/src/client/actions/MessageReactionAdd.js +55 -0
- package/src/client/actions/MessageReactionRemove.js +45 -0
- package/src/client/actions/MessageReactionRemoveAll.js +33 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
- package/src/client/actions/MessageUpdate.js +26 -0
- package/src/client/actions/PresenceUpdate.js +42 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +31 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +26 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +47 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +36 -0
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +44 -0
- package/src/client/websocket/WebSocketManager.js +393 -0
- package/src/client/websocket/WebSocketShard.js +231 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_CREATE.js +26 -0
- package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/READY.js +27 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +64 -0
- package/src/errors/DJSError.js +48 -0
- package/src/errors/ErrorCodes.js +319 -0
- package/src/errors/Messages.js +170 -0
- package/src/errors/index.js +5 -0
- package/src/index.js +213 -0
- package/src/managers/ApplicationCommandManager.js +263 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +434 -0
- package/src/managers/AutoModerationRuleManager.js +288 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/CachedManager.js +57 -0
- package/src/managers/CategoryChannelChildManager.js +77 -0
- package/src/managers/ChannelManager.js +128 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +494 -0
- package/src/managers/GuildEmojiManager.js +174 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +83 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +283 -0
- package/src/managers/GuildMemberManager.js +540 -0
- package/src/managers/GuildMemberRoleManager.js +204 -0
- package/src/managers/GuildScheduledEventManager.js +297 -0
- package/src/managers/GuildStickerManager.js +182 -0
- package/src/managers/GuildTextThreadManager.js +91 -0
- package/src/managers/MessageManager.js +259 -0
- package/src/managers/PermissionOverwriteManager.js +168 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +68 -0
- package/src/managers/ReactionUserManager.js +77 -0
- package/src/managers/RoleManager.js +360 -0
- package/src/managers/StageInstanceManager.js +154 -0
- package/src/managers/ThreadManager.js +204 -0
- package/src/managers/ThreadMemberManager.js +182 -0
- package/src/managers/UserManager.js +139 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/sharding/Shard.js +457 -0
- package/src/sharding/ShardClientUtil.js +285 -0
- package/src/sharding/ShardingManager.js +326 -0
- package/src/structures/ActionRow.js +46 -0
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +97 -0
- package/src/structures/ApplicationCommand.js +606 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +46 -0
- package/src/structures/Attachment.js +140 -0
- package/src/structures/AttachmentBuilder.js +116 -0
- package/src/structures/AutoModerationActionExecution.js +116 -0
- package/src/structures/AutoModerationRule.js +284 -0
- package/src/structures/AutocompleteInteraction.js +97 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseChannel.js +160 -0
- package/src/structures/BaseGuild.js +119 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +186 -0
- package/src/structures/BaseGuildVoiceChannel.js +234 -0
- package/src/structures/BaseInteraction.js +344 -0
- package/src/structures/BaseSelectMenuComponent.js +56 -0
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +65 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CategoryChannel.js +45 -0
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +20 -0
- package/src/structures/ChannelSelectMenuInteraction.js +33 -0
- package/src/structures/ChatInputCommandInteraction.js +41 -0
- package/src/structures/ClientApplication.js +193 -0
- package/src/structures/ClientPresence.js +82 -0
- package/src/structures/ClientUser.js +185 -0
- package/src/structures/CommandInteraction.js +224 -0
- package/src/structures/CommandInteractionOptionResolver.js +308 -0
- package/src/structures/Component.js +47 -0
- package/src/structures/ContextMenuCommandInteraction.js +64 -0
- package/src/structures/DMChannel.js +129 -0
- package/src/structures/DirectoryChannel.js +36 -0
- package/src/structures/Embed.js +220 -0
- package/src/structures/EmbedBuilder.js +41 -0
- package/src/structures/Emoji.js +108 -0
- package/src/structures/ForumChannel.js +264 -0
- package/src/structures/Guild.js +1361 -0
- package/src/structures/GuildAuditLogs.js +91 -0
- package/src/structures/GuildAuditLogsEntry.js +527 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildChannel.js +457 -0
- package/src/structures/GuildEmoji.js +148 -0
- package/src/structures/GuildMember.js +518 -0
- package/src/structures/GuildPreview.js +193 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +439 -0
- package/src/structures/GuildTemplate.js +241 -0
- package/src/structures/Integration.js +220 -0
- package/src/structures/IntegrationApplication.js +85 -0
- package/src/structures/InteractionCollector.js +263 -0
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +59 -0
- package/src/structures/Invite.js +322 -0
- package/src/structures/InviteGuild.js +22 -0
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +11 -0
- package/src/structures/MentionableSelectMenuInteraction.js +71 -0
- package/src/structures/Message.js +997 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +107 -0
- package/src/structures/MessageContextMenuCommandInteraction.js +20 -0
- package/src/structures/MessageMentions.js +297 -0
- package/src/structures/MessagePayload.js +299 -0
- package/src/structures/MessageReaction.js +142 -0
- package/src/structures/ModalBuilder.js +34 -0
- package/src/structures/ModalSubmitFields.js +55 -0
- package/src/structures/ModalSubmitInteraction.js +121 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +60 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +372 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +458 -0
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +11 -0
- package/src/structures/RoleSelectMenuInteraction.js +33 -0
- package/src/structures/SelectMenuBuilder.js +26 -0
- package/src/structures/SelectMenuComponent.js +26 -0
- package/src/structures/SelectMenuInteraction.js +26 -0
- package/src/structures/SelectMenuOptionBuilder.js +26 -0
- package/src/structures/StageChannel.js +112 -0
- package/src/structures/StageInstance.js +167 -0
- package/src/structures/Sticker.js +272 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +20 -0
- package/src/structures/StringSelectMenuInteraction.js +21 -0
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Team.js +117 -0
- package/src/structures/TeamMember.js +70 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +29 -0
- package/src/structures/ThreadChannel.js +606 -0
- package/src/structures/ThreadMember.js +113 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +331 -0
- package/src/structures/UserContextMenuCommandInteraction.js +29 -0
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +11 -0
- package/src/structures/UserSelectMenuInteraction.js +51 -0
- package/src/structures/VoiceChannel.js +96 -0
- package/src/structures/VoiceRegion.js +46 -0
- package/src/structures/VoiceState.js +303 -0
- package/src/structures/Webhook.js +481 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +49 -0
- package/src/structures/Widget.js +88 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +108 -0
- package/src/structures/interfaces/Collector.js +335 -0
- package/src/structures/interfaces/InteractionResponses.js +320 -0
- package/src/structures/interfaces/TextBasedChannel.js +413 -0
- package/src/util/APITypes.js +456 -0
- package/src/util/ActivityFlagsBitField.js +26 -0
- package/src/util/ApplicationFlagsBitField.js +26 -0
- package/src/util/BitField.js +176 -0
- package/src/util/ChannelFlagsBitField.js +41 -0
- package/src/util/Channels.js +150 -0
- package/src/util/Colors.js +73 -0
- package/src/util/Components.js +152 -0
- package/src/util/Constants.js +230 -0
- package/src/util/DataResolver.js +140 -0
- package/src/util/Enums.js +13 -0
- package/src/util/Events.js +160 -0
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +41 -0
- package/src/util/IntentsBitField.js +34 -0
- package/src/util/LimitedCollection.js +68 -0
- package/src/util/MessageFlagsBitField.js +32 -0
- package/src/util/Options.js +216 -0
- package/src/util/Partials.js +44 -0
- package/src/util/PermissionsBitField.js +104 -0
- package/src/util/ShardEvents.js +27 -0
- package/src/util/Status.js +33 -0
- package/src/util/Sweepers.js +467 -0
- package/src/util/SystemChannelFlagsBitField.js +43 -0
- package/src/util/ThreadMemberFlagsBitField.js +31 -0
- package/src/util/Transformers.js +36 -0
- package/src/util/UserFlagsBitField.js +32 -0
- package/src/util/Util.js +394 -0
- package/src/util/WebSocketShardEvents.js +25 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
4
|
+
const { lazy } = require('@discordjs/util');
|
|
5
|
+
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
|
6
|
+
const { Routes, WebhookType } = require('discord-api-types/v10');
|
|
7
|
+
const MessagePayload = require('./MessagePayload');
|
|
8
|
+
const { DiscordjsError, ErrorCodes } = require('../errors');
|
|
9
|
+
const DataResolver = require('../util/DataResolver');
|
|
10
|
+
|
|
11
|
+
const getMessage = lazy(() => require('./Message').Message);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents a webhook.
|
|
15
|
+
*/
|
|
16
|
+
class Webhook {
|
|
17
|
+
constructor(client, data) {
|
|
18
|
+
/**
|
|
19
|
+
* The client that instantiated the webhook
|
|
20
|
+
* @name Webhook#client
|
|
21
|
+
* @type {Client}
|
|
22
|
+
* @readonly
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
25
|
+
if (data) this._patch(data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_patch(data) {
|
|
29
|
+
if ('name' in data) {
|
|
30
|
+
/**
|
|
31
|
+
* The name of the webhook
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
this.name = data.name;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The token for the webhook, unavailable for follower webhooks and webhooks owned by another application.
|
|
39
|
+
* @name Webhook#token
|
|
40
|
+
* @type {?string}
|
|
41
|
+
*/
|
|
42
|
+
Object.defineProperty(this, 'token', {
|
|
43
|
+
value: data.token ?? null,
|
|
44
|
+
writable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if ('avatar' in data) {
|
|
49
|
+
/**
|
|
50
|
+
* The avatar for the webhook
|
|
51
|
+
* @type {?string}
|
|
52
|
+
*/
|
|
53
|
+
this.avatar = data.avatar;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The webhook's id
|
|
58
|
+
* @type {Snowflake}
|
|
59
|
+
*/
|
|
60
|
+
this.id = data.id;
|
|
61
|
+
|
|
62
|
+
if ('type' in data) {
|
|
63
|
+
/**
|
|
64
|
+
* The type of the webhook
|
|
65
|
+
* @type {WebhookType}
|
|
66
|
+
*/
|
|
67
|
+
this.type = data.type;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ('guild_id' in data) {
|
|
71
|
+
/**
|
|
72
|
+
* The guild the webhook belongs to
|
|
73
|
+
* @type {Snowflake}
|
|
74
|
+
*/
|
|
75
|
+
this.guildId = data.guild_id;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if ('channel_id' in data) {
|
|
79
|
+
/**
|
|
80
|
+
* The id of the channel the webhook belongs to
|
|
81
|
+
* @type {Snowflake}
|
|
82
|
+
*/
|
|
83
|
+
this.channelId = data.channel_id;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ('user' in data) {
|
|
87
|
+
/**
|
|
88
|
+
* The owner of the webhook
|
|
89
|
+
* @type {?(User|APIUser)}
|
|
90
|
+
*/
|
|
91
|
+
this.owner = this.client.users?._add(data.user) ?? data.user;
|
|
92
|
+
} else {
|
|
93
|
+
this.owner ??= null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ('application_id' in data) {
|
|
97
|
+
/**
|
|
98
|
+
* The application that created this webhook
|
|
99
|
+
* @type {?Snowflake}
|
|
100
|
+
*/
|
|
101
|
+
this.applicationId = data.application_id;
|
|
102
|
+
} else {
|
|
103
|
+
this.applicationId ??= null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if ('source_guild' in data) {
|
|
107
|
+
/**
|
|
108
|
+
* The source guild of the webhook
|
|
109
|
+
* @type {?(Guild|APIGuild)}
|
|
110
|
+
*/
|
|
111
|
+
this.sourceGuild = this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
|
|
112
|
+
} else {
|
|
113
|
+
this.sourceGuild ??= null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if ('source_channel' in data) {
|
|
117
|
+
/**
|
|
118
|
+
* The source channel of the webhook
|
|
119
|
+
* @type {?(NewsChannel|APIChannel)}
|
|
120
|
+
*/
|
|
121
|
+
this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
|
|
122
|
+
} else {
|
|
123
|
+
this.sourceChannel ??= null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Options that can be passed into send.
|
|
129
|
+
* @typedef {BaseMessageOptions} WebhookMessageCreateOptions
|
|
130
|
+
* @property {boolean} [tts=false] Whether the message should be spoken aloud
|
|
131
|
+
* @property {MessageFlags} [flags] Which flags to set for the message.
|
|
132
|
+
* <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be set.</info>
|
|
133
|
+
* @property {string} [username=this.name] Username override for the message
|
|
134
|
+
* @property {string} [avatarURL] Avatar URL override for the message
|
|
135
|
+
* @property {Snowflake} [threadId] The id of the thread in the channel to send to.
|
|
136
|
+
* <info>For interaction webhooks, this property is ignored</info>
|
|
137
|
+
* @property {string} [threadName] Name of the thread to create (only available if webhook is in a forum channel)
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Options that can be passed into editMessage.
|
|
142
|
+
* @typedef {BaseMessageOptions} WebhookMessageEditOptions
|
|
143
|
+
* @property {Attachment[]} [attachments] Attachments to send with the message
|
|
144
|
+
* @property {Snowflake} [threadId] The id of the thread this message belongs to
|
|
145
|
+
* <info>For interaction webhooks, this property is ignored</info>
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The channel the webhook belongs to
|
|
150
|
+
* @type {?(TextChannel|VoiceChannel|StageChannel|NewsChannel|ForumChannel)}
|
|
151
|
+
* @readonly
|
|
152
|
+
*/
|
|
153
|
+
get channel() {
|
|
154
|
+
return this.client.channels.resolve(this.channelId);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sends a message with this webhook.
|
|
159
|
+
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The options to provide
|
|
160
|
+
* @returns {Promise<Message>}
|
|
161
|
+
* @example
|
|
162
|
+
* // Send a basic message
|
|
163
|
+
* webhook.send('hello!')
|
|
164
|
+
* .then(message => console.log(`Sent message: ${message.content}`))
|
|
165
|
+
* .catch(console.error);
|
|
166
|
+
* @example
|
|
167
|
+
* // Send a basic message in a thread
|
|
168
|
+
* webhook.send({ content: 'hello!', threadId: '836856309672348295' })
|
|
169
|
+
* .then(message => console.log(`Sent message: ${message.content}`))
|
|
170
|
+
* .catch(console.error);
|
|
171
|
+
* @example
|
|
172
|
+
* // Send a remote file
|
|
173
|
+
* webhook.send({
|
|
174
|
+
* files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
|
|
175
|
+
* })
|
|
176
|
+
* .then(console.log)
|
|
177
|
+
* .catch(console.error);
|
|
178
|
+
* @example
|
|
179
|
+
* // Send a local file
|
|
180
|
+
* webhook.send({
|
|
181
|
+
* files: [{
|
|
182
|
+
* attachment: 'entire/path/to/file.jpg',
|
|
183
|
+
* name: 'file.jpg'
|
|
184
|
+
* }]
|
|
185
|
+
* })
|
|
186
|
+
* .then(console.log)
|
|
187
|
+
* .catch(console.error);
|
|
188
|
+
* @example
|
|
189
|
+
* // Send an embed with a local image inside
|
|
190
|
+
* webhook.send({
|
|
191
|
+
* content: 'This is an embed',
|
|
192
|
+
* embeds: [{
|
|
193
|
+
* thumbnail: {
|
|
194
|
+
* url: 'attachment://file.jpg'
|
|
195
|
+
* }
|
|
196
|
+
* }],
|
|
197
|
+
* files: [{
|
|
198
|
+
* attachment: 'entire/path/to/file.jpg',
|
|
199
|
+
* name: 'file.jpg'
|
|
200
|
+
* }]
|
|
201
|
+
* })
|
|
202
|
+
* .then(console.log)
|
|
203
|
+
* .catch(console.error);
|
|
204
|
+
*/
|
|
205
|
+
async send(options) {
|
|
206
|
+
if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
|
|
207
|
+
|
|
208
|
+
let messagePayload;
|
|
209
|
+
|
|
210
|
+
if (options instanceof MessagePayload) {
|
|
211
|
+
messagePayload = options.resolveBody();
|
|
212
|
+
} else {
|
|
213
|
+
messagePayload = MessagePayload.create(this, options).resolveBody();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const query = makeURLSearchParams({
|
|
217
|
+
wait: true,
|
|
218
|
+
thread_id: messagePayload.options.threadId,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const { body, files } = await messagePayload.resolveFiles();
|
|
222
|
+
const d = await this.client.rest.post(Routes.webhook(this.id, this.token), {
|
|
223
|
+
body,
|
|
224
|
+
files,
|
|
225
|
+
query,
|
|
226
|
+
auth: false,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
if (!this.client.channels) return d;
|
|
230
|
+
return this.client.channels.cache.get(d.channel_id)?.messages._add(d, false) ?? new (getMessage())(this.client, d);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Sends a raw slack message with this webhook.
|
|
235
|
+
* @param {Object} body The raw body to send
|
|
236
|
+
* @returns {Promise<boolean>}
|
|
237
|
+
* @example
|
|
238
|
+
* // Send a slack message
|
|
239
|
+
* webhook.sendSlackMessage({
|
|
240
|
+
* 'username': 'Wumpus',
|
|
241
|
+
* 'attachments': [{
|
|
242
|
+
* 'pretext': 'this looks pretty cool',
|
|
243
|
+
* 'color': '#F0F',
|
|
244
|
+
* 'footer_icon': 'http://snek.s3.amazonaws.com/topSnek.png',
|
|
245
|
+
* 'footer': 'Powered by sneks',
|
|
246
|
+
* 'ts': Date.now() / 1_000
|
|
247
|
+
* }]
|
|
248
|
+
* }).catch(console.error);
|
|
249
|
+
* @see {@link https://api.slack.com/messaging/webhooks}
|
|
250
|
+
*/
|
|
251
|
+
async sendSlackMessage(body) {
|
|
252
|
+
if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
|
|
253
|
+
|
|
254
|
+
const data = await this.client.rest.post(Routes.webhookPlatform(this.id, this.token, 'slack'), {
|
|
255
|
+
query: makeURLSearchParams({ wait: true }),
|
|
256
|
+
auth: false,
|
|
257
|
+
body,
|
|
258
|
+
});
|
|
259
|
+
return data.toString() === 'ok';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Options used to edit a {@link Webhook}.
|
|
264
|
+
* @typedef {Object} WebhookEditOptions
|
|
265
|
+
* @property {string} [name=this.name] The new name for the webhook
|
|
266
|
+
* @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
|
|
267
|
+
* @property {GuildTextChannelResolvable} [channel] The new channel for the webhook
|
|
268
|
+
* @property {string} [reason] Reason for editing the webhook
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Edits this webhook.
|
|
273
|
+
* @param {WebhookEditOptions} options Options for editing the webhook
|
|
274
|
+
* @returns {Promise<Webhook>}
|
|
275
|
+
*/
|
|
276
|
+
async edit({ name = this.name, avatar, channel, reason }) {
|
|
277
|
+
if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
|
|
278
|
+
avatar = await DataResolver.resolveImage(avatar);
|
|
279
|
+
}
|
|
280
|
+
channel &&= channel.id ?? channel;
|
|
281
|
+
const data = await this.client.rest.patch(Routes.webhook(this.id, channel ? undefined : this.token), {
|
|
282
|
+
body: { name, avatar, channel_id: channel },
|
|
283
|
+
reason,
|
|
284
|
+
auth: !this.token || Boolean(channel),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
this.name = data.name;
|
|
288
|
+
this.avatar = data.avatar;
|
|
289
|
+
this.channelId = data.channel_id;
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Options that can be passed into fetchMessage.
|
|
295
|
+
* @typedef {options} WebhookFetchMessageOptions
|
|
296
|
+
* @property {boolean} [cache=true] Whether to cache the message.
|
|
297
|
+
* @property {Snowflake} [threadId] The id of the thread this message belongs to.
|
|
298
|
+
* <info>For interaction webhooks, this property is ignored</info>
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Gets a message that was sent by this webhook.
|
|
303
|
+
* @param {Snowflake|'@original'} message The id of the message to fetch
|
|
304
|
+
* @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
|
|
305
|
+
* @returns {Promise<Message>} Returns the message sent by this webhook
|
|
306
|
+
*/
|
|
307
|
+
async fetchMessage(message, { threadId } = {}) {
|
|
308
|
+
if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
|
|
309
|
+
|
|
310
|
+
const data = await this.client.rest.get(Routes.webhookMessage(this.id, this.token, message), {
|
|
311
|
+
query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
|
|
312
|
+
auth: false,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
if (!this.client.channels) return data;
|
|
316
|
+
return (
|
|
317
|
+
this.client.channels.cache.get(data.channel_id)?.messages._add(data, false) ??
|
|
318
|
+
new (getMessage())(this.client, data)
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Edits a message that was sent by this webhook.
|
|
324
|
+
* @param {MessageResolvable|'@original'} message The message to edit
|
|
325
|
+
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
|
326
|
+
* @returns {Promise<Message>} Returns the message edited by this webhook
|
|
327
|
+
*/
|
|
328
|
+
async editMessage(message, options) {
|
|
329
|
+
if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
|
|
330
|
+
|
|
331
|
+
let messagePayload;
|
|
332
|
+
|
|
333
|
+
if (options instanceof MessagePayload) messagePayload = options;
|
|
334
|
+
else messagePayload = MessagePayload.create(this, options);
|
|
335
|
+
|
|
336
|
+
const { body, files } = await messagePayload.resolveBody().resolveFiles();
|
|
337
|
+
|
|
338
|
+
const d = await this.client.rest.patch(
|
|
339
|
+
Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
|
|
340
|
+
{
|
|
341
|
+
body,
|
|
342
|
+
files,
|
|
343
|
+
query: messagePayload.options.threadId
|
|
344
|
+
? makeURLSearchParams({ thread_id: messagePayload.options.threadId })
|
|
345
|
+
: undefined,
|
|
346
|
+
auth: false,
|
|
347
|
+
},
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
const channelManager = this.client.channels;
|
|
351
|
+
if (!channelManager) return d;
|
|
352
|
+
|
|
353
|
+
const messageManager = channelManager.cache.get(d.channel_id)?.messages;
|
|
354
|
+
if (!messageManager) return new (getMessage())(this.client, d);
|
|
355
|
+
|
|
356
|
+
const existing = messageManager.cache.get(d.id);
|
|
357
|
+
if (!existing) return messageManager._add(d);
|
|
358
|
+
|
|
359
|
+
const clone = existing._clone();
|
|
360
|
+
clone._patch(d);
|
|
361
|
+
return clone;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Deletes the webhook.
|
|
366
|
+
* @param {string} [reason] Reason for deleting this webhook
|
|
367
|
+
* @returns {Promise<void>}
|
|
368
|
+
*/
|
|
369
|
+
async delete(reason) {
|
|
370
|
+
await this.client.rest.delete(Routes.webhook(this.id, this.token), {
|
|
371
|
+
reason,
|
|
372
|
+
auth: !this.token,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Delete a message that was sent by this webhook.
|
|
378
|
+
* @param {MessageResolvable|'@original'} message The message to delete
|
|
379
|
+
* @param {Snowflake} [threadId] The id of the thread this message belongs to
|
|
380
|
+
* @returns {Promise<void>}
|
|
381
|
+
*/
|
|
382
|
+
async deleteMessage(message, threadId) {
|
|
383
|
+
if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
|
|
384
|
+
|
|
385
|
+
await this.client.rest.delete(
|
|
386
|
+
Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
|
|
387
|
+
{
|
|
388
|
+
query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
|
|
389
|
+
auth: false,
|
|
390
|
+
},
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The timestamp the webhook was created at
|
|
396
|
+
* @type {number}
|
|
397
|
+
* @readonly
|
|
398
|
+
*/
|
|
399
|
+
get createdTimestamp() {
|
|
400
|
+
return DiscordSnowflake.timestampFrom(this.id);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* The time the webhook was created at
|
|
405
|
+
* @type {Date}
|
|
406
|
+
* @readonly
|
|
407
|
+
*/
|
|
408
|
+
get createdAt() {
|
|
409
|
+
return new Date(this.createdTimestamp);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* The URL of this webhook
|
|
414
|
+
* @type {string}
|
|
415
|
+
* @readonly
|
|
416
|
+
*/
|
|
417
|
+
get url() {
|
|
418
|
+
return this.client.options.rest.api + Routes.webhook(this.id, this.token);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* A link to the webhook's avatar.
|
|
423
|
+
* @param {ImageURLOptions} [options={}] Options for the image URL
|
|
424
|
+
* @returns {?string}
|
|
425
|
+
*/
|
|
426
|
+
avatarURL(options = {}) {
|
|
427
|
+
return this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Whether this webhook is created by a user.
|
|
432
|
+
* @returns {boolean}
|
|
433
|
+
*/
|
|
434
|
+
isUserCreated() {
|
|
435
|
+
return Boolean(this.type === WebhookType.Incoming && this.owner && !this.owner.bot);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Whether this webhook is created by an application.
|
|
440
|
+
* @returns {boolean}
|
|
441
|
+
*/
|
|
442
|
+
isApplicationCreated() {
|
|
443
|
+
return this.type === WebhookType.Application;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Whether or not this webhook is a channel follower webhook.
|
|
448
|
+
* @returns {boolean}
|
|
449
|
+
*/
|
|
450
|
+
isChannelFollower() {
|
|
451
|
+
return this.type === WebhookType.ChannelFollower;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Whether or not this webhook is an incoming webhook.
|
|
456
|
+
* @returns {boolean}
|
|
457
|
+
*/
|
|
458
|
+
isIncoming() {
|
|
459
|
+
return this.type === WebhookType.Incoming;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
static applyToClass(structure, ignore = []) {
|
|
463
|
+
for (const prop of [
|
|
464
|
+
'send',
|
|
465
|
+
'sendSlackMessage',
|
|
466
|
+
'fetchMessage',
|
|
467
|
+
'edit',
|
|
468
|
+
'editMessage',
|
|
469
|
+
'delete',
|
|
470
|
+
'deleteMessage',
|
|
471
|
+
'createdTimestamp',
|
|
472
|
+
'createdAt',
|
|
473
|
+
'url',
|
|
474
|
+
]) {
|
|
475
|
+
if (ignore.includes(prop)) continue;
|
|
476
|
+
Object.defineProperty(structure.prototype, prop, Object.getOwnPropertyDescriptor(Webhook.prototype, prop));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
module.exports = Webhook;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Base = require('./Base');
|
|
4
|
+
const { Emoji } = require('./Emoji');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a channel link in a guild's welcome screen.
|
|
8
|
+
* @extends {Base}
|
|
9
|
+
*/
|
|
10
|
+
class WelcomeChannel extends Base {
|
|
11
|
+
constructor(guild, data) {
|
|
12
|
+
super(guild.client);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The guild for this welcome channel
|
|
16
|
+
* @type {Guild|InviteGuild}
|
|
17
|
+
*/
|
|
18
|
+
this.guild = guild;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The description of this welcome channel
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
this.description = data.description;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The raw emoji data
|
|
28
|
+
* @type {Object}
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
this._emoji = {
|
|
32
|
+
name: data.emoji_name,
|
|
33
|
+
id: data.emoji_id,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The id of this welcome channel
|
|
38
|
+
* @type {Snowflake}
|
|
39
|
+
*/
|
|
40
|
+
this.channelId = data.channel_id;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The channel of this welcome channel
|
|
45
|
+
* @type {?(TextChannel|NewsChannel|ForumChannel)}
|
|
46
|
+
*/
|
|
47
|
+
get channel() {
|
|
48
|
+
return this.client.channels.resolve(this.channelId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The emoji of this welcome channel
|
|
53
|
+
* @type {GuildEmoji|Emoji}
|
|
54
|
+
*/
|
|
55
|
+
get emoji() {
|
|
56
|
+
return this.client.emojis.resolve(this._emoji.id) ?? new Emoji(this.client, this._emoji);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = WelcomeChannel;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const { GuildFeature } = require('discord-api-types/v10');
|
|
5
|
+
const Base = require('./Base');
|
|
6
|
+
const WelcomeChannel = require('./WelcomeChannel');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a welcome screen.
|
|
10
|
+
* @extends {Base}
|
|
11
|
+
*/
|
|
12
|
+
class WelcomeScreen extends Base {
|
|
13
|
+
constructor(guild, data) {
|
|
14
|
+
super(guild.client);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The guild for this welcome screen
|
|
18
|
+
* @type {Guild}
|
|
19
|
+
*/
|
|
20
|
+
this.guild = guild;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The description of this welcome screen
|
|
24
|
+
* @type {?string}
|
|
25
|
+
*/
|
|
26
|
+
this.description = data.description ?? null;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Collection of welcome channels belonging to this welcome screen
|
|
30
|
+
* @type {Collection<Snowflake, WelcomeChannel>}
|
|
31
|
+
*/
|
|
32
|
+
this.welcomeChannels = new Collection();
|
|
33
|
+
|
|
34
|
+
for (const channel of data.welcome_channels) {
|
|
35
|
+
const welcomeChannel = new WelcomeChannel(this.guild, channel);
|
|
36
|
+
this.welcomeChannels.set(welcomeChannel.channelId, welcomeChannel);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether the welcome screen is enabled on the guild
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
*/
|
|
44
|
+
get enabled() {
|
|
45
|
+
return this.guild.features.includes(GuildFeature.WelcomeScreenEnabled);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = WelcomeScreen;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const { Routes } = require('discord-api-types/v10');
|
|
5
|
+
const Base = require('./Base');
|
|
6
|
+
const WidgetMember = require('./WidgetMember');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a Widget.
|
|
10
|
+
* @extends {Base}
|
|
11
|
+
*/
|
|
12
|
+
class Widget extends Base {
|
|
13
|
+
constructor(client, data) {
|
|
14
|
+
super(client);
|
|
15
|
+
this._patch(data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represents a channel in a Widget
|
|
20
|
+
* @typedef {Object} WidgetChannel
|
|
21
|
+
* @property {Snowflake} id Id of the channel
|
|
22
|
+
* @property {string} name Name of the channel
|
|
23
|
+
* @property {number} position Position of the channel
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
_patch(data) {
|
|
27
|
+
/**
|
|
28
|
+
* The id of the guild.
|
|
29
|
+
* @type {Snowflake}
|
|
30
|
+
*/
|
|
31
|
+
this.id = data.id;
|
|
32
|
+
|
|
33
|
+
if ('name' in data) {
|
|
34
|
+
/**
|
|
35
|
+
* The name of the guild.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
this.name = data.name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ('instant_invite' in data) {
|
|
42
|
+
/**
|
|
43
|
+
* The invite of the guild.
|
|
44
|
+
* @type {?string}
|
|
45
|
+
*/
|
|
46
|
+
this.instantInvite = data.instant_invite;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The list of channels in the guild.
|
|
51
|
+
* @type {Collection<Snowflake, WidgetChannel>}
|
|
52
|
+
*/
|
|
53
|
+
this.channels = new Collection();
|
|
54
|
+
for (const channel of data.channels) {
|
|
55
|
+
this.channels.set(channel.id, channel);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The list of members in the guild.
|
|
60
|
+
* These strings are just arbitrary numbers, they aren't Snowflakes.
|
|
61
|
+
* @type {Collection<string, WidgetMember>}
|
|
62
|
+
*/
|
|
63
|
+
this.members = new Collection();
|
|
64
|
+
for (const member of data.members) {
|
|
65
|
+
this.members.set(member.id, new WidgetMember(this.client, member));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ('presence_count' in data) {
|
|
69
|
+
/**
|
|
70
|
+
* The number of members online.
|
|
71
|
+
* @type {number}
|
|
72
|
+
*/
|
|
73
|
+
this.presenceCount = data.presence_count;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Update the Widget.
|
|
79
|
+
* @returns {Promise<Widget>}
|
|
80
|
+
*/
|
|
81
|
+
async fetch() {
|
|
82
|
+
const data = await this.client.rest.get(Routes.guildWidgetJSON(this.id));
|
|
83
|
+
this._patch(data);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = Widget;
|