feat(Call): Get users in dm call
This commit is contained in:
parent
a24f29b802
commit
bb24adc1dc
@ -61,7 +61,7 @@
|
|||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"bignumber.js": "^9.1.0",
|
"bignumber.js": "^9.1.0",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"discord-api-types": "^0.37.1",
|
"discord-api-types": "^0.37.2",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"json-bigint": "^1.0.0",
|
"json-bigint": "^1.0.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
@ -81,7 +81,7 @@
|
|||||||
"@types/node": "^16.11.12",
|
"@types/node": "^16.11.12",
|
||||||
"conventional-changelog-cli": "^2.2.2",
|
"conventional-changelog-cli": "^2.2.2",
|
||||||
"dtslint": "^4.2.1",
|
"dtslint": "^4.2.1",
|
||||||
"eslint": "^8.21.0",
|
"eslint": "^8.22.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
|
@ -118,6 +118,10 @@ class Client extends BaseClient {
|
|||||||
*/
|
*/
|
||||||
this.voice = new ClientVoiceManager(this);
|
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 });
|
this.voiceStates = new VoiceStateManager({ client: this });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,6 +244,10 @@ class Client extends BaseClient {
|
|||||||
this.options.messageSweepInterval * 1_000,
|
this.options.messageSweepInterval * 1_000,
|
||||||
).unref();
|
).unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.options.intents) {
|
||||||
|
process.emitWarning('Intent is not available.', 'DeprecationWarning');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,6 @@ const { GuildMember } = require('../structures/GuildMember');
|
|||||||
const { Message } = require('../structures/Message');
|
const { Message } = require('../structures/Message');
|
||||||
const ThreadMember = require('../structures/ThreadMember');
|
const ThreadMember = require('../structures/ThreadMember');
|
||||||
const User = require('../structures/User');
|
const User = require('../structures/User');
|
||||||
const { Opcodes } = require('../util/Constants');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages API methods for users and stores their cache.
|
* 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 });
|
const dm_channel = await this.client.channels._add(data, null, { cache });
|
||||||
await this.client.ws.broadcast({
|
await dm_channel.sync();
|
||||||
op: Opcodes.DM_UPDATE,
|
|
||||||
d: {
|
|
||||||
channel_id: dm_channel.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return dm_channel;
|
return dm_channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Collection } = require('@discordjs/collection');
|
||||||
const { joinVoiceChannel, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
|
const { joinVoiceChannel, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
|
||||||
const { Channel } = require('./Channel');
|
const { Channel } = require('./Channel');
|
||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
const MessageManager = require('../managers/MessageManager');
|
const MessageManager = require('../managers/MessageManager');
|
||||||
const { Status } = require('../util/Constants');
|
const { Status, Opcodes } = require('../util/Constants');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a direct message channel between two users.
|
* 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() {
|
get shard() {
|
||||||
return this.client.ws.shards.first();
|
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() {
|
get voiceAdapterCreator() {
|
||||||
return methods => {
|
return methods => {
|
||||||
this.client.voice.adapters.set(this.id, methods);
|
this.client.voice.adapters.set(this.id, methods);
|
||||||
|
@ -7,7 +7,7 @@ const Invite = require('./Invite');
|
|||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
const { Error } = require('../errors');
|
const { Error } = require('../errors');
|
||||||
const MessageManager = require('../managers/MessageManager');
|
const MessageManager = require('../managers/MessageManager');
|
||||||
const { Status } = require('../util/Constants');
|
const { Status, Opcodes } = require('../util/Constants');
|
||||||
const DataResolver = require('../util/DataResolver');
|
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() {
|
get shard() {
|
||||||
return this.client.ws.shards.first();
|
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() {
|
get voiceAdapterCreator() {
|
||||||
return methods => {
|
return methods => {
|
||||||
this.client.voice.adapters.set(this.id, methods);
|
this.client.voice.adapters.set(this.id, methods);
|
||||||
|
9
typings/index.d.ts
vendored
9
typings/index.d.ts
vendored
@ -796,6 +796,8 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public setting: ClientUserSettingManager;
|
public setting: ClientUserSettingManager;
|
||||||
public relationships: RelationshipsManager;
|
public relationships: RelationshipsManager;
|
||||||
public updateCookie(): Promise<void>;
|
public updateCookie(): Promise<void>;
|
||||||
|
public readonly callVoice?: VoiceConnection;
|
||||||
|
public voiceStates: VoiceStateManager;
|
||||||
// End
|
// End
|
||||||
public channels: ChannelManager;
|
public channels: ChannelManager;
|
||||||
public readonly emojis: BaseGuildEmojiManager;
|
public readonly emojis: BaseGuildEmojiManager;
|
||||||
@ -828,7 +830,6 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public QRLogin(debug?: boolean): DiscordAuthWebsocket;
|
public QRLogin(debug?: boolean): DiscordAuthWebsocket;
|
||||||
public remoteAuth(url: string, forceAccept?: boolean): Promise<remoteAuthConfrim | undefined>;
|
public remoteAuth(url: string, forceAccept?: boolean): Promise<remoteAuthConfrim | undefined>;
|
||||||
public createToken(): Promise<string>;
|
public createToken(): Promise<string>;
|
||||||
public readonly callVoice: VoiceConnection | undefined;
|
|
||||||
public isReady(): this is Client<true>;
|
public isReady(): this is Client<true>;
|
||||||
/** @deprecated Use {@link Sweepers#sweepMessages} instead */
|
/** @deprecated Use {@link Sweepers#sweepMessages} instead */
|
||||||
public sweepMessages(lifetime?: number): number;
|
public sweepMessages(lifetime?: number): number;
|
||||||
@ -1158,7 +1159,10 @@ 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?: object): Promise<VoiceConnection>;
|
public call(options?: object): Promise<VoiceConnection>;
|
||||||
|
public sync(): undefined;
|
||||||
public readonly shard: WebSocketShard;
|
public readonly shard: WebSocketShard;
|
||||||
|
public readonly voiceUsers: Collection<Snowflake, User>;
|
||||||
|
public readonly voiceConnection?: VoiceConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Emoji extends Base {
|
export class Emoji extends Base {
|
||||||
@ -2323,7 +2327,10 @@ export class PartialGroupDMChannel extends TextBasedChannelMixin(Channel, [
|
|||||||
public removeInvite(invite: Invite): Promise<PartialGroupDMChannel>;
|
public removeInvite(invite: Invite): Promise<PartialGroupDMChannel>;
|
||||||
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
|
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
|
||||||
public call(options?: object): Promise<VoiceConnection>;
|
public call(options?: object): Promise<VoiceConnection>;
|
||||||
|
public sync(): undefined;
|
||||||
public readonly shard: WebSocketShard;
|
public readonly shard: WebSocketShard;
|
||||||
|
public readonly voiceUsers: Collection<Snowflake, User>;
|
||||||
|
public readonly voiceConnection?: VoiceConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PermissionOverwrites extends Base {
|
export class PermissionOverwrites extends Base {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user