From 817aa690ff6910aa8bd810f77faa0bc63aec2a3a Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:28:45 +0700 Subject: [PATCH] Adding feature voiceState.getPreview(): Return URL Image Stream .-. --- src/errors/Messages.js | 1 + src/rest/APIRequest.js | 4 ++-- src/structures/DMChannel.js | 15 +++++++++++++++ src/structures/VoiceState.js | 13 +++++++++++++ typings/index.d.ts | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 398218f..a8b45ae 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -170,6 +170,7 @@ const Messages = { MESSAGE_ID_NOT_FOUND: 'Message ID not found', MESSAGE_EMBED_LINK_LENGTH: 'Message content with embed link length is too long', GUILD_MEMBERS_FETCH: msg => `${msg}`, + USER_NOT_STREAMING: 'User is not streaming', }; for (const [name, message] of Object.entries(Messages)) register(name, message); diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 73e2cca..7853928 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -63,8 +63,8 @@ class APIRequest { } headers = Object.assign(headers, body.getHeaders()); // eslint-disable-next-line eqeqeq - } else if (this.options.data != null) { - body = JSON.stringify(this.options.data); + } else if (this.options.data != null || this.options.usingApplicationJson) { + body = this.options.data ? JSON.stringify(this.options.data) : undefined; headers['Content-Type'] = 'application/json'; } else if (this.options.body != null) { body = new FormData(); diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index 555de4f..7466332 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -94,6 +94,21 @@ class DMChannel extends Channel { createMessageComponentCollector() {} awaitMessageComponent() {} // Doesn't work on DM channels; bulkDelete() {} + // Testing feature: Call + // URL: https://discord.com/api/v9/channels/DMchannelId/call/ring + /** + * Call this DMChannel. [TEST only] + * @returns {Promise} + */ + call() { + console.log('TEST only, and not working !'); + return this.client.api.channels(this.id).call.ring.post({ + usingApplicationJson: true, + data: { + recipients: null, + }, + }); + } } TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete']); diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index 78d9bf5..7bf4281 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -259,6 +259,19 @@ class VoiceState extends Base { }); } + /** + * Get URL Image of the user's streaming video (NOT STREAMING !!!) + * @returns {string} URL Image of the user's streaming video + */ + async getPreview() { + if (!this.streaming) throw new Error('USER_NOT_STREAMING'); + // URL: https://discord.com/api/v9/streams/guild:guildid:voicechannelid:userid/preview + const data = await this.client.api.streams[ + `guild%3A${this.guild.id}%3A${this.channelId}%3A${this.id}` + ].preview.get(); + return data.url; + } + toJSON() { return super.toJSON({ id: true, diff --git a/typings/index.d.ts b/typings/index.d.ts index c997d86..6bb4e5c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2631,6 +2631,7 @@ export class VoiceState extends Base { public setChannel(channel: GuildVoiceChannelResolvable | null, reason?: string): Promise; public setRequestToSpeak(request?: boolean): Promise; public setSuppressed(suppressed?: boolean): Promise; + public getPreview(): Promise; } export class Webhook extends WebhookMixin() {