discord-selfbot-v13.js 0.0.1-security → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord-selfbot-v13.js might be problematic. Click here for more details.
- package/LICENSE +674 -0
- package/README.md +128 -5
- package/package.json +98 -3
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +87 -0
- package/src/client/Client.js +1124 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +120 -0
- package/src/client/actions/ActionsManager.js +78 -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 +39 -0
- package/src/client/actions/ChannelUpdate.js +43 -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 +65 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +21 -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 +33 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +31 -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 +21 -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 +115 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +61 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +46 -0
- package/src/client/actions/MessageReactionAdd.js +56 -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 +45 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +33 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +32 -0
- package/src/client/actions/ThreadListSync.js +59 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +34 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +35 -0
- package/src/client/actions/VoiceStateUpdate.js +57 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +51 -0
- package/src/client/websocket/WebSocketManager.js +412 -0
- package/src/client/websocket/WebSocketShard.js +905 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -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/CALL_CREATE.js +14 -0
- package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
- package/src/client/websocket/handlers/CALL_UPDATE.js +11 -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_RECIPIENT_ADD.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -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 +53 -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_LIST_UPDATE.js +55 -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_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -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 +16 -0
- package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
- package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +11 -0
- package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -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_ACK.js +16 -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 +171 -0
- package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +17 -0
- package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +15 -0
- package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +18 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -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_GUILD_SETTINGS_UPDATE.js +12 -0
- package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +9 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -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 +87 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +228 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +194 -0
- package/src/managers/ApplicationCommandManager.js +267 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +425 -0
- package/src/managers/AutoModerationRuleManager.js +296 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/BillingManager.js +66 -0
- package/src/managers/CachedManager.js +71 -0
- package/src/managers/ChannelManager.js +139 -0
- package/src/managers/ClientUserSettingManager.js +490 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/DeveloperPortalManager.js +104 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +504 -0
- package/src/managers/GuildEmojiManager.js +171 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildFolderManager.js +24 -0
- package/src/managers/GuildForumThreadManager.js +114 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +304 -0
- package/src/managers/GuildMemberManager.js +772 -0
- package/src/managers/GuildMemberRoleManager.js +191 -0
- package/src/managers/GuildScheduledEventManager.js +296 -0
- package/src/managers/GuildSettingManager.js +148 -0
- package/src/managers/GuildStickerManager.js +179 -0
- package/src/managers/GuildTextThreadManager.js +98 -0
- package/src/managers/InteractionManager.js +39 -0
- package/src/managers/MessageManager.js +393 -0
- package/src/managers/PermissionOverwriteManager.js +166 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +71 -0
- package/src/managers/RelationshipManager.js +258 -0
- package/src/managers/RoleManager.js +352 -0
- package/src/managers/SessionManager.js +57 -0
- package/src/managers/StageInstanceManager.js +162 -0
- package/src/managers/ThreadManager.js +207 -0
- package/src/managers/ThreadMemberManager.js +186 -0
- package/src/managers/UserManager.js +150 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/rest/APIRequest.js +133 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/CaptchaSolver.js +139 -0
- package/src/rest/DiscordAPIError.js +103 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +82 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +430 -0
- package/src/sharding/Shard.js +443 -0
- package/src/sharding/ShardClientUtil.js +275 -0
- package/src/sharding/ShardingManager.js +318 -0
- package/src/structures/AnonymousGuild.js +98 -0
- package/src/structures/ApplicationCommand.js +1030 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +45 -0
- package/src/structures/AutoModerationActionExecution.js +89 -0
- package/src/structures/AutoModerationRule.js +294 -0
- package/src/structures/AutocompleteInteraction.js +106 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseCommandInteraction.js +211 -0
- package/src/structures/BaseGuild.js +116 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +203 -0
- package/src/structures/BaseGuildVoiceChannel.js +243 -0
- package/src/structures/BaseMessageComponent.js +114 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/Call.js +58 -0
- package/src/structures/CategoryChannel.js +85 -0
- package/src/structures/Channel.js +271 -0
- package/src/structures/ClientApplication.js +233 -0
- package/src/structures/ClientPresence.js +92 -0
- package/src/structures/ClientUser.js +635 -0
- package/src/structures/CommandInteraction.js +41 -0
- package/src/structures/CommandInteractionOptionResolver.js +276 -0
- package/src/structures/ContextMenuInteraction.js +65 -0
- package/src/structures/DMChannel.js +289 -0
- package/src/structures/DeveloperPortalApplication.js +520 -0
- package/src/structures/DirectoryChannel.js +20 -0
- package/src/structures/Emoji.js +148 -0
- package/src/structures/ForumChannel.js +271 -0
- package/src/structures/Guild.js +1744 -0
- package/src/structures/GuildAuditLogs.js +734 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildBoost.js +108 -0
- package/src/structures/GuildChannel.js +468 -0
- package/src/structures/GuildEmoji.js +161 -0
- package/src/structures/GuildFolder.js +75 -0
- package/src/structures/GuildMember.js +686 -0
- package/src/structures/GuildPreview.js +191 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +441 -0
- package/src/structures/GuildTemplate.js +236 -0
- package/src/structures/Integration.js +188 -0
- package/src/structures/IntegrationApplication.js +96 -0
- package/src/structures/Interaction.js +351 -0
- package/src/structures/InteractionCollector.js +248 -0
- package/src/structures/InteractionResponse.js +114 -0
- package/src/structures/InteractionWebhook.js +43 -0
- package/src/structures/Invite.js +375 -0
- package/src/structures/InviteGuild.js +23 -0
- package/src/structures/InviteStageInstance.js +86 -0
- package/src/structures/Message.js +1188 -0
- package/src/structures/MessageActionRow.js +103 -0
- package/src/structures/MessageAttachment.js +204 -0
- package/src/structures/MessageButton.js +231 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +120 -0
- package/src/structures/MessageContextMenuInteraction.js +20 -0
- package/src/structures/MessageEmbed.js +586 -0
- package/src/structures/MessageMentions.js +272 -0
- package/src/structures/MessagePayload.js +358 -0
- package/src/structures/MessageReaction.js +171 -0
- package/src/structures/MessageSelectMenu.js +391 -0
- package/src/structures/Modal.js +279 -0
- package/src/structures/ModalSubmitFieldsResolver.js +53 -0
- package/src/structures/ModalSubmitInteraction.js +119 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +449 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +443 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/RichPresence.js +722 -0
- package/src/structures/Role.js +531 -0
- package/src/structures/SelectMenuInteraction.js +170 -0
- package/src/structures/Session.js +81 -0
- package/src/structures/StageChannel.js +104 -0
- package/src/structures/StageInstance.js +208 -0
- package/src/structures/Sticker.js +310 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StoreChannel.js +56 -0
- package/src/structures/Team.js +167 -0
- package/src/structures/TeamMember.js +71 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputComponent.js +201 -0
- package/src/structures/ThreadChannel.js +626 -0
- package/src/structures/ThreadMember.js +105 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +730 -0
- package/src/structures/UserContextMenuInteraction.js +29 -0
- package/src/structures/VoiceChannel.js +110 -0
- package/src/structures/VoiceRegion.js +53 -0
- package/src/structures/VoiceState.js +353 -0
- package/src/structures/WebEmbed.js +412 -0
- package/src/structures/Webhook.js +461 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +48 -0
- package/src/structures/Widget.js +87 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +190 -0
- package/src/structures/interfaces/Collector.js +300 -0
- package/src/structures/interfaces/InteractionResponses.js +313 -0
- package/src/structures/interfaces/TextBasedChannel.js +566 -0
- package/src/util/ActivityFlags.js +44 -0
- package/src/util/ApplicationFlags.js +76 -0
- package/src/util/AttachmentFlags.js +38 -0
- package/src/util/BitField.js +170 -0
- package/src/util/ChannelFlags.js +45 -0
- package/src/util/Constants.js +1940 -0
- package/src/util/DataResolver.js +145 -0
- package/src/util/Formatters.js +214 -0
- package/src/util/GuildMemberFlags.js +43 -0
- package/src/util/Intents.js +74 -0
- package/src/util/LimitedCollection.js +131 -0
- package/src/util/MessageFlags.js +54 -0
- package/src/util/Options.js +364 -0
- package/src/util/Permissions.js +187 -0
- package/src/util/PremiumUsageFlags.js +31 -0
- package/src/util/PurchasedFlags.js +31 -0
- package/src/util/RemoteAuth.js +514 -0
- package/src/util/RoleFlags.js +37 -0
- package/src/util/SnowflakeUtil.js +92 -0
- package/src/util/Sweepers.js +466 -0
- package/src/util/SystemChannelFlags.js +55 -0
- package/src/util/ThreadMemberFlags.js +30 -0
- package/src/util/UserFlags.js +104 -0
- package/src/util/Util.js +882 -0
- package/src/util/Voice.js +1456 -0
- package/src/util/arRPC/index.js +229 -0
- package/src/util/arRPC/process/detectable.json +1 -0
- package/src/util/arRPC/process/index.js +102 -0
- package/src/util/arRPC/process/native/index.js +5 -0
- package/src/util/arRPC/process/native/linux.js +37 -0
- package/src/util/arRPC/process/native/win32.js +25 -0
- package/src/util/arRPC/transports/ipc.js +281 -0
- package/src/util/arRPC/transports/websocket.js +128 -0
- package/typings/enums.d.ts +346 -0
- package/typings/index.d.ts +7776 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +283 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
4
|
+
const DataManager = require('./DataManager');
|
5
|
+
const { TypeError } = require('../errors');
|
6
|
+
const { Role } = require('../structures/Role');
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Manages API methods for roles of a GuildMember and stores their cache.
|
10
|
+
* @extends {DataManager}
|
11
|
+
*/
|
12
|
+
class GuildMemberRoleManager extends DataManager {
|
13
|
+
constructor(member) {
|
14
|
+
super(member.client, Role);
|
15
|
+
|
16
|
+
/**
|
17
|
+
* The GuildMember this manager belongs to
|
18
|
+
* @type {GuildMember}
|
19
|
+
*/
|
20
|
+
this.member = member;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* The Guild this manager belongs to
|
24
|
+
* @type {Guild}
|
25
|
+
*/
|
26
|
+
this.guild = member.guild;
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* The roles of this member
|
31
|
+
* @type {Collection<Snowflake, Role>}
|
32
|
+
* @readonly
|
33
|
+
*/
|
34
|
+
get cache() {
|
35
|
+
const everyone = this.guild.roles.everyone;
|
36
|
+
return this.guild.roles.cache.filter(role => this.member._roles.includes(role.id)).set(everyone.id, everyone);
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* The role of the member used to hoist them in a separate category in the users list
|
41
|
+
* @type {?Role}
|
42
|
+
* @readonly
|
43
|
+
*/
|
44
|
+
get hoist() {
|
45
|
+
const hoistedRoles = this.cache.filter(role => role.hoist);
|
46
|
+
if (!hoistedRoles.size) return null;
|
47
|
+
return hoistedRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* The role of the member used to set their role icon
|
52
|
+
* @type {?Role}
|
53
|
+
* @readonly
|
54
|
+
*/
|
55
|
+
get icon() {
|
56
|
+
const iconRoles = this.cache.filter(role => role.icon || role.unicodeEmoji);
|
57
|
+
if (!iconRoles.size) return null;
|
58
|
+
return iconRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* The role of the member used to set their color
|
63
|
+
* @type {?Role}
|
64
|
+
* @readonly
|
65
|
+
*/
|
66
|
+
get color() {
|
67
|
+
const coloredRoles = this.cache.filter(role => role.color);
|
68
|
+
if (!coloredRoles.size) return null;
|
69
|
+
return coloredRoles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev));
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* The role of the member with the highest position
|
74
|
+
* @type {Role}
|
75
|
+
* @readonly
|
76
|
+
*/
|
77
|
+
get highest() {
|
78
|
+
return this.cache.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this.cache.first());
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* The premium subscriber role of the guild, if present on the member
|
83
|
+
* @type {?Role}
|
84
|
+
* @readonly
|
85
|
+
*/
|
86
|
+
get premiumSubscriberRole() {
|
87
|
+
return this.cache.find(role => role.tags?.premiumSubscriberRole) ?? null;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* The managed role this member created when joining the guild, if any
|
92
|
+
* <info>Only ever available on bots</info>
|
93
|
+
* @type {?Role}
|
94
|
+
* @readonly
|
95
|
+
*/
|
96
|
+
get botRole() {
|
97
|
+
if (!this.member.user.bot) return null;
|
98
|
+
return this.cache.find(role => role.tags?.botId === this.member.user.id) ?? null;
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Adds a role (or multiple roles) to the member.
|
103
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to add
|
104
|
+
* @param {string} [reason] Reason for adding the role(s)
|
105
|
+
* @returns {Promise<GuildMember>}
|
106
|
+
*/
|
107
|
+
async add(roleOrRoles, reason) {
|
108
|
+
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
109
|
+
const resolvedRoles = [];
|
110
|
+
for (const role of roleOrRoles.values()) {
|
111
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
112
|
+
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role);
|
113
|
+
resolvedRoles.push(resolvedRole);
|
114
|
+
}
|
115
|
+
|
116
|
+
const newRoles = [...new Set(resolvedRoles.concat(...this.cache.keys()))];
|
117
|
+
return this.set(newRoles, reason);
|
118
|
+
} else {
|
119
|
+
roleOrRoles = this.guild.roles.resolveId(roleOrRoles);
|
120
|
+
if (roleOrRoles === null) {
|
121
|
+
throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snowflake or Array or Collection of Roles or Snowflakes');
|
122
|
+
}
|
123
|
+
|
124
|
+
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles].put({ reason });
|
125
|
+
|
126
|
+
const clone = this.member._clone();
|
127
|
+
clone._roles = [...this.cache.keys(), roleOrRoles];
|
128
|
+
return clone;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Removes a role (or multiple roles) from the member.
|
134
|
+
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to remove
|
135
|
+
* @param {string} [reason] Reason for removing the role(s)
|
136
|
+
* @returns {Promise<GuildMember>}
|
137
|
+
*/
|
138
|
+
async remove(roleOrRoles, reason) {
|
139
|
+
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
140
|
+
const resolvedRoles = [];
|
141
|
+
for (const role of roleOrRoles.values()) {
|
142
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
143
|
+
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role);
|
144
|
+
resolvedRoles.push(resolvedRole);
|
145
|
+
}
|
146
|
+
|
147
|
+
const newRoles = this.cache.filter(role => !resolvedRoles.includes(role.id));
|
148
|
+
return this.set(newRoles, reason);
|
149
|
+
} else {
|
150
|
+
roleOrRoles = this.guild.roles.resolveId(roleOrRoles);
|
151
|
+
if (roleOrRoles === null) {
|
152
|
+
throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snowflake or Array or Collection of Roles or Snowflakes');
|
153
|
+
}
|
154
|
+
|
155
|
+
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles].delete({ reason });
|
156
|
+
|
157
|
+
const clone = this.member._clone();
|
158
|
+
const newRoles = this.cache.filter(role => role.id !== roleOrRoles);
|
159
|
+
clone._roles = [...newRoles.keys()];
|
160
|
+
return clone;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Sets the roles applied to the member.
|
166
|
+
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role ids to apply
|
167
|
+
* @param {string} [reason] Reason for applying the roles
|
168
|
+
* @returns {Promise<GuildMember>}
|
169
|
+
* @example
|
170
|
+
* // Set the member's roles to a single role
|
171
|
+
* guildMember.roles.set(['391156570408615936'])
|
172
|
+
* .then(console.log)
|
173
|
+
* .catch(console.error);
|
174
|
+
* @example
|
175
|
+
* // Remove all the roles from a member
|
176
|
+
* guildMember.roles.set([])
|
177
|
+
* .then(member => console.log(`Member roles is now of ${member.roles.cache.size} size`))
|
178
|
+
* .catch(console.error);
|
179
|
+
*/
|
180
|
+
set(roles, reason) {
|
181
|
+
return this.member.edit({ roles }, reason);
|
182
|
+
}
|
183
|
+
|
184
|
+
clone() {
|
185
|
+
const clone = new this.constructor(this.member);
|
186
|
+
clone.member._roles = [...this.cache.keys()];
|
187
|
+
return clone;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
module.exports = GuildMemberRoleManager;
|
@@ -0,0 +1,296 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
4
|
+
const CachedManager = require('./CachedManager');
|
5
|
+
const { TypeError, Error } = require('../errors');
|
6
|
+
const { GuildScheduledEvent } = require('../structures/GuildScheduledEvent');
|
7
|
+
const { PrivacyLevels, GuildScheduledEventEntityTypes, GuildScheduledEventStatuses } = require('../util/Constants');
|
8
|
+
const DataResolver = require('../util/DataResolver');
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Manages API methods for GuildScheduledEvents and stores their cache.
|
12
|
+
* @extends {CachedManager}
|
13
|
+
*/
|
14
|
+
class GuildScheduledEventManager extends CachedManager {
|
15
|
+
constructor(guild, iterable) {
|
16
|
+
super(guild.client, GuildScheduledEvent, iterable);
|
17
|
+
|
18
|
+
/**
|
19
|
+
* The guild this manager belongs to
|
20
|
+
* @type {Guild}
|
21
|
+
*/
|
22
|
+
this.guild = guild;
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* The cache of this manager
|
27
|
+
* @type {Collection<Snowflake, GuildScheduledEvent>}
|
28
|
+
* @name GuildScheduledEventManager#cache
|
29
|
+
*/
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Data that resolves to give a GuildScheduledEvent object. This can be:
|
33
|
+
* * A Snowflake
|
34
|
+
* * A GuildScheduledEvent object
|
35
|
+
* @typedef {Snowflake|GuildScheduledEvent} GuildScheduledEventResolvable
|
36
|
+
*/
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Options used to create a guild scheduled event.
|
40
|
+
* @typedef {Object} GuildScheduledEventCreateOptions
|
41
|
+
* @property {string} name The name of the guild scheduled event
|
42
|
+
* @property {DateResolvable} scheduledStartTime The time to schedule the event at
|
43
|
+
* @property {DateResolvable} [scheduledEndTime] The time to end the event at
|
44
|
+
* <warn>This is required if `entityType` is 'EXTERNAL'</warn>
|
45
|
+
* @property {PrivacyLevel|number} privacyLevel The privacy level of the guild scheduled event
|
46
|
+
* @property {GuildScheduledEventEntityType|number} entityType The scheduled entity type of the event
|
47
|
+
* @property {string} [description] The description of the guild scheduled event
|
48
|
+
* @property {GuildVoiceChannelResolvable} [channel] The channel of the guild scheduled event
|
49
|
+
* <warn>This is required if `entityType` is 'STAGE_INSTANCE' or `VOICE`</warn>
|
50
|
+
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
|
51
|
+
* guild scheduled event
|
52
|
+
* <warn>This is required if `entityType` is 'EXTERNAL'</warn>
|
53
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [image] The cover image of the guild scheduled event
|
54
|
+
* @property {string} [reason] The reason for creating the guild scheduled event
|
55
|
+
*/
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Options used to set entity metadata of a guild scheduled event.
|
59
|
+
* @typedef {Object} GuildScheduledEventEntityMetadataOptions
|
60
|
+
* @property {string} [location] The location of the guild scheduled event
|
61
|
+
* <warn>This is required if `entityType` is 'EXTERNAL'</warn>
|
62
|
+
*/
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Creates a new guild scheduled event.
|
66
|
+
* @param {GuildScheduledEventCreateOptions} options Options for creating the guild scheduled event
|
67
|
+
* @returns {Promise<GuildScheduledEvent>}
|
68
|
+
*/
|
69
|
+
async create(options) {
|
70
|
+
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
71
|
+
let {
|
72
|
+
privacyLevel,
|
73
|
+
entityType,
|
74
|
+
channel,
|
75
|
+
name,
|
76
|
+
scheduledStartTime,
|
77
|
+
description,
|
78
|
+
scheduledEndTime,
|
79
|
+
entityMetadata,
|
80
|
+
reason,
|
81
|
+
image,
|
82
|
+
} = options;
|
83
|
+
|
84
|
+
if (typeof privacyLevel === 'string') privacyLevel = PrivacyLevels[privacyLevel];
|
85
|
+
if (typeof entityType === 'string') entityType = GuildScheduledEventEntityTypes[entityType];
|
86
|
+
|
87
|
+
let entity_metadata, channel_id;
|
88
|
+
if (entityType === GuildScheduledEventEntityTypes.EXTERNAL) {
|
89
|
+
channel_id = typeof channel === 'undefined' ? channel : null;
|
90
|
+
entity_metadata = { location: entityMetadata?.location };
|
91
|
+
} else {
|
92
|
+
channel_id = this.guild.channels.resolveId(channel);
|
93
|
+
if (!channel_id) throw new Error('GUILD_VOICE_CHANNEL_RESOLVE');
|
94
|
+
entity_metadata = typeof entityMetadata === 'undefined' ? entityMetadata : null;
|
95
|
+
}
|
96
|
+
|
97
|
+
const data = await this.client.api.guilds(this.guild.id, 'scheduled-events').post({
|
98
|
+
data: {
|
99
|
+
channel_id,
|
100
|
+
name,
|
101
|
+
privacy_level: privacyLevel,
|
102
|
+
scheduled_start_time: new Date(scheduledStartTime).toISOString(),
|
103
|
+
scheduled_end_time: scheduledEndTime ? new Date(scheduledEndTime).toISOString() : scheduledEndTime,
|
104
|
+
description,
|
105
|
+
image: image && (await DataResolver.resolveImage(image)),
|
106
|
+
entity_type: entityType,
|
107
|
+
entity_metadata,
|
108
|
+
},
|
109
|
+
reason,
|
110
|
+
});
|
111
|
+
|
112
|
+
return this._add(data);
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Options used to fetch a single guild scheduled event from a guild.
|
117
|
+
* @typedef {BaseFetchOptions} FetchGuildScheduledEventOptions
|
118
|
+
* @property {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to fetch
|
119
|
+
* @property {boolean} [withUserCount=true] Whether to fetch the number of users subscribed to the scheduled event
|
120
|
+
*/
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Options used to fetch multiple guild scheduled events from a guild.
|
124
|
+
* @typedef {Object} FetchGuildScheduledEventsOptions
|
125
|
+
* @property {boolean} [cache] Whether or not to cache the fetched guild scheduled events
|
126
|
+
* @property {boolean} [withUserCount=true] Whether to fetch the number of users subscribed to each scheduled event
|
127
|
+
* should be returned
|
128
|
+
*/
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Obtains one or more guild scheduled events from Discord, or the guild cache if it's already available.
|
132
|
+
* @param {GuildScheduledEventResolvable|FetchGuildScheduledEventOptions|FetchGuildScheduledEventsOptions} [options]
|
133
|
+
* The id of the guild scheduled event or options
|
134
|
+
* @returns {Promise<GuildScheduledEvent|Collection<Snowflake, GuildScheduledEvent>>}
|
135
|
+
*/
|
136
|
+
async fetch(options = {}) {
|
137
|
+
const id = this.resolveId(options.guildScheduledEvent ?? options);
|
138
|
+
|
139
|
+
if (id) {
|
140
|
+
if (!options.force) {
|
141
|
+
const existing = this.cache.get(id);
|
142
|
+
if (existing) return existing;
|
143
|
+
}
|
144
|
+
|
145
|
+
const data = await this.client.api
|
146
|
+
.guilds(this.guild.id, 'scheduled-events', id)
|
147
|
+
.get({ query: { with_user_count: options.withUserCount ?? true } });
|
148
|
+
return this._add(data, options.cache);
|
149
|
+
}
|
150
|
+
|
151
|
+
const data = await this.client.api
|
152
|
+
.guilds(this.guild.id, 'scheduled-events')
|
153
|
+
.get({ query: { with_user_count: options.withUserCount ?? true } });
|
154
|
+
|
155
|
+
return data.reduce(
|
156
|
+
(coll, rawGuildScheduledEventData) =>
|
157
|
+
coll.set(
|
158
|
+
rawGuildScheduledEventData.id,
|
159
|
+
this.guild.scheduledEvents._add(rawGuildScheduledEventData, options.cache),
|
160
|
+
),
|
161
|
+
new Collection(),
|
162
|
+
);
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Options used to edit a guild scheduled event.
|
167
|
+
* @typedef {Object} GuildScheduledEventEditOptions
|
168
|
+
* @property {string} [name] The name of the guild scheduled event
|
169
|
+
* @property {DateResolvable} [scheduledStartTime] The time to schedule the event at
|
170
|
+
* @property {DateResolvable} [scheduledEndTime] The time to end the event at
|
171
|
+
* @property {PrivacyLevel|number} [privacyLevel] The privacy level of the guild scheduled event
|
172
|
+
* @property {GuildScheduledEventEntityType|number} [entityType] The scheduled entity type of the event
|
173
|
+
* @property {string} [description] The description of the guild scheduled event
|
174
|
+
* @property {?GuildVoiceChannelResolvable} [channel] The channel of the guild scheduled event
|
175
|
+
* @property {GuildScheduledEventStatus|number} [status] The status of the guild scheduled event
|
176
|
+
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
|
177
|
+
* guild scheduled event
|
178
|
+
* <warn>This can be modified only if `entityType` of the `GuildScheduledEvent` to be edited is 'EXTERNAL'</warn>
|
179
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [image] The cover image of the guild scheduled event
|
180
|
+
* @property {string} [reason] The reason for editing the guild scheduled event
|
181
|
+
*/
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Edits a guild scheduled event.
|
185
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to edit
|
186
|
+
* @param {GuildScheduledEventEditOptions} options Options to edit the guild scheduled event
|
187
|
+
* @returns {Promise<GuildScheduledEvent>}
|
188
|
+
*/
|
189
|
+
async edit(guildScheduledEvent, options) {
|
190
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
191
|
+
if (!guildScheduledEventId) throw new Error('GUILD_SCHEDULED_EVENT_RESOLVE');
|
192
|
+
|
193
|
+
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
194
|
+
let {
|
195
|
+
privacyLevel,
|
196
|
+
entityType,
|
197
|
+
channel,
|
198
|
+
status,
|
199
|
+
name,
|
200
|
+
scheduledStartTime,
|
201
|
+
description,
|
202
|
+
scheduledEndTime,
|
203
|
+
entityMetadata,
|
204
|
+
reason,
|
205
|
+
image,
|
206
|
+
} = options;
|
207
|
+
|
208
|
+
if (typeof privacyLevel === 'string') privacyLevel = PrivacyLevels[privacyLevel];
|
209
|
+
if (typeof entityType === 'string') entityType = GuildScheduledEventEntityTypes[entityType];
|
210
|
+
if (typeof status === 'string') status = GuildScheduledEventStatuses[status];
|
211
|
+
|
212
|
+
let entity_metadata;
|
213
|
+
if (entityMetadata) {
|
214
|
+
entity_metadata = {
|
215
|
+
location: entityMetadata.location,
|
216
|
+
};
|
217
|
+
}
|
218
|
+
|
219
|
+
const data = await this.client.api.guilds(this.guild.id, 'scheduled-events', guildScheduledEventId).patch({
|
220
|
+
data: {
|
221
|
+
channel_id: typeof channel === 'undefined' ? channel : this.guild.channels.resolveId(channel),
|
222
|
+
name,
|
223
|
+
privacy_level: privacyLevel,
|
224
|
+
scheduled_start_time: scheduledStartTime ? new Date(scheduledStartTime).toISOString() : undefined,
|
225
|
+
scheduled_end_time: scheduledEndTime ? new Date(scheduledEndTime).toISOString() : scheduledEndTime,
|
226
|
+
description,
|
227
|
+
entity_type: entityType,
|
228
|
+
status,
|
229
|
+
image: image && (await DataResolver.resolveImage(image)),
|
230
|
+
entity_metadata,
|
231
|
+
},
|
232
|
+
reason,
|
233
|
+
});
|
234
|
+
|
235
|
+
return this._add(data);
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Deletes a guild scheduled event.
|
240
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to delete
|
241
|
+
* @returns {Promise<void>}
|
242
|
+
*/
|
243
|
+
async delete(guildScheduledEvent) {
|
244
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
245
|
+
if (!guildScheduledEventId) throw new Error('GUILD_SCHEDULED_EVENT_RESOLVE');
|
246
|
+
|
247
|
+
await this.client.api.guilds(this.guild.id, 'scheduled-events', guildScheduledEventId).delete();
|
248
|
+
}
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Options used to fetch subscribers of a guild scheduled event
|
252
|
+
* @typedef {Object} FetchGuildScheduledEventSubscribersOptions
|
253
|
+
* @property {number} [limit] The maximum numbers of users to fetch
|
254
|
+
* @property {boolean} [withMember] Whether to fetch guild member data of the users
|
255
|
+
* @property {Snowflake} [before] Consider only users before this user id
|
256
|
+
* @property {Snowflake} [after] Consider only users after this user id
|
257
|
+
* <warn>If both `before` and `after` are provided, only `before` is respected</warn>
|
258
|
+
*/
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Represents a subscriber of a {@link GuildScheduledEvent}
|
262
|
+
* @typedef {Object} GuildScheduledEventUser
|
263
|
+
* @property {Snowflake} guildScheduledEventId The id of the guild scheduled event which the user subscribed to
|
264
|
+
* @property {User} user The user that subscribed to the guild scheduled event
|
265
|
+
* @property {?GuildMember} member The guild member associated with the user, if any
|
266
|
+
*/
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Fetches subscribers of a guild scheduled event.
|
270
|
+
* @param {GuildScheduledEventResolvable} guildScheduledEvent The guild scheduled event to fetch subscribers of
|
271
|
+
* @param {FetchGuildScheduledEventSubscribersOptions} [options={}] Options for fetching the subscribers
|
272
|
+
* @returns {Promise<Collection<Snowflake, GuildScheduledEventUser>>}
|
273
|
+
*/
|
274
|
+
async fetchSubscribers(guildScheduledEvent, options = {}) {
|
275
|
+
const guildScheduledEventId = this.resolveId(guildScheduledEvent);
|
276
|
+
if (!guildScheduledEventId) throw new Error('GUILD_SCHEDULED_EVENT_RESOLVE');
|
277
|
+
|
278
|
+
let { limit, withMember, before, after } = options;
|
279
|
+
|
280
|
+
const data = await this.client.api.guilds(this.guild.id, 'scheduled-events', guildScheduledEventId).users.get({
|
281
|
+
query: { limit, with_member: withMember, before, after },
|
282
|
+
});
|
283
|
+
|
284
|
+
return data.reduce(
|
285
|
+
(coll, rawData) =>
|
286
|
+
coll.set(rawData.user.id, {
|
287
|
+
guildScheduledEventId: rawData.guild_scheduled_event_id,
|
288
|
+
user: this.client.users._add(rawData.user),
|
289
|
+
member: rawData.member ? this.guild.members._add({ ...rawData.member, user: rawData.user }) : null,
|
290
|
+
}),
|
291
|
+
new Collection(),
|
292
|
+
);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
module.exports = GuildScheduledEventManager;
|
@@ -0,0 +1,148 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const BaseManager = require('./BaseManager');
|
4
|
+
/**
|
5
|
+
* Manages API methods for users and stores their cache.
|
6
|
+
* @extends {BaseManager}
|
7
|
+
* @see {@link https://luna.gitlab.io/discord-unofficial-docs/user_settings.html}
|
8
|
+
*/
|
9
|
+
class GuildSettingManager extends BaseManager {
|
10
|
+
constructor(client, guildId = null) {
|
11
|
+
super(client);
|
12
|
+
/**
|
13
|
+
* Raw data
|
14
|
+
* @type {Object}
|
15
|
+
*/
|
16
|
+
this.rawSetting = {};
|
17
|
+
/**
|
18
|
+
* Guild Id
|
19
|
+
* @type {?Snowflake}
|
20
|
+
*/
|
21
|
+
this.guildId = guildId;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Get the guild
|
25
|
+
* @type {?Guild}
|
26
|
+
* @readonly
|
27
|
+
*/
|
28
|
+
get guild() {
|
29
|
+
return this.client.guilds.cache.get(this.guildId);
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Patch data file
|
33
|
+
* @private
|
34
|
+
* @param {Object} data Raw Data to patch
|
35
|
+
*/
|
36
|
+
_patch(data = {}) {
|
37
|
+
this.rawSetting = Object.assign(this.rawSetting, data);
|
38
|
+
if ('suppress_everyone' in data) {
|
39
|
+
/**
|
40
|
+
* Notification setting > Suppress `@everyone` and `@here`
|
41
|
+
* @type {?boolean}
|
42
|
+
*/
|
43
|
+
this.suppressEveryone = data.suppress_everyone;
|
44
|
+
}
|
45
|
+
if ('suppress_roles' in data) {
|
46
|
+
/**
|
47
|
+
* Notification setting > Suppress all role `@mention`
|
48
|
+
* @type {?boolean}
|
49
|
+
*/
|
50
|
+
this.suppressRoles = data.suppress_roles;
|
51
|
+
}
|
52
|
+
if ('mute_scheduled_events' in data) {
|
53
|
+
/**
|
54
|
+
* Notification setting > Mute new events
|
55
|
+
* @type {?boolean}
|
56
|
+
*/
|
57
|
+
this.muteScheduledEvents = data.mute_scheduled_events;
|
58
|
+
}
|
59
|
+
if ('message_notifications' in data) {
|
60
|
+
/**
|
61
|
+
* Notification setting > Message notifications
|
62
|
+
* * `0` = All messages
|
63
|
+
* * `1` = Only @mentions
|
64
|
+
* * `2` = Nothing
|
65
|
+
* @type {?number}
|
66
|
+
*/
|
67
|
+
this.messageNotifications = data.message_notifications;
|
68
|
+
}
|
69
|
+
if ('flags' in data) {
|
70
|
+
/**
|
71
|
+
* Flags (unknown)
|
72
|
+
* @type {?number}
|
73
|
+
*/
|
74
|
+
this.flags = data.flags;
|
75
|
+
}
|
76
|
+
if ('mobile_push' in data) {
|
77
|
+
/**
|
78
|
+
* Notification setting > Mobile push notifications
|
79
|
+
* @type {?boolean}
|
80
|
+
*/
|
81
|
+
this.mobilePush = data.mobile_push;
|
82
|
+
}
|
83
|
+
if ('muted' in data) {
|
84
|
+
/**
|
85
|
+
* Mute server
|
86
|
+
* @type {?boolean}
|
87
|
+
*/
|
88
|
+
this.muted = data.muted;
|
89
|
+
}
|
90
|
+
if ('mute_config' in data && data.mute_config !== null) {
|
91
|
+
/**
|
92
|
+
* Mute config (muted = true)
|
93
|
+
* * `muteConfig.endTime`: End time (Date)
|
94
|
+
* * `muteConfig.selectedTimeWindow`: Selected time window (seconds) (number)
|
95
|
+
* @type {?Object}
|
96
|
+
*/
|
97
|
+
this.muteConfig = {
|
98
|
+
endTime: new Date(data.mute_config.end_time),
|
99
|
+
selectedTimeWindow: data.mute_config.selected_time_window,
|
100
|
+
};
|
101
|
+
} else {
|
102
|
+
this.muteConfig = null;
|
103
|
+
}
|
104
|
+
if ('hide_muted_channels' in data) {
|
105
|
+
/**
|
106
|
+
* Hide muted channels
|
107
|
+
* @type {?boolean}
|
108
|
+
*/
|
109
|
+
this.hideMutedChannels = data.hide_muted_channels;
|
110
|
+
}
|
111
|
+
if ('channel_overrides' in data) {
|
112
|
+
/**
|
113
|
+
* Channel overrides (unknown)
|
114
|
+
* @type {?Array}
|
115
|
+
*/
|
116
|
+
this.channelOverrides = data.channel_overrides;
|
117
|
+
}
|
118
|
+
if ('notify_highlights' in data) {
|
119
|
+
/**
|
120
|
+
* Notification setting > Suppress highlights
|
121
|
+
* * `0` = ??? (unknown)
|
122
|
+
* * `1` = Enable
|
123
|
+
* * `2` = Disable
|
124
|
+
* @type {?number}
|
125
|
+
*/
|
126
|
+
this.notifyHighlights = data.notify_highlights;
|
127
|
+
}
|
128
|
+
if ('version' in data) {
|
129
|
+
/**
|
130
|
+
* Version (unknown)
|
131
|
+
* @type {?number}
|
132
|
+
*/
|
133
|
+
this.version = data.version;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
/**
|
137
|
+
* Edit guild settings
|
138
|
+
* @param {Object} data Data to edit
|
139
|
+
* @returns {Promise<GuildSettingManager>}
|
140
|
+
*/
|
141
|
+
async edit(data) {
|
142
|
+
const data_ = await this.client.api.users('@me').settings.patch(data);
|
143
|
+
this._patch(data_);
|
144
|
+
return this;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
module.exports = GuildSettingManager;
|