Files
discord.js-selfbot/src/client/websocket/handlers/READY.js

138 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-03-19 17:37:45 +07:00
'use strict';
let ClientUser;
2022-05-21 20:58:33 +07:00
const { VoiceConnection, VoiceConnectionStatus } = require('@discordjs/voice');
const axios = require('axios');
2022-04-16 19:01:05 +07:00
const chalk = require('chalk');
const Discord = require('../../../index');
2022-05-11 20:19:04 +07:00
const { Events, Opcodes } = require('../../../util/Constants');
2022-05-21 20:58:33 +07:00
const { Networking } = require('../../../util/Voice');
2022-06-13 23:53:43 +07:00
/**
* Emitted whenever clientOptions.checkUpdate = true
* @event Client#update
2022-06-15 18:35:32 +07:00
* @param {string} oldVersion Log data :v
* @param {string} newVersion Log data :)) ehe
2022-06-13 23:53:43 +07:00
*/
async function checkUpdate(client) {
const res_ = await axios
.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`)
.catch(() => {});
if (!res_) {
2022-06-13 23:53:43 +07:00
return client.emit('update', `${chalk.redBright('[Fail]')} Check Update error`);
}
const lastest_tag = res_.data['dist-tags'].latest;
2022-06-15 18:35:32 +07:00
client.emit('update', Discord.version, lastest_tag);
return null;
}
2022-03-19 17:37:45 +07:00
module.exports = (client, { d: data }, shard) => {
if (client.options.checkUpdate) {
checkUpdate(client);
}
2022-05-21 20:58:33 +07:00
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);
} else {
ClientUser ??= require('../../../structures/ClientUser');
client.user = new ClientUser(client, data.user);
client.users.cache.set(client.user.id, client.user);
}
2022-03-19 17:37:45 +07:00
client.user.setAFK(false);
2022-03-19 17:37:45 +07:00
client.setting._patch(data.user_settings);
client.user.connectedAccounts = data.connected_accounts ?? [];
client.user._patchNote(data.notes);
for (const private_channel of data.private_channels) {
client.channels._add(private_channel);
}
// Remove event because memory leak
if (client.options.readyStatus) {
client.customStatusAuto(client);
}
/**
2022-04-16 19:01:05 +07:00
* Read_state: Return Array:
* {
* mention_count: 14, // ok it's ping count
* last_pin_timestamp: '1970-01-01T00:00:00+00:00', // why discord ?
* last_message_id: 0, // :)
* id: '840218426969817119' // channel id
* },
*/
/*
for (const object of data.read_state) {
if (object.mention_count == 0) continue;
client.user.messageMentions.set(object.id, object);
}
*/
2022-03-20 14:25:53 +07:00
for (const guild of data.guilds) {
guild.shardId = shard.id;
client.guilds._add(guild);
}
2022-03-19 17:37:45 +07:00
// Receive messages in large guilds
2022-05-11 20:19:04 +07:00
client.guilds.cache.map(guild => {
client.ws.broadcast({
op: Opcodes.LAZY_REQUEST,
d: {
guild_id: guild.id,
typing: true,
threads: false,
activities: true,
thread_member_lists: [],
members: [],
channels: {
// [guild.channels.cache.first().id]: [[0, 99]],
},
},
});
return true;
});
client.relationships._setup(data.relationships);
2022-03-19 17:37:45 +07:00
shard.checkReady();
2022-03-19 17:37:45 +07:00
};