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

172 lines
5.2 KiB
JavaScript
Raw Normal View History

2022-03-19 17:37:45 +07:00
'use strict';
let ClientUser;
2022-10-15 12:26:52 +07:00
const { VoiceConnection } = require('@discordjs/voice');
2022-04-16 19:01:05 +07:00
const chalk = require('chalk');
2022-05-11 20:19:04 +07:00
const { Events, Opcodes } = require('../../../util/Constants');
2022-10-15 12:26:52 +07:00
const { VoiceConnection: VoiceConnection_patch } = require('../../../util/Voice');
2022-11-15 20:06:03 +07:00
let firstReady = false;
function patchVoice(client) {
try {
/* eslint-disable */
VoiceConnection.prototype.configureNetworking = VoiceConnection_patch.prototype.configureNetworking;
client.emit(
'debug',
`${chalk.greenBright('[OK]')} Patched ${chalk.cyanBright(
'VoiceConnection.prototype.configureNetworking',
)} [${chalk.bgMagentaBright('@discordjs/voice')} - ${chalk.redBright('v0.16.0')}]`,
2022-11-15 20:06:03 +07:00
);
/* eslint-enable */
} catch (e) {
client.emit(
'debug',
`${chalk.redBright('[Fail]')} Patched ${chalk.cyanBright(
'VoiceConnection.prototype.configureNetworking',
)} [${chalk.bgMagentaBright('@discordjs/voice')} - ${chalk.redBright('v0.16.0')}]\n${e.stack}`,
2022-11-15 20:06:03 +07:00
);
client.emit(
Events.ERROR,
`${chalk.redBright('[Fail]')} Patched ${chalk.cyanBright(
'VoiceConnection.prototype.configureNetworking',
)} [${chalk.bgMagentaBright('@discordjs/voice')} - ${chalk.redBright('v0.16.0')}]`,
2022-11-15 20:06:03 +07:00
);
client.emit(
Events.ERROR,
`${chalk.redBright('[Error]')} Please install ${chalk.bgMagentaBright(
'@discordjs/voice',
)} version ${chalk.redBright('v0.16.0')}`,
2022-11-15 20:06:03 +07:00
);
}
2022-11-15 20:06:03 +07:00
}
module.exports = async (client, { d: data }, shard) => {
if (!firstReady) {
client.once('update', (currentVersion, newVersion) => {
if (!newVersion) {
console.log(`
${chalk.redBright('[WARNING]')} Cannot check new Discord.js-selfbot-v13 version.
Current: ${chalk.blueBright(currentVersion)}
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
const client = new Client({
checkUpdate: false,
});
and using event update
https://discordjs-self-v13.netlify.app/#/docs/docs/main/class/Client?scrollTo=e-update\n`);
} else if (currentVersion !== newVersion && !currentVersion.includes('-')) {
2022-07-16 15:31:44 +07:00
console.log(`
2022-06-25 10:28:31 +07:00
${chalk.yellowBright('[WARNING]')} New Discord.js-selfbot-v13 version.
2022-11-15 20:06:03 +07:00
Current: ${chalk.redBright(currentVersion)} => Latest: ${chalk.greenBright(newVersion)}
2022-08-21 09:54:13 +07:00
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
2022-11-06 12:05:18 +07:00
const client = new Client({
checkUpdate: false,
});
2022-06-25 10:28:31 +07:00
and using event update
2022-08-21 09:54:13 +07:00
https://discordjs-self-v13.netlify.app/#/docs/docs/main/class/Client?scrollTo=e-update\n`);
2022-11-15 20:06:03 +07:00
} else {
console.log(
`
${chalk.greenBright('[OK]')} Discord.js-selfbot-v13 is up to date. Current: ${chalk.blueBright(currentVersion)}
2022-08-21 09:54:13 +07:00
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
2022-11-06 12:05:18 +07:00
const client = new Client({
checkUpdate: false,
});
2022-06-25 10:28:31 +07:00
and using event update
2022-08-21 09:54:13 +07:00
https://discordjs-self-v13.netlify.app/#/docs/docs/main/class/Client?scrollTo=e-update\n`,
2022-11-15 20:06:03 +07:00
);
}
});
if (client.options.checkUpdate) {
client.checkUpdate();
}
2022-03-19 17:37:45 +07:00
2022-11-15 20:06:03 +07:00
if (client.options.patchVoice) {
patchVoice(client);
}
2022-11-15 20:06:03 +07:00
2023-01-26 13:40:51 +07:00
if (client.options.syncStatus) {
2022-11-15 20:06:03 +07:00
client.customStatusAuto(client);
}
firstReady = true;
2022-05-21 20:58:33 +07:00
}
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.settings._patch(data.user_settings);
client.user.connectedAccounts = data.connected_accounts ?? [];
2022-10-25 12:37:23 +07:00
client.relationships._setup(data.relationships);
client.user._patchNote(data.notes);
2022-07-16 16:37:41 +07:00
const syncTime = Date.now();
for (const private_channel of data.private_channels) {
2022-07-16 16:37:41 +07:00
const channel = client.channels._add(private_channel);
// Rate limit warning
if (client.options.DMSync) {
client.ws.broadcast({
op: Opcodes.DM_UPDATE,
d: {
channel_id: channel.id,
},
});
}
}
if (client.options.DMSync) {
console.warn(
`Gateway Rate Limit Warning: Sending ${data.private_channels.length} Requests / ${Date.now() - syncTime || 1} ms`,
);
}
for (const guild of data.guilds) {
guild.shardId = shard.id;
client.guilds._add(guild);
}
2022-03-19 17:37:45 +07:00
for (const gSetting of data.user_guild_settings) {
const guild = client.guilds.cache.get(gSetting.guild_id);
if (guild) guild.settings._patch(gSetting);
}
2022-12-25 18:54:45 +07:00
const largeGuilds = data.guilds.filter(g => g.large);
2023-01-12 17:35:59 +07:00
client.emit('debug', `[READY] Received ${data.guilds.length} guilds, ${largeGuilds.length} large guilds`);
2022-12-25 18:54:45 +07:00
// Receive messages in large guilds
2022-12-25 18:54:45 +07:00
for (const guild of largeGuilds) {
await client.sleep(client.options.messageCreateEventGuildTimeout);
2022-05-11 20:19:04 +07:00
client.ws.broadcast({
2023-02-16 11:55:35 +07:00
op: Opcodes.GUILD_SUBSCRIPTIONS,
2022-05-11 20:19:04 +07:00
d: {
guild_id: guild.id,
typing: true,
2022-08-09 10:43:16 +07:00
threads: true,
2022-05-11 20:19:04 +07:00
activities: true,
thread_member_lists: [],
members: [],
channels: {},
2022-05-11 20:19:04 +07:00
},
});
}
2022-05-11 20:19:04 +07:00
shard.checkReady();
2022-03-19 17:37:45 +07:00
};