UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

1,210 lines (1,209 loc) 73.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RestClient = void 0; const detritus_client_rest_1 = require("detritus-client-rest"); const constants_1 = require("detritus-client-rest/lib/constants"); const detritus_utils_1 = require("detritus-utils"); const basecollection_1 = require("../collections/basecollection"); const constants_2 = require("../constants"); const utils_1 = require("../utils"); const structures_1 = require("../structures"); class RestClient { constructor(token, options, client) { this.raw = new detritus_client_rest_1.Client(token, options); this.client = client; Object.defineProperty(this, 'client', { enumerable: false, writable: false }); this.raw.on(constants_1.RestEvents.REQUEST, (payload) => this.client.emit(constants_2.ClientEvents.REST_REQUEST, payload)); this.raw.on(constants_1.RestEvents.RESPONSE, (payload) => this.client.emit(constants_2.ClientEvents.REST_RESPONSE, payload)); } get isBot() { return this.raw.isBot; } get isUser() { return this.raw.isUser; } setAuthType(type) { return this.raw.setAuthType(type); } async request(info, init) { return this.raw.request(info, init); } async delete(info, init) { return this.raw.delete(info, init); } async get(info, init) { return this.raw.get(info, init); } async head(info, init) { return this.raw.head(info, init); } async options(info, init) { return this.raw.options(info, init); } async patch(info, init) { return this.raw.patch(info, init); } async post(info, init) { return this.raw.post(info, init); } async put(info, init) { return this.raw.put(info, init); } /* -- Rest Requests Start -- */ acceptAgreements(privacy = true, terms = true) { return this.raw.acceptAgreements(privacy, terms); } acceptInvite(code) { return this.raw.acceptInvite(code); } acceptTeamInvite(token) { return this.raw.acceptTeamInvite(token); } ackChannelMessage(channelId, messageId, token) { return this.raw.ackChannelMessage(channelId, messageId, token); } ackChannelPins(channelId) { return this.raw.ackChannelPins(channelId); } ackGuild(guildId) { return this.raw.ackGuild(guildId); } async acceptTemplate(templateId, options) { const data = await this.raw.acceptTemplate(templateId, options); let guild; if (this.client.guilds.has(data.id)) { guild = this.client.guilds.get(data.id); guild.merge(data); } else { guild = new structures_1.Guild(this.client, data); this.client.guilds.insert(guild); } return guild; } activateOauth2ApplicationLicense(applicationId, options) { return this.raw.activateOauth2ApplicationLicense(applicationId, options); } addConnection(platform, accountId, options) { return this.raw.addConnection(platform, accountId, options); } addGuildMember(guildId, userId, options) { return this.raw.addGuildMember(guildId, userId, options); } addGuildMemberRole(guildId, userId, roleId, options = {}) { return this.raw.addGuildMemberRole(guildId, userId, roleId, options); } addPinnedMessage(channelId, messageId) { return this.raw.addPinnedMessage(channelId, messageId); } addRecipient(channelId, userId) { return this.raw.addRecipient(channelId, userId); } addOauth2ApplicationWhitelistUser(applicationId, options) { return this.raw.addOauth2ApplicationWhitelistUser(applicationId, options); } addTeamMember(teamId, options) { return this.raw.addTeamMember(teamId, options); } addThreadMember(channelId, userId) { return this.raw.addThreadMember(channelId, userId); } authorizeIpAddress(options) { return this.raw.authorizeIpAddress(options); } beginGuildPrune(guildId, options = {}) { return this.raw.beginGuildPrune(guildId, options); } bulkDeleteMessages(channelId, messageIds) { return this.raw.bulkDeleteMessages(channelId, messageIds); } async bulkOverwriteApplicationCommands(applicationId, commands) { const data = await this.raw.bulkOverwriteApplicationCommands(applicationId, commands); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const command = new structures_1.ApplicationCommand(this.client, raw); collection.set(command.id, command); } return collection; } async bulkOverwriteApplicationGuildCommands(applicationId, guildId, commands) { const data = await this.raw.bulkOverwriteApplicationGuildCommands(applicationId, guildId, commands); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const command = new structures_1.ApplicationCommand(this.client, raw); collection.set(command.id, command); } return collection; } async bulkOverwriteApplicationGuildCommandsPermissions(applicationId, guildId, permissions) { const data = await this.raw.bulkOverwriteApplicationGuildCommandsPermissions(applicationId, guildId, permissions); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const commandPermissions = new structures_1.ApplicationCommandPermissions(this.client, raw); collection.set(commandPermissions.id, commandPermissions); } return collection; } connectionCallback(platform, options) { return this.raw.connectionCallback(platform, options); } createApplicationCommand(applicationId, options) { return this.raw.createApplicationCommand(applicationId, options); } createApplicationGuildCommand(applicationId, guildId, options) { return this.raw.createApplicationGuildCommand(applicationId, guildId, options); } async createApplicationNews(options) { const data = await this.raw.createApplicationNews(options); return new structures_1.ApplicationNews(this.client, data); } async createChannelInvite(channelId, options = {}) { const data = await this.raw.createChannelInvite(channelId, options); return new structures_1.Invite(this.client, data); } async createChannelMessageThread(channelId, messageId, options) { const data = await this.raw.createChannelMessageThread(channelId, messageId, options); let channel; if (this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); // this should never happen lmao } else { channel = structures_1.createChannelFromData(this.client, data); this.client.channels.insert(channel); } return channel; } createChannelStoreListingGrantEntitlement(channelId) { return this.raw.createChannelStoreListingGrantEntitlement(channelId); } async createChannelThread(channelId, options) { const data = await this.raw.createChannelThread(channelId, options); let channel; if (this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); // this should never happen lmao } else { channel = structures_1.createChannelFromData(this.client, data); this.client.channels.insert(channel); } return channel; } async createDm(options = {}) { const data = await this.raw.createDm(options); let channel; if (this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); // this should never happen lmao } else { channel = structures_1.createChannelFromData(this.client, data); this.client.channels.insert(channel); } return channel; } async createGuild(options) { const data = await this.raw.createGuild(options); let guild; if (this.client.guilds.has(data.id)) { guild = this.client.guilds.get(data.id); guild.merge(data); } else { guild = new structures_1.Guild(this.client, data); this.client.guilds.insert(guild); } return guild; } createGuildBan(guildId, userId, options = {}) { // make into object? return this.raw.createGuildBan(guildId, userId, options); } async createGuildChannel(guildId, options, updateCache = true) { const data = await this.raw.createGuildChannel(guildId, options); let channel; if (updateCache && this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); // this should never happen lmao } else { channel = structures_1.createChannelFromData(this.client, data); this.client.channels.insert(channel); } return channel; } async createGuildEmoji(guildId, options, updateCache = true) { const data = await this.raw.createGuildEmoji(guildId, options); let emoji; if (updateCache && this.client.emojis.has(guildId, data.id)) { emoji = this.client.emojis.get(guildId, data.id); emoji.merge(data); } else { data.guild_id = guildId; emoji = new structures_1.Emoji(this.client, data); this.client.emojis.insert(emoji); } return emoji; } async createGuildSticker(guildId, options) { const data = await this.raw.createGuildSticker(guildId, options); return new structures_1.Sticker(this.client, data); } createGuildIntegration(guildId, options) { // make this into object? return this.raw.createGuildIntegration(guildId, options); } async createGuildRole(guildId, options = {}) { const data = await this.raw.createGuildRole(guildId, options); data.guild_id = guildId; const role = new structures_1.Role(this.client, data); if (this.client.guilds.has(guildId)) { const guild = this.client.guilds.get(guildId); guild.roles.set(role.id, role); } return role; } async createGuildTemplate(guildId, options) { const data = await this.raw.createGuildTemplate(guildId, options); return new structures_1.Template(this.client, data); } async createInteractionResponse(interactionId, token, options, data) { const listenerData = utils_1.createComponentListenerOrNone((typeof (options) === 'object') ? options.data || data : data, interactionId); const rawData = await this.raw.createInteractionResponse(interactionId, token, options, data); if (listenerData) { const [lId, listener] = listenerData; const listenerId = lId || interactionId; if (listener) { listener.id = listenerId; this.client.gatewayHandler._componentHandler.insert(listener); } else { this.client.gatewayHandler._componentHandler.delete(listenerId); } } return rawData; } createLobby(applicationId, options = {}) { return this.raw.createLobby(applicationId, options); } createMeBillingPaymentSource(options) { return this.raw.createMeBillingPaymentSource(options); } createMeBillingSubscription(options) { return this.raw.createMeBillingSubscription(options); } async createMessage(channelId, options = {}) { const listenerData = utils_1.createComponentListenerOrNone(options); const data = await this.raw.createMessage(channelId, options); if (this.client.channels.has(data.channel_id)) { const channel = this.client.channels.get(data.channel_id); if (channel.guildId) { data.guild_id = channel.guildId; } } const message = new structures_1.Message(this.client, data); this.client.messages.insert(message); if (listenerData) { const [lId, listener] = listenerData; const listenerId = lId || message.id; if (listener) { listener.id = listenerId; this.client.gatewayHandler._componentHandler.insert(listener); } else { this.client.gatewayHandler._componentHandler.delete(listenerId); } } return message; } createOauth2Application(options) { return this.raw.createOauth2Application(options); } async createOauth2ApplicationAsset(applicationId, options) { const data = await this.raw.createOauth2ApplicationAsset(applicationId, options); data.application_id = applicationId; return new structures_1.Oauth2ApplicationAsset(this.client, data); } createOauth2ApplicationBot(applicationId) { return this.raw.createOauth2ApplicationBot(applicationId); } createReaction(channelId, messageId, emoji) { return this.raw.createReaction(channelId, messageId, emoji); } async createStageInstance(options) { const data = await this.raw.createStageInstance(options); return new structures_1.StageInstance(this.client, data); } async createStoreApplicationAsset(applicationId, options) { const data = await this.raw.createStoreApplicationAsset(applicationId, options); data.application_id = applicationId; return new structures_1.StoreApplicationAsset(this.client, data); } createTeam(options = {}) { // make this an object? return this.raw.createTeam(options); } async createWebhook(channelId, options) { const data = await this.raw.createWebhook(channelId, options); return new structures_1.Webhook(this.client, data); } async crosspostMessage(channelId, messageId) { const data = await this.raw.crosspostMessage(channelId, messageId); if (this.client.channels.has(data.channel_id)) { const channel = this.client.channels.get(data.channel_id); if (channel.guildId) { data.guild_id = channel.guildId; } } const message = new structures_1.Message(this.client, data); this.client.messages.insert(message); return message; } deleteAccount(options) { return this.raw.deleteAccount(options); } deleteApplicationCommand(applicationId, commandId) { return this.raw.deleteApplicationCommand(applicationId, commandId); } deleteApplicationGuildCommand(applicationId, guildId, commandId) { return this.raw.deleteApplicationGuildCommand(applicationId, guildId, commandId); } async deleteChannel(channelId, options = {}) { const data = await this.raw.deleteChannel(channelId, options); let channel; if (this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); this.client.channels.delete(data.id); channel.merge(data); } else { channel = structures_1.createChannelFromData(this.client, data); } // go through each message and mark them as deleted or wait for the event? return channel; } deleteChannelOverwrite(channelId, overwriteId, options = {}) { return this.raw.deleteChannelOverwrite(channelId, overwriteId, options); } deleteConnection(platform, accountId) { return this.raw.deleteConnection(platform, accountId); } deleteGuild(guildId, options = {}) { // go through each message and mark them as deleted or wait for the event? return this.raw.deleteGuild(guildId, options); } deleteGuildEmoji(guildId, emojiId, options = {}) { return this.raw.deleteGuildEmoji(guildId, emojiId, options); } deleteGuildIntegration(guildId, integrationId, options = {}) { return this.raw.deleteGuildIntegration(guildId, integrationId, options); } deleteGuildPremiumSubscription(guildId, subscriptionId) { return this.raw.deleteGuildPremiumSubscription(guildId, subscriptionId); } deleteGuildRole(guildId, roleId, options = {}) { return this.raw.deleteGuildRole(guildId, roleId, options); } deleteGuildSticker(guildId, stickerId, options = {}) { return this.raw.deleteGuildSticker(guildId, stickerId, options); } deleteGuildTemplate(guildId, templateId) { return this.raw.deleteGuildTemplate(guildId, templateId); } async deleteInvite(code, options = {}) { const data = await this.raw.deleteInvite(code, options); return new structures_1.Invite(this.client, data); } deleteLobby(lobbyId) { return this.raw.deleteLobby(lobbyId); } deleteMeBillingPaymentSource(paymentSourceId) { return this.raw.deleteMeBillingPaymentSource(paymentSourceId); } deleteMeBillingSubscription(subscriptionId) { return this.raw.deleteMeBillingSubscription(subscriptionId); } async deleteMessage(channelId, messageId, options = {}) { const data = await this.raw.deleteMessage(channelId, messageId, options); if (this.client.messages.has(messageId)) { const message = this.client.messages.get(messageId); message.deleted = true; } this.client.gatewayHandler._componentHandler.delete(messageId); return data; } deleteOauth2Application(applicationId, options = {}) { return this.raw.deleteOauth2Application(applicationId, options); } deleteOauth2ApplicationAsset(applicationId, assetId) { return this.raw.deleteOauth2ApplicationAsset(applicationId, assetId); } deletePinnedMessage(channelId, messageId) { return this.raw.deletePinnedMessage(channelId, messageId); } deleteReactions(channelId, messageId) { return this.raw.deleteReactions(channelId, messageId); } deleteReactionsEmoji(channelId, messageId, emoji) { return this.raw.deleteReactionsEmoji(channelId, messageId, emoji); } deleteReaction(channelId, messageId, emoji, userId = '@me') { return this.raw.deleteReaction(channelId, messageId, emoji, userId); } deleteRelationship(userId) { return this.raw.deleteRelationship(userId); } deleteStageInstance(channelId) { return this.raw.deleteStageInstance(channelId); } deleteStoreApplicationAsset(applicationId, assetId) { return this.raw.deleteStoreApplicationAsset(applicationId, assetId); } deleteTeam(teamId, options = {}) { return this.raw.deleteTeam(teamId, options); } deleteWebhook(webhookId, options = {}) { return this.raw.deleteWebhook(webhookId, options); } deleteWebhookToken(webhookId, webhookToken, options = {}) { return this.raw.deleteWebhookToken(webhookId, webhookToken, options); } async deleteWebhookTokenMessage(webhookId, webhookToken, messageId) { const data = await this.raw.deleteWebhookTokenMessage(webhookId, webhookToken, messageId); if (this.client.messages.has(messageId)) { const message = this.client.messages.get(messageId); message.deleted = true; } this.client.gatewayHandler._componentHandler.delete(messageId); return data; } disableAccount(options) { return this.raw.disableAccount(options); } async editApplicationCommand(applicationId, commandId, options = {}) { const data = await this.raw.editApplicationCommand(applicationId, commandId, options); return new structures_1.ApplicationCommand(this.client, data); } async editApplicationGuildCommand(applicationId, guildId, commandId, options = {}) { const data = await this.raw.editApplicationGuildCommand(applicationId, guildId, commandId, options); return new structures_1.ApplicationCommand(this.client, data); } async editApplicationGuildCommandPermissions(applicationId, guildId, commandId, options) { const data = await this.raw.editApplicationGuildCommandPermissions(applicationId, guildId, commandId, options); return new structures_1.ApplicationCommandPermissions(this.client, data); } editApplicationNews(newsId, options = {}) { return this.raw.editApplicationNews(newsId, options); } /* Issue with merging data with these edited objects is that the gateway event wont have differences then */ async editChannel(channelId, options = {}, updateCache = true) { const data = await this.raw.editChannel(channelId, options); let channel; if (updateCache && this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); } else { channel = structures_1.createChannelFromData(this.client, data); // insert? nah } return channel; } editChannelOverwrite(channelId, overwriteId, options = {}) { return this.raw.editChannelOverwrite(channelId, overwriteId, options); } editConnection(platform, accountId, options = {}) { return this.raw.editConnection(platform, accountId, options); } async editGuild(guildId, options = {}, updateCache = true) { const data = await this.raw.editGuild(guildId, options); let guild; if (updateCache && this.client.guilds.has(data.id)) { guild = this.client.guilds.get(data.id); guild.merge(data); } else { guild = new structures_1.Guild(this.client, data); } return guild; } editGuildChannels(guildId, channels, options = {}) { return this.raw.editGuildChannels(guildId, channels, options); } editGuildEmbed(guildId, options) { return this.raw.editGuildEmbed(guildId, options); } async editGuildEmoji(guildId, emojiId, options = {}, updateCache = true) { const data = await this.raw.editGuildEmoji(guildId, emojiId, options); let emoji; if (updateCache && this.client.emojis.has(guildId, data.id)) { emoji = this.client.emojis.get(guildId, data.id); emoji.merge(data); } else { data.guild_id = guildId; emoji = new structures_1.Emoji(this.client, data); } return emoji; } editGuildIntegration(guildId, integrationId, options = {}) { return this.raw.editGuildIntegration(guildId, integrationId, options); } editGuildMember(guildId, userId, options = {}) { return this.raw.editGuildMember(guildId, userId, options); } editGuildMemberVerification(guildId, options = {}) { return this.raw.editGuildMemberVerification(guildId, options); } editGuildMfaLevel(guildId, options) { return this.raw.editGuildMfaLevel(guildId, options); } editGuildNick(guildId, nick, options = {}) { return this.raw.editGuildNick(guildId, nick, options); } async editGuildRole(guildId, roleId, options = {}, updateCache = true) { const data = await this.raw.editGuildRole(guildId, roleId, options); let role; if (updateCache && this.client.guilds.has(guildId)) { const guild = this.client.guilds.get(guildId); if (guild.roles.has(data.id)) { role = guild.roles.get(data.id); role.merge(data); } else { data.guild_id = guildId; role = new structures_1.Role(this.client, data); guild.roles.set(role.id, role); } } else { data.guild_id = guildId; role = new structures_1.Role(this.client, data); } return role; } async editGuildRolePositions(guildId, roles, options = {}, updateCache = true) { const data = await this.raw.editGuildRolePositions(guildId, roles, options); const collection = new basecollection_1.BaseCollection(); if (updateCache && this.client.guilds.has(guildId)) { const guild = this.client.guilds.get(guildId); guild.roles.clear(); for (let raw of data) { raw.guild_id = guildId; const role = new structures_1.Role(this.client, raw); guild.roles.set(role.id, role); collection.set(role.id, role); } } else { for (let raw of data) { raw.guild_id = guildId; const role = new structures_1.Role(this.client, raw); collection.set(role.id, role); } } return collection; } async editGuildSticker(guildId, stickerId, options = {}, updateCache = true) { const data = await this.raw.editGuildSticker(guildId, stickerId, options); guildId = data.guild_id; let sticker; if (updateCache && this.client.stickers.has(guildId, data.id)) { sticker = this.client.stickers.get(guildId, data.id); sticker.merge(data); } else { sticker = new structures_1.Sticker(this.client, data); } return sticker; } editGuildVanity(guildId, code, options = {}) { return this.raw.editGuildVanity(guildId, code, options); } editGuildVoiceState(guildId, userId, options) { return this.raw.editGuildVoiceState(guildId, userId, options); } editLobby(lobbyId, options = {}) { return this.raw.editLobby(lobbyId, options); } editLobbyMember(lobbyId, userId, options = {}) { return this.raw.editLobbyMember(lobbyId, userId, options); } async editMe(options = {}, updateCache = true) { const data = await this.raw.editMe(options); let user; if (updateCache && this.client.user !== null) { user = this.client.user; user.merge(data); } else { user = new structures_1.UserMe(this.client, data); } return user; } editMeBillingPaymentSource(paymentSourceId, options = {}) { return this.raw.editMeBillingPaymentSource(paymentSourceId, options); } editMeBillingSubscription(subscriptionId, options = {}) { return this.raw.editMeBillingSubscription(subscriptionId, options); } async editMessage(channelId, messageId, options = {}, updateCache = true) { const listenerData = utils_1.createComponentListenerOrNone(options); const data = await this.raw.editMessage(channelId, messageId, options); let message; if (updateCache && this.client.messages.has(data.id)) { message = this.client.messages.get(data.id); message.merge(data); // should we really merge? the message_update event wont have differences then } else { message = new structures_1.Message(this.client, data); this.client.messages.insert(message); } if (listenerData) { const [lId, listener] = listenerData; const listenerId = lId || message.id; if (listener) { listener.id = listenerId; this.client.gatewayHandler._componentHandler.insert(listener); } else { this.client.gatewayHandler._componentHandler.delete(listenerId); } } return message; } editNote(userId, note) { return this.raw.editNote(userId, note); } editOauth2Application(applicationId, options = {}) { return this.raw.editOauth2Application(applicationId, options); } editRelationship(userId, type) { return this.raw.editRelationship(userId, type); } editStageInstance(channelId, options = {}) { return this.raw.editStageInstance(channelId, options); } editSettings(options = {}) { return this.raw.editSettings(options); } async editTeam(teamId, options = {}) { return this.raw.editTeam(teamId, options); } async editUser(options = {}) { return this.editMe(options); } async editWebhook(webhookId, options = {}) { const data = await this.raw.editWebhook(webhookId, options); return new structures_1.Webhook(this.client, data); } async editWebhookToken(webhookId, webhookToken, options = {}) { const data = await this.raw.editWebhookToken(webhookId, webhookToken, options); return new structures_1.Webhook(this.client, data); } async editWebhookTokenMessage(webhookId, webhookToken, messageId, options = {}, updateCache = true) { const listenerData = utils_1.createComponentListenerOrNone(options); const data = await this.raw.editWebhookTokenMessage(webhookId, webhookToken, messageId, options); let message; if (updateCache && this.client.messages.has(data.id)) { message = this.client.messages.get(data.id); message.merge(data); } else { message = new structures_1.Message(this.client, data); this.client.messages.insert(message); } if (message.interaction) { this.client.gatewayHandler._componentHandler.replaceId(message.interaction.id, message.id); } if (listenerData) { const [lId, listener] = listenerData; const listenerId = lId || message.id; if (listener) { listener.id = listenerId; this.client.gatewayHandler._componentHandler.insert(listener); } else { this.client.gatewayHandler._componentHandler.delete(listenerId); } } return message; } enableOauth2ApplicationAssets(applicationId) { return this.raw.enableOauth2ApplicationAssets(applicationId); } enableOauth2ApplicationRpc(applicationId) { return this.raw.enableOauth2ApplicationRpc(applicationId); } async executeWebhook(webhookId, webhookToken, options = {}, compatibleType) { const listenerData = utils_1.createComponentListenerOrNone(options); const data = await this.raw.executeWebhook(webhookId, webhookToken, options, compatibleType); if (data) { const message = new structures_1.Message(this.client, data); this.client.messages.insert(message); if (listenerData) { const [lId, listener] = listenerData; const listenerId = lId || message.id; if (listener) { listener.id = listenerId; this.client.gatewayHandler._componentHandler.insert(listener); } else { this.client.gatewayHandler._componentHandler.delete(listenerId); } } return message; } if (listenerData) { const [lId, listener] = listenerData; if (listener) { listener.id = lId || detritus_utils_1.Snowflake.generate().id; this.client.gatewayHandler._componentHandler.insert(listener); } } return data; } fetchActivities() { return this.raw.fetchActivities(); } async fetchApplicationCommands(applicationId) { const data = await this.raw.fetchApplicationCommands(applicationId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const command = new structures_1.ApplicationCommand(this.client, raw); collection.set(command.id, command); } return collection; } async fetchApplicationCommand(applicationId, commandId) { const data = await this.raw.fetchApplicationCommand(applicationId, commandId); return new structures_1.ApplicationCommand(this.client, data); } async fetchApplicationGuildCommands(applicationId, guildId) { const data = await this.raw.fetchApplicationGuildCommands(applicationId, guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const command = new structures_1.ApplicationCommand(this.client, raw); collection.set(command.id, command); } return collection; } async fetchApplicationGuildCommandsPermissions(applicationId, guildId) { const data = await this.raw.fetchApplicationGuildCommandsPermissions(applicationId, guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const commandPermissions = new structures_1.ApplicationCommandPermissions(this.client, raw); collection.set(commandPermissions.id, commandPermissions); } return collection; } async fetchApplicationGuildCommand(applicationId, guildId, commandId) { const data = await this.raw.fetchApplicationGuildCommand(applicationId, guildId, commandId); return new structures_1.ApplicationCommand(this.client, data); } async fetchApplicationGuildCommandPermissions(applicationId, guildId, commandId) { const data = await this.raw.fetchApplicationGuildCommandPermissions(applicationId, guildId, commandId); return new structures_1.ApplicationCommandPermissions(this.client, data); } async fetchApplicationNews(applicationIds) { const data = await this.raw.fetchApplicationNews(applicationIds); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const applicationNews = new structures_1.ApplicationNews(this.client, raw); collection.set(applicationNews.id, applicationNews); } return collection; } async fetchApplicationNewsId(newsId) { const data = await this.raw.fetchApplicationNewsId(newsId); return new structures_1.ApplicationNews(this.client, data); } fetchApplications() { return this.raw.fetchApplications(); } async fetchApplication(applicationId) { const data = await this.raw.fetchApplication(applicationId); return new structures_1.Application(this.client, data); } async fetchApplicationsDetectable() { const data = await this.raw.fetchApplicationsDetectable.call(this); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const application = new structures_1.Application(this.client, raw); collection.set(application.id, application); } return collection; } fetchApplicationsPublic(applicationIds) { return this.raw.fetchApplicationsPublic(applicationIds); } fetchApplicationsTrendingGlobal() { return this.raw.fetchApplicationsTrendingGlobal(); } fetchAuthConsentRequired() { return this.raw.fetchAuthConsentRequired(); } async fetchChannel(channelId, updateCache = true) { const data = await this.raw.fetchChannel(channelId); let channel; if (updateCache && this.client.channels.has(data.id)) { channel = this.client.channels.get(data.id); channel.merge(data); } else { channel = structures_1.createChannelFromData(this.client, data); } return channel; } fetchChannelCall(channelId) { return this.raw.fetchChannelCall(channelId); } async fetchChannelInvites(channelId) { const data = await this.raw.fetchChannelInvites(channelId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const invite = new structures_1.Invite(this.client, raw); collection.set(invite.code, invite); } return collection; } async fetchChannelStoreListing(channelId) { const data = await this.raw.fetchChannelStoreListing(channelId); return new structures_1.StoreListing(this.client, data); } async fetchChannelThreadsActive(channelId) { const data = await this.raw.fetchChannelThreadsActive(channelId); const hasMore = data['has_more']; const members = new basecollection_1.BaseCollection(); const threads = new basecollection_1.BaseCollection(); for (let raw of data.members) { const threadMember = new structures_1.ThreadMember(this.client, raw); let collection; if (members.has(threadMember.id)) { collection = members.get(threadMember.id); } else { collection = new basecollection_1.BaseCollection(); } collection.set(threadMember.userId, threadMember); } for (let raw of data.threads) { const thread = structures_1.createChannelFromData(this.client, raw); threads.set(thread.id, thread); } return { hasMore, members, threads }; } async fetchChannelThreadsArchivedPrivate(channelId, options = {}) { const data = await this.raw.fetchChannelThreadsArchivedPrivate(channelId, options); const hasMore = data['has_more']; const members = new basecollection_1.BaseCollection(); const threads = new basecollection_1.BaseCollection(); for (let raw of data.members) { const threadMember = new structures_1.ThreadMember(this.client, raw); let collection; if (members.has(threadMember.id)) { collection = members.get(threadMember.id); } else { collection = new basecollection_1.BaseCollection(); } collection.set(threadMember.userId, threadMember); } for (let raw of data.threads) { const thread = structures_1.createChannelFromData(this.client, raw); threads.set(thread.id, thread); } return { hasMore, members, threads }; } async fetchChannelThreadsArchivedPrivateJoined(channelId, options = {}) { const data = await this.raw.fetchChannelThreadsArchivedPrivateJoined(channelId, options); const hasMore = data['has_more']; const members = new basecollection_1.BaseCollection(); const threads = new basecollection_1.BaseCollection(); for (let raw of data.members) { const threadMember = new structures_1.ThreadMember(this.client, raw); let collection; if (members.has(threadMember.id)) { collection = members.get(threadMember.id); } else { collection = new basecollection_1.BaseCollection(); } collection.set(threadMember.userId, threadMember); } for (let raw of data.threads) { const thread = structures_1.createChannelFromData(this.client, raw); threads.set(thread.id, thread); } return { hasMore, members, threads }; } async fetchChannelThreadsArchivedPublic(channelId, options = {}) { const data = await this.raw.fetchChannelThreadsArchivedPublic(channelId, options); const hasMore = data['has_more']; const members = new basecollection_1.BaseCollection(); const threads = new basecollection_1.BaseCollection(); for (let raw of data.members) { const threadMember = new structures_1.ThreadMember(this.client, raw); let collection; if (members.has(threadMember.id)) { collection = members.get(threadMember.id); } else { collection = new basecollection_1.BaseCollection(); } collection.set(threadMember.userId, threadMember); } for (let raw of data.threads) { const thread = structures_1.createChannelFromData(this.client, raw); threads.set(thread.id, thread); } return { hasMore, members, threads }; } async fetchChannelWebhooks(channelId) { const data = await this.raw.fetchChannelWebhooks(channelId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const webhook = new structures_1.Webhook(this.client, raw); collection.set(webhook.id, webhook); } return collection; } fetchConsentRequired() { return this.raw.fetchConsentRequired(); } fetchConnectionAuthorizeUrl(platform) { return this.raw.fetchConnectionAuthorizeUrl(platform); } fetchDiscoverableGuilds() { return this.raw.fetchDiscoverableGuilds(); } async fetchDms(userId = '@me', updateCache = true) { const data = await this.raw.fetchDms(userId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let channel; if (updateCache && this.client.channels.has(raw.id)) { channel = this.client.channels.get(raw.id); channel.merge(raw); } else { channel = structures_1.createChannelFromData(this.client, raw); } collection.set(channel.id, channel); } return collection; } fetchExperiments(fingerprint) { return this.raw.fetchExperiments(fingerprint); } fetchGateway() { return this.raw.fetchGateway(); } fetchGatewayBot() { return this.raw.fetchGatewayBot(); } async fetchGiftCode(code, options = {}) { const data = await this.raw.fetchGiftCode(code, options); return new structures_1.Gift(this.client, data); } async fetchGuild(guildId, options = {}, updateCache = true) { const data = await this.raw.fetchGuild(guildId, options); let guild; if (updateCache && this.client.guilds.has(data.id)) { guild = this.client.guilds.get(data.id); guild.merge(data); } else { guild = new structures_1.Guild(this.client, data, true); } guild.hasMetadata = true; return guild; } fetchGuildApplications(guildId, channelId) { return this.raw.fetchGuildApplications(guildId, channelId); } async fetchGuildAuditLogs(guildId, options = {}) { const data = await this.raw.fetchGuildAuditLogs(guildId, options); const collection = new basecollection_1.BaseCollection(); for (let raw of data.audit_log_entries) { let target = null; if (this.client.users.has(raw.target_id)) { target = this.client.users.get(raw.target_id); // target.merge(data.users.find((user) => user.id === raw.target_id)); } else { let rawTarget = data.users.find((user) => user.id === raw.target_id); if (rawTarget !== undefined) { target = new structures_1.User(this.client, rawTarget); } else { rawTarget = data.webhooks.find((webhook) => webhook.id === raw.target_id); if (rawTarget !== undefined) { target = new structures_1.Webhook(this.client, rawTarget); } } } let user = null; if (this.client.users.has(raw.user_id)) { user = this.client.users.get(raw.user_id); } else { const rawUser = data.users.find((u) => u.id === raw.user_id); if (rawUser !== undefined) { user = new structures_1.User(this.client, rawUser); } } raw.guild_id = guildId; raw.target = target; raw.user = user; const auditLog = new structures_1.AuditLog(this.client, raw); collection.set(auditLog.id, auditLog); } return collection; } async fetchGuildBans(guildId) { const data = await this.raw.fetchGuildBans(guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let user; if (this.client.users.has(raw.user.id)) { user = this.client.users.get(raw.user.id); user.merge(raw.user); } else { user = new structures_1.User(this.client, raw.user); } collection.set(user.id, { reason: raw.reason, user, }); } return collection; } async fetchGuildChannels(guildId) { const data = await this.raw.fetchGuildChannels(guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let channel; if (this.client.channels.has(raw.id)) { channel = this.client.channels.get(raw.id); channel.merge(raw); } else { channel = structures_1.createChannelFromData(this.client, raw); } collection.set(channel.id, channel); } return collection; } fetchGuildEmbed(guildId) { return this.raw.fetchGuildEmbed(guildId); } async fetchGuildEmojis(guildId) { const data = await this.raw.fetchGuildEmojis(guildId); if (this.client.emojis.enabled && this.client.guilds.has(guildId)) { const guild = this.client.guilds.get(guildId); guild.merge({ emojis: data }); return guild.emojis; } else { const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let emoji; if (this.client.emojis.has(guildId, raw.id)) { emoji = this.client.emojis.get(guildId, raw.id); emoji.merge(raw); } else { raw.guild_id = guildId; emoji = new structures_1.Emoji(this.client, raw); } collection.set(emoji.id || emoji.name, emoji); } return collection; } } async fetchGuildEmoji(guildId, emojiId) { const data = await this.raw.fetchGuildEmoji(guildId, emojiId); let emoji; if (this.client.emojis.has(guildId, data.id)) { emoji = this.client.emojis.get(guildId, data.id); emoji.merge(data); } else { data.guild_id = guildId; emoji = new structures_1.Emoji(this.client, data); } return emoji; } async fetchGuildIntegrations(guildId) { const data = await this.raw.fetchGuildIntegrations(guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { raw.guild_id = guildId; const integration = new structures_1.Integration(this.client, raw); collection.set(integration.id, integration); } return collection; } async fetchGuildInvites(guildId) { const data = await this.raw.fetchGuildInvites(guildId); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { const invite = new structures_1.Invite(this.client, raw); collection.set(invite.code, invite); } return collection; } async fetchGuildMember(guildId, userId) { const data = await this.raw.fetchGuildMember(guildId, userId); let member; if (this.client.members.has(guildId, userId)) { member = this.client.members.get(guildId, userId); member.merge(data); } else { data.guild_id = guildId; member = new structures_1.Member(this.client, data); this.client.members.insert(member); } return member; } async fetchGuildMembers(guildId, options = {}) { const data = await this.raw.fetchGuildMembers(guildId, options); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let member; if (this.client.members.has(guildId, raw.user.id)) { member = this.client.members.get(guildId, raw.user.id); member.merge(raw); } else { raw.guild_id = guildId; member = new structures_1.Member(this.client, raw); this.client.members.insert(member); } collection.set(member.id, member); } return collection; } async fetchGuildMembersSearch(guildId, options) { const data = await this.raw.fetchGuildMembersSearch(guildId, options); const collection = new basecollection_1.BaseCollection(); for (let raw of data) { let member; if (this.client.members.has(guildId, raw.user.id)) { member = this.client.members.get(guildId, raw.user.id); member.merge(raw); } else { raw.guild_id = guildId; member = new structures_1.Member(this.client, raw); this.client.members.insert(member);