feat: remove messageCreateEventGuildTimeout & change UA default

This commit is contained in:
Elysia 2024-01-23 21:03:42 +07:00
parent 87d0334eb8
commit 2472642184
5 changed files with 39 additions and 35 deletions

View File

@ -677,9 +677,6 @@ class Client extends BaseClient {
if (!Array.isArray(options.partials)) { if (!Array.isArray(options.partials)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array'); throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array');
} }
if (typeof options.messageCreateEventGuildTimeout !== 'number' || isNaN(options.messageCreateEventGuildTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageCreateEventGuildTimeout', 'a number');
}
if (typeof options.DMChannelVoiceStatusSync !== 'number' || isNaN(options.DMChannelVoiceStatusSync)) { if (typeof options.DMChannelVoiceStatusSync !== 'number' || isNaN(options.DMChannelVoiceStatusSync)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'DMChannelVoiceStatusSync', 'a number'); throw new TypeError('CLIENT_INVALID_OPTION', 'DMChannelVoiceStatusSync', 'a number');
} }

View File

@ -38,23 +38,27 @@ module.exports = (client, { d: data }, shard) => {
// ClientSetting // ClientSetting
client.settings._patch(data.user_settings); client.settings._patch(data.user_settings);
Promise.all( if (largeGuilds.length) {
largeGuilds.map(async (guild, index) => {
client.ws.broadcast({ client.ws.broadcast({
op: Opcodes.GUILD_SUBSCRIPTIONS, op: Opcodes.GUILD_SUBSCRIPTIONS_BULK,
d: { d: {
guild_id: guild.id, subscriptions: largeGuilds.reduce((accumulator, guild) => {
accumulator[guild.id] = {
typing: true, typing: true,
threads: true, threads: true,
activities: true, activities: true,
member_updates: true,
thread_member_lists: [], thread_member_lists: [],
members: [], members: [],
channels: {}, channels: {},
};
return accumulator;
}, {}),
}, },
}); });
client.emit('debug', `[READY] Register guild ${guild.id}`); }
await client.sleep(client.options.messageCreateEventGuildTimeout * index);
}), Promise.all(
data.private_channels.map(async (c, index) => { data.private_channels.map(async (c, index) => {
if (client.options.DMChannelVoiceStatusSync < 1) return; if (client.options.DMChannelVoiceStatusSync < 1) return;
client.ws.broadcast({ client.ws.broadcast({

View File

@ -9,7 +9,7 @@ const { Error, RangeError, TypeError } = require('../errors');
exports.MaxBulkDeletableMessageAge = 1_209_600_000; exports.MaxBulkDeletableMessageAge = 1_209_600_000;
exports.UserAgent = exports.UserAgent =
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9023 Chrome/108.0.5359.215 Electron/22.3.26 Safari/537.36'; 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
/** /**
* The types of WebSocket error codes: * The types of WebSocket error codes:
@ -174,6 +174,8 @@ exports.Status = {
* * SPEED_TEST_DELETE: 33 => Delete a voice speed test. * * SPEED_TEST_DELETE: 33 => Delete a voice speed test.
* * REQUEST_LAST_MESSAGES: 34 => Request last messages for a guild's channels. * * REQUEST_LAST_MESSAGES: 34 => Request last messages for a guild's channels.
* * SEARCH_RECENT_MEMBERS: 35 => ~ Opcode 8 (Member Safety) * * SEARCH_RECENT_MEMBERS: 35 => ~ Opcode 8 (Member Safety)
* * REQUEST_CHANNEL_STATUSES: 36 => Request Voice Channel status.
* * GUILD_SUBSCRIPTIONS_BULK: 37 => ~ Opcode 14
* @typedef {Object<string, number>} Opcodes * @typedef {Object<string, number>} Opcodes
*/ */
exports.Opcodes = { exports.Opcodes = {
@ -212,7 +214,9 @@ exports.Opcodes = {
SPEED_TEST_DELETE: 33, // Payload: null SPEED_TEST_DELETE: 33, // Payload: null
REQUEST_LAST_MESSAGES: 34, // Payload: { guild_id: string, channel_ids: string[] } REQUEST_LAST_MESSAGES: 34, // Payload: { guild_id: string, channel_ids: string[] }
SEARCH_RECENT_MEMBERS: 35, // Payload: { guild_id: string, query: string, continuation_token?: Snowflake } SEARCH_RECENT_MEMBERS: 35, // Payload: { guild_id: string, query: string, continuation_token?: Snowflake }
// Update: 17/7/2023 REQUEST_CHANNEL_STATUSES: 36, // Payload: { guild_id: string } | Response: CHANNEL_STATUSES | { guild_id, channels: { status, id }[] }
GUILD_SUBSCRIPTIONS_BULK: 37, // Payload: { subscriptions: Object<guild_id, { Payload_op14 - guild_id }> } | Response: Opcode 14
// Updated: 23/1/2024
}; };
/** /**

View File

@ -49,7 +49,6 @@ const Intents = require('./Intents');
/** /**
* Options for a client. * Options for a client.
* @typedef {Object} ClientOptions * @typedef {Object} ClientOptions
* @property {number} [messageCreateEventGuildTimeout=100] The amount of time in milliseconds that the Client to register for messages with each guild
* @property {number} [DMChannelVoiceStatusSync=0] The amount of time in milliseconds that the Client to register the event with each DM channel (0=Disable) * @property {number} [DMChannelVoiceStatusSync=0] The amount of time in milliseconds that the Client to register the event with each DM channel (0=Disable)
* @property {number} [captchaRetryLimit=3] Captcha retry limit * @property {number} [captchaRetryLimit=3] Captcha retry limit
* @property {CaptchaSolver} [captchaSolver] Captcha Solver * @property {CaptchaSolver} [captchaSolver] Captcha Solver
@ -154,7 +153,6 @@ class Options extends null {
*/ */
static createDefault() { static createDefault() {
return { return {
messageCreateEventGuildTimeout: 100,
DMChannelVoiceStatusSync: 0, DMChannelVoiceStatusSync: 0,
captchaRetryLimit: 3, captchaRetryLimit: 3,
captchaSolver: () => Promise.reject(new Error('CAPTCHA_SOLVER_NOT_IMPLEMENTED')), captchaSolver: () => Promise.reject(new Error('CAPTCHA_SOLVER_NOT_IMPLEMENTED')),
@ -181,19 +179,19 @@ class Options extends null {
capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities
properties: { properties: {
os: 'Windows', os: 'Windows',
browser: 'Discord Client', browser: 'Chrome',
release_channel: 'stable', device: '',
client_version: '1.0.9023',
os_version: '10.0.19045',
os_arch: 'x64',
app_arch: 'ia32',
system_locale: 'en-US', system_locale: 'en-US',
browser_user_agent: UserAgent, browser_user_agent: UserAgent,
browser_version: '22.3.26', browser_version: '120.0.0.0',
client_build_number: 244874, os_version: '10',
native_build_number: 39515, referrer: '',
referring_domain: '',
referrer_current: '',
referring_domain_current: '',
release_channel: 'stable',
client_build_number: 260292,
client_event_source: null, client_event_source: null,
design_id: 0,
}, },
compress: false, compress: false,
client_state: { client_state: {

3
typings/index.d.ts vendored
View File

@ -5188,7 +5188,6 @@ export interface ClientFetchInviteOptions {
export type CaptchaSolver = (captcha: Captcha, UserAgent: string) => Promise<string>; export type CaptchaSolver = (captcha: Captcha, UserAgent: string) => Promise<string>;
export interface ClientOptions { export interface ClientOptions {
messageCreateEventGuildTimeout?: number;
DMChannelVoiceStatusSync?: number; DMChannelVoiceStatusSync?: number;
captchaRetryLimit?: number; captchaRetryLimit?: number;
captchaSolver?: CaptchaSolver; captchaSolver?: CaptchaSolver;
@ -5496,6 +5495,8 @@ export interface ConstantsOpcodes {
SPEED_TEST_DELETE: 33; SPEED_TEST_DELETE: 33;
REQUEST_LAST_MESSAGES: 34; REQUEST_LAST_MESSAGES: 34;
SEARCH_RECENT_MEMBERS: 35; SEARCH_RECENT_MEMBERS: 35;
REQUEST_CHANNEL_STATUSES: 36;
GUILD_SUBSCRIPTIONS_BULK: 37;
} }
export interface ConstantsShardEvents { export interface ConstantsShardEvents {