feat: new class Call
This commit is contained in:
56
src/structures/Call.js
Normal file
56
src/structures/Call.js
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Base = require('./Base');
|
||||
|
||||
/**
|
||||
* Represents a call
|
||||
* @extends {Base}
|
||||
*/
|
||||
class Call extends Base {
|
||||
constructor(client, data) {
|
||||
super(client);
|
||||
/**
|
||||
* The channel ID of the call
|
||||
* @type {Snowflake}
|
||||
*/
|
||||
this.channelId = data.channel_id;
|
||||
|
||||
/**
|
||||
* The list of user ID who is ringing
|
||||
* @type {Collection<Snowflake, User>}
|
||||
*/
|
||||
this.ringing = new Collection();
|
||||
}
|
||||
_patch(data) {
|
||||
if ('region' in data) {
|
||||
/**
|
||||
* The region of the call
|
||||
* @type {string}
|
||||
*/
|
||||
this.region = data.region;
|
||||
}
|
||||
if ('ringing' in data) {
|
||||
for (const userId of data.ringing) {
|
||||
this.ringing.set(userId, this.client.users.cache.get(userId));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The channel of the call
|
||||
* @type {?DMChannel|PartialGroupDMChannel}
|
||||
*/
|
||||
get channel() {
|
||||
return this.client.channels.cache.get(this.channelId);
|
||||
}
|
||||
/**
|
||||
* Sets the voice region of the call
|
||||
* @param {string} region Region of the call
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
setVoiceRegion(region) {
|
||||
return this.client.api.channels(this.channelId).call.patch({ data: { region } });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Call;
|
@@ -563,6 +563,19 @@ class ClientUser extends User {
|
||||
else this._packageName = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop ringing
|
||||
* @param {ChannelResolvable} channel DMChannel | GroupDMChannel
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
stopRinging(channel) {
|
||||
const id = this.client.channels.resolveId(channel);
|
||||
if (!channel) return false;
|
||||
return this.client.api.channels(id).call['stop-ringing'].post({
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientUser;
|
||||
|
@@ -471,7 +471,7 @@ class User extends Base {
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
ring() {
|
||||
if (!this.dmChannel?.id) return Promise.reject(new Error('USER_NO_DM_CHANNEL'));
|
||||
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'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user