feat: Ringing specific users

#895
This commit is contained in:
Elysia 2023-10-29 13:28:27 +07:00
parent a25d839f99
commit 842efd9ac2
4 changed files with 41 additions and 20 deletions

View File

@ -154,7 +154,7 @@ class DMChannel extends Channel {
// Doesn't work on DM channels; setRateLimitPerUser() {} // Doesn't work on DM channels; setRateLimitPerUser() {}
// Doesn't work on DM channels; setNSFW() {} // Doesn't work on DM channels; setNSFW() {}
// Testing feature: Call // 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 * Call this DMChannel. Return discordjs/voice VoiceConnection
* @param {CallOptions} options Options for the call * @param {CallOptions} options Options for the call
@ -177,11 +177,7 @@ class DMChannel extends Channel {
); );
} else { } else {
if (options.ring) { if (options.ring) {
this.client.api.channels(this.id).call.ring.post({ this.ring();
data: {
recipients: null,
},
});
} }
const connection = joinVoiceChannel({ const connection = joinVoiceChannel({
channelId: this.id, channelId: this.id,
@ -201,6 +197,19 @@ class DMChannel extends Channel {
} }
}); });
} }
/**
* Ring the user's phone / PC (call)
* @returns {Promise<any>}
*/
ring() {
return this.client.api.channels(this.id).call.ring.post({
data: {
recipients: null,
},
});
}
/** /**
* Sync VoiceState of this DMChannel. * Sync VoiceState of this DMChannel.
* @returns {undefined} * @returns {undefined}

View File

@ -354,6 +354,22 @@ class PartialGroupDMChannel extends Channel {
} }
}); });
} }
/**
* Ring the user's phone / PC (call)
* @param {UserResolvable[]} recipients Array of recipients
* @returns {Promise<any>}
*/
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. * Sync VoiceState of this Group DMChannel.
* @returns {undefined} * @returns {undefined}

View File

@ -517,25 +517,18 @@ class User extends Base {
/** /**
* Ring the user's phone / PC (call) * Ring the user's phone / PC (call)
* @returns {Promise<boolean>} * @returns {Promise<any>}
* @deprecated
*/ */
ring() { ring() {
if (this.relationships !== 'FRIEND') return Promise.reject(new Error('USER_NOT_FRIEND')); if (this.relationships !== 'FRIEND') return Promise.reject(new Error('USER_NOT_FRIEND'));
if (!this.client.user.voice?.channelId || !this.client.callVoice) { if (!this.client.user.voice?.channelId || !this.client.callVoice) {
return Promise.reject(new Error('CLIENT_NO_CALL')); return Promise.reject(new Error('CLIENT_NO_CALL'));
} }
return new Promise((resolve, reject) => { return this.client.api.channels(this.dmChannel.id).call.ring.post({
this.client.api data: {
.channels(this.dmChannel.id) recipients: [this.id],
.call.ring.post({ },
data: {
recipients: [this.id],
},
})
.then(() => resolve(true))
.catch(e => {
reject(e);
});
}); });
} }

5
typings/index.d.ts vendored
View File

@ -1337,6 +1337,7 @@ export class DMChannel extends TextBasedChannelMixin(Channel, [
public fetch(force?: boolean): Promise<this>; public fetch(force?: boolean): Promise<this>;
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
public call(options?: CallOptions): Promise<VoiceConnection>; public call(options?: CallOptions): Promise<VoiceConnection>;
public ring(): Promise<any>;
public sync(): undefined; public sync(): undefined;
public readonly shard: WebSocketShard; public readonly shard: WebSocketShard;
public readonly voiceUsers: Collection<Snowflake, User>; public readonly voiceUsers: Collection<Snowflake, User>;
@ -2598,6 +2599,7 @@ export class PartialGroupDMChannel extends TextBasedChannelMixin(Channel, [
public setOwner(user: UserResolvable): Promise<PartialGroupDMChannel>; public setOwner(user: UserResolvable): Promise<PartialGroupDMChannel>;
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
public call(options?: CallOptions): Promise<VoiceConnection>; public call(options?: CallOptions): Promise<VoiceConnection>;
public ring(recipients: UserResolvable[]): Promise<any>;
public sync(): undefined; public sync(): undefined;
public readonly shard: WebSocketShard; public readonly shard: WebSocketShard;
public readonly voiceUsers: Collection<Snowflake, User>; public readonly voiceUsers: Collection<Snowflake, User>;
@ -3302,7 +3304,8 @@ export class User extends PartialTextBasedChannel(Base) {
public getProfile(guildId?: Snowflake): Promise<User>; public getProfile(guildId?: Snowflake): Promise<User>;
public setNickname(nickname: string | null): Promise<boolean>; public setNickname(nickname: string | null): Promise<boolean>;
public toString(): UserMention; public toString(): UserMention;
public ring(): Promise<boolean>; /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */
public ring(): Promise<any>;
public themeColors?: [number, number]; public themeColors?: [number, number];
public readonly hexThemeColor: [string, string] | null; public readonly hexThemeColor: [string, string] | null;
} }