Calling support (1)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
const process = require('node:process');
|
||||
const { setInterval, setTimeout } = require('node:timers');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { getVoiceConnection } = require('@discordjs/voice');
|
||||
const RichPresence = require('discord-rpc-contructor');
|
||||
const BaseClient = require('./BaseClient');
|
||||
const ActionsManager = require('./actions/ActionsManager');
|
||||
@@ -15,6 +16,7 @@ const ClientUserSettingManager = require('../managers/ClientUserSettingManager')
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const RelationshipsManager = require('../managers/RelationshipsManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientPresence = require('../structures/ClientPresence');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
@@ -113,6 +115,8 @@ class Client extends BaseClient {
|
||||
*/
|
||||
this.voice = new ClientVoiceManager(this);
|
||||
|
||||
this.voiceStates = new VoiceStateManager({ client: this });
|
||||
|
||||
/**
|
||||
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
||||
* @type {?ShardClientUtil}
|
||||
@@ -248,6 +252,15 @@ class Client extends BaseClient {
|
||||
return this.readyAt ? Date.now() - this.readyAt : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection to current call
|
||||
* @type {?VoiceConnection}
|
||||
* @readonly
|
||||
*/
|
||||
get callVoice() {
|
||||
return getVoiceConnection(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Cloudflare Cookie and Discord Fingerprint
|
||||
*/
|
||||
@@ -335,7 +348,6 @@ class Client extends BaseClient {
|
||||
* client.QRLogin();
|
||||
*/
|
||||
QRLogin(debug = false) {
|
||||
console.log(this.options);
|
||||
const QR = new DiscordAuthWebsocket(this, debug);
|
||||
this.emit(Events.DEBUG, `Preparing to connect to the gateway`, QR);
|
||||
return QR;
|
||||
|
@@ -29,6 +29,26 @@ class VoiceStateUpdate extends Action {
|
||||
client.voice.onVoiceStateUpdate(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||
* @event Client#voiceStateUpdate
|
||||
* @param {VoiceState} oldState The voice state before the update
|
||||
* @param {VoiceState} newState The voice state after the update
|
||||
*/
|
||||
client.emit(Events.VOICE_STATE_UPDATE, oldState, newState);
|
||||
} else {
|
||||
// Update the state
|
||||
const oldState =
|
||||
client.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState({ client }, { user_id: data.user_id });
|
||||
|
||||
const newState = client.voiceStates._add(data);
|
||||
|
||||
// Emit event
|
||||
if (data.user_id === client.user.id) {
|
||||
client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`);
|
||||
client.voice.onVoiceStateUpdate(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||
* @event Client#voiceStateUpdate
|
||||
|
@@ -24,19 +24,26 @@ class ClientVoiceManager {
|
||||
client.on(Events.SHARD_DISCONNECT, (_, shardId) => {
|
||||
for (const [guildId, adapter] of this.adapters.entries()) {
|
||||
if (client.guilds.cache.get(guildId)?.shardId === shardId) {
|
||||
adapter.destroy();
|
||||
// Because it has 1 shard => adapter.destroy();
|
||||
}
|
||||
adapter.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onVoiceServer(payload) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
||||
if (payload.guild_id) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
||||
} else {
|
||||
this.adapters.get(payload.channel_id)?.onVoiceServerUpdate(payload);
|
||||
}
|
||||
}
|
||||
|
||||
onVoiceStateUpdate(payload) {
|
||||
if (payload.guild_id && payload.session_id && payload.user_id === this.client.user?.id) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);
|
||||
} else if (payload.channel_id && payload.session_id && payload.user_id === this.client.user?.id) {
|
||||
this.adapters.get(payload.channel_id)?.onVoiceStateUpdate(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
let ClientUser;
|
||||
const { VoiceConnection, VoiceConnectionStatus } = require('@discordjs/voice');
|
||||
const axios = require('axios');
|
||||
const chalk = require('chalk');
|
||||
const Discord = require('../../../index');
|
||||
const { Events, Opcodes } = require('../../../util/Constants');
|
||||
const { Networking } = require('../../../util/Voice');
|
||||
|
||||
async function checkUpdate() {
|
||||
const res_ = await axios.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`);
|
||||
@@ -29,9 +31,42 @@ module.exports = (client, { d: data }, shard) => {
|
||||
try {
|
||||
checkUpdate();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
console.log(`${chalk.redBright('[Fail]')} Check Update error:`, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (client.options.patchVoice) {
|
||||
/* eslint-disable */
|
||||
VoiceConnection.prototype.configureNetworking = function () {
|
||||
const { server, state } = this.packets;
|
||||
if (!server || !state || this.state.status === VoiceConnectionStatus.Destroyed || !server.endpoint) return;
|
||||
const networking = new Networking(
|
||||
{
|
||||
endpoint: server.endpoint,
|
||||
serverId: server.guild_id ?? server.channel_id,
|
||||
token: server.token,
|
||||
sessionId: state.session_id,
|
||||
userId: state.user_id,
|
||||
},
|
||||
Boolean(this.debug),
|
||||
);
|
||||
networking.once('close', this.onNetworkingClose);
|
||||
networking.on('stateChange', this.onNetworkingStateChange);
|
||||
networking.on('error', this.onNetworkingError);
|
||||
networking.on('debug', this.onNetworkingDebug);
|
||||
this.state = {
|
||||
...this.state,
|
||||
status: VoiceConnectionStatus.Connecting,
|
||||
networking,
|
||||
};
|
||||
};
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`${chalk.greenBright('[OK]')} Patched VoiceConnection.prototype.configureNetworking [@discordjs/voice]`,
|
||||
);
|
||||
/* eslint-enable */
|
||||
}
|
||||
|
||||
client.session_id = data.session_id;
|
||||
if (client.user) {
|
||||
client.user._patch(data.user);
|
||||
|
Reference in New Issue
Block a user