diff --git a/package.json b/package.json index 1c0a7ae..5fde4fc 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "axios": "^0.27.2", "bignumber.js": "^9.1.0", "chalk": "^4.1.2", - "discord-api-types": "^0.37.1", + "discord-api-types": "^0.37.2", "form-data": "^4.0.0", "json-bigint": "^1.0.0", "node-fetch": "^2.6.1", @@ -81,7 +81,7 @@ "@types/node": "^16.11.12", "conventional-changelog-cli": "^2.2.2", "dtslint": "^4.2.1", - "eslint": "^8.21.0", + "eslint": "^8.22.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.25.3", "eslint-plugin-prettier": "^4.0.0", diff --git a/src/client/Client.js b/src/client/Client.js index 6f45858..81bfbe4 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -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'); + } } /** diff --git a/src/managers/UserManager.js b/src/managers/UserManager.js index 1a8ae31..a5c6eec 100644 --- a/src/managers/UserManager.js +++ b/src/managers/UserManager.js @@ -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; } diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index 88c2913..8081fe8 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -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} + * @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); diff --git a/src/structures/PartialGroupDMChannel.js b/src/structures/PartialGroupDMChannel.js index 0a7d5ac..b9bc5d7 100644 --- a/src/structures/PartialGroupDMChannel.js +++ b/src/structures/PartialGroupDMChannel.js @@ -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} + * @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); diff --git a/typings/index.d.ts b/typings/index.d.ts index 8509bd3..bd2a829 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -796,6 +796,8 @@ export class Client extends BaseClient { public setting: ClientUserSettingManager; public relationships: RelationshipsManager; public updateCookie(): Promise; + public readonly callVoice?: VoiceConnection; + public voiceStates: VoiceStateManager; // End public channels: ChannelManager; public readonly emojis: BaseGuildEmojiManager; @@ -828,7 +830,6 @@ export class Client extends BaseClient { public QRLogin(debug?: boolean): DiscordAuthWebsocket; public remoteAuth(url: string, forceAccept?: boolean): Promise; public createToken(): Promise; - public readonly callVoice: VoiceConnection | undefined; public isReady(): this is Client; /** @deprecated Use {@link Sweepers#sweepMessages} instead */ public sweepMessages(lifetime?: number): number; @@ -1158,7 +1159,10 @@ export class DMChannel extends TextBasedChannelMixin(Channel, [ public fetch(force?: boolean): Promise; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public call(options?: object): Promise; + public sync(): undefined; public readonly shard: WebSocketShard; + public readonly voiceUsers: Collection; + public readonly voiceConnection?: VoiceConnection; } export class Emoji extends Base { @@ -2323,7 +2327,10 @@ export class PartialGroupDMChannel extends TextBasedChannelMixin(Channel, [ public removeInvite(invite: Invite): Promise; public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator; public call(options?: object): Promise; + public sync(): undefined; public readonly shard: WebSocketShard; + public readonly voiceUsers: Collection; + public readonly voiceConnection?: VoiceConnection; } export class PermissionOverwrites extends Base {