feat(Call): Get users in dm call

This commit is contained in:
March 7th
2022-08-14 17:16:51 +07:00
parent a24f29b802
commit bb24adc1dc
6 changed files with 118 additions and 12 deletions

View File

@@ -118,6 +118,10 @@ class Client extends BaseClient {
*/
this.voice = new ClientVoiceManager(this);
/**
* A manager of the voice states of this client (Support DM / Group DM)
* @type {VoiceStateManager}
*/
this.voiceStates = new VoiceStateManager({ client: this });
/**
@@ -240,6 +244,10 @@ class Client extends BaseClient {
this.options.messageSweepInterval * 1_000,
).unref();
}
if (this.options.intents) {
process.emitWarning('Intent is not available.', 'DeprecationWarning');
}
}
/**

View File

@@ -5,7 +5,6 @@ const { GuildMember } = require('../structures/GuildMember');
const { Message } = require('../structures/Message');
const ThreadMember = require('../structures/ThreadMember');
const User = require('../structures/User');
const { Opcodes } = require('../util/Constants');
/**
* Manages API methods for users and stores their cache.
@@ -65,12 +64,7 @@ class UserManager extends CachedManager {
},
});
const dm_channel = await this.client.channels._add(data, null, { cache });
await this.client.ws.broadcast({
op: Opcodes.DM_UPDATE,
d: {
channel_id: dm_channel.id,
},
});
await dm_channel.sync();
return dm_channel;
}

View File

@@ -1,10 +1,11 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const { joinVoiceChannel, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
const { Channel } = require('./Channel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const MessageManager = require('../managers/MessageManager');
const { Status } = require('../util/Constants');
const { Status, Opcodes } = require('../util/Constants');
/**
* Represents a direct message channel between two users.
@@ -135,9 +136,57 @@ class DMChannel extends Channel {
});
});
}
/**
* Sync VoiceState of this DMChannel.
* @returns {undefined}
*/
sync() {
this.client.ws.broadcast({
op: Opcodes.DM_UPDATE,
d: {
channel_id: this.id,
},
});
}
/**
* The user in this voice-based channel
* @type {Collection<Snowflake, User>}
* @readonly
*/
get voiceUsers() {
const coll = new Collection();
for (const state of this.client.voiceStates.cache.values()) {
if (state.channelId === this.id && state.user) {
coll.set(state.id, state.user);
}
}
return coll;
}
/**
* Get connection to current call
* @type {?VoiceConnection}
* @readonly
*/
get voiceConnection() {
const check = this.client.callVoice?.joinConfig?.channelId == this.id;
if (check) {
return this.client.callVoice;
}
return null;
}
/**
* Get current shard
* @type {WebSocketShard}
* @readonly
*/
get shard() {
return this.client.ws.shards.first();
}
/**
* The voice state adapter for this client that can be used with @discordjs/voice to play audio in DM / Group DM channels.
* @type {?Function}
* @readonly
*/
get voiceAdapterCreator() {
return methods => {
this.client.voice.adapters.set(this.id, methods);

View File

@@ -7,7 +7,7 @@ const Invite = require('./Invite');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors');
const MessageManager = require('../managers/MessageManager');
const { Status } = require('../util/Constants');
const { Status, Opcodes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
/**
@@ -279,9 +279,57 @@ class PartialGroupDMChannel extends Channel {
});
});
}
/**
* Sync VoiceState of this Group DMChannel.
* @returns {undefined}
*/
sync() {
this.client.ws.broadcast({
op: Opcodes.DM_UPDATE,
d: {
channel_id: this.id,
},
});
}
/**
* The user in this voice-based channel
* @type {Collection<Snowflake, User>}
* @readonly
*/
get voiceUsers() {
const coll = new Collection();
for (const state of this.client.voiceStates.cache.values()) {
if (state.channelId === this.id && state.user) {
coll.set(state.id, state.user);
}
}
return coll;
}
/**
* Get connection to current call
* @type {?VoiceConnection}
* @readonly
*/
get voiceConnection() {
const check = this.client.callVoice?.joinConfig?.channelId == this.id;
if (check) {
return this.client.callVoice;
}
return null;
}
/**
* Get current shard
* @type {WebSocketShard}
* @readonly
*/
get shard() {
return this.client.ws.shards.first();
}
/**
* The voice state adapter for this client that can be used with @discordjs/voice to play audio in DM / Group DM channels.
* @type {?Function}
* @readonly
*/
get voiceAdapterCreator() {
return methods => {
this.client.voice.adapters.set(this.id, methods);