From 842efd9ac21892c028ab348dd26d47a50fcd88b3 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:28:27 +0700 Subject: [PATCH] feat: Ringing specific users #895 --- src/structures/DMChannel.js | 21 +++++++++++++++------ src/structures/PartialGroupDMChannel.js | 16 ++++++++++++++++ src/structures/User.js | 19 ++++++------------- typings/index.d.ts | 5 ++++- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index e4b37d7..748dc70 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -154,7 +154,7 @@ class DMChannel extends Channel { // Doesn't work on DM channels; setRateLimitPerUser() {} // Doesn't work on DM channels; setNSFW() {} // Testing feature: Call - // URL: https://discord.com/api/v9/channels/DMchannelId/call/ring + // URL: https://discord.com/api/v9/channels/:DMchannelId/call/ring /** * Call this DMChannel. Return discordjs/voice VoiceConnection * @param {CallOptions} options Options for the call @@ -177,11 +177,7 @@ class DMChannel extends Channel { ); } else { if (options.ring) { - this.client.api.channels(this.id).call.ring.post({ - data: { - recipients: null, - }, - }); + this.ring(); } const connection = joinVoiceChannel({ channelId: this.id, @@ -201,6 +197,19 @@ class DMChannel extends Channel { } }); } + + /** + * Ring the user's phone / PC (call) + * @returns {Promise} + */ + ring() { + return this.client.api.channels(this.id).call.ring.post({ + data: { + recipients: null, + }, + }); + } + /** * Sync VoiceState of this DMChannel. * @returns {undefined} diff --git a/src/structures/PartialGroupDMChannel.js b/src/structures/PartialGroupDMChannel.js index b48a30d..0545b1a 100644 --- a/src/structures/PartialGroupDMChannel.js +++ b/src/structures/PartialGroupDMChannel.js @@ -354,6 +354,22 @@ class PartialGroupDMChannel extends Channel { } }); } + + /** + * Ring the user's phone / PC (call) + * @param {UserResolvable[]} recipients Array of recipients + * @returns {Promise} + */ + ring(recipients) { + if (!recipients || !Array.isArray(recipients) || recipients.length == 0) recipients = null; + recipients = recipients.map(r => this.client.users.resolveId(r)).filter(r => r && this.recipients.get(r)); + return this.client.api.channels(this.id).call.ring.post({ + data: { + recipients, + }, + }); + } + /** * Sync VoiceState of this Group DMChannel. * @returns {undefined} diff --git a/src/structures/User.js b/src/structures/User.js index 5914ae7..4164bb1 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -517,25 +517,18 @@ class User extends Base { /** * Ring the user's phone / PC (call) - * @returns {Promise} + * @returns {Promise} + * @deprecated */ ring() { if (this.relationships !== 'FRIEND') return Promise.reject(new Error('USER_NOT_FRIEND')); if (!this.client.user.voice?.channelId || !this.client.callVoice) { return Promise.reject(new Error('CLIENT_NO_CALL')); } - return new Promise((resolve, reject) => { - this.client.api - .channels(this.dmChannel.id) - .call.ring.post({ - data: { - recipients: [this.id], - }, - }) - .then(() => resolve(true)) - .catch(e => { - reject(e); - }); + return this.client.api.channels(this.dmChannel.id).call.ring.post({ + data: { + recipients: [this.id], + }, }); } diff --git a/typings/index.d.ts b/typings/index.d.ts index e110961..1310052 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1337,6 +1337,7 @@ export class DMChannel extends TextBasedChannelMixin(Channel, [ public fetch(force?: boolean): Promise; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public call(options?: CallOptions): Promise; + public ring(): Promise; public sync(): undefined; public readonly shard: WebSocketShard; public readonly voiceUsers: Collection; @@ -2598,6 +2599,7 @@ export class PartialGroupDMChannel extends TextBasedChannelMixin(Channel, [ public setOwner(user: UserResolvable): Promise; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public call(options?: CallOptions): Promise; + public ring(recipients: UserResolvable[]): Promise; public sync(): undefined; public readonly shard: WebSocketShard; public readonly voiceUsers: Collection; @@ -3302,7 +3304,8 @@ export class User extends PartialTextBasedChannel(Base) { public getProfile(guildId?: Snowflake): Promise; public setNickname(nickname: string | null): Promise; public toString(): UserMention; - public ring(): Promise; + /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ + public ring(): Promise; public themeColors?: [number, number]; public readonly hexThemeColor: [string, string] | null; }