From 247264218400c5f8bf0133e5fdb8e4546c07cba4 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:03:42 +0700 Subject: [PATCH] feat: remove messageCreateEventGuildTimeout & change UA default --- src/client/Client.js | 3 --- src/client/websocket/handlers/READY.js | 36 ++++++++++++++------------ src/util/Constants.js | 10 ++++--- src/util/Options.js | 22 +++++++--------- typings/index.d.ts | 3 ++- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index d3375b4..e1239f8 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -677,9 +677,6 @@ class Client extends BaseClient { if (!Array.isArray(options.partials)) { 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)) { throw new TypeError('CLIENT_INVALID_OPTION', 'DMChannelVoiceStatusSync', 'a number'); } diff --git a/src/client/websocket/handlers/READY.js b/src/client/websocket/handlers/READY.js index 0a9481f..fcf26b3 100644 --- a/src/client/websocket/handlers/READY.js +++ b/src/client/websocket/handlers/READY.js @@ -38,23 +38,27 @@ module.exports = (client, { d: data }, shard) => { // ClientSetting client.settings._patch(data.user_settings); + if (largeGuilds.length) { + client.ws.broadcast({ + op: Opcodes.GUILD_SUBSCRIPTIONS_BULK, + d: { + subscriptions: largeGuilds.reduce((accumulator, guild) => { + accumulator[guild.id] = { + typing: true, + threads: true, + activities: true, + member_updates: true, + thread_member_lists: [], + members: [], + channels: {}, + }; + return accumulator; + }, {}), + }, + }); + } + Promise.all( - largeGuilds.map(async (guild, index) => { - client.ws.broadcast({ - op: Opcodes.GUILD_SUBSCRIPTIONS, - d: { - guild_id: guild.id, - typing: true, - threads: true, - activities: true, - thread_member_lists: [], - members: [], - channels: {}, - }, - }); - client.emit('debug', `[READY] Register guild ${guild.id}`); - await client.sleep(client.options.messageCreateEventGuildTimeout * index); - }), data.private_channels.map(async (c, index) => { if (client.options.DMChannelVoiceStatusSync < 1) return; client.ws.broadcast({ diff --git a/src/util/Constants.js b/src/util/Constants.js index 99d4b03..a57f7bd 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -9,7 +9,7 @@ const { Error, RangeError, TypeError } = require('../errors'); exports.MaxBulkDeletableMessageAge = 1_209_600_000; 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: @@ -172,8 +172,10 @@ exports.Status = { * * REQUEST_SOUNDBOARD_SOUNDS: 31 * * SPEED_TEST_CREATE: 32 => Create 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) + * * REQUEST_CHANNEL_STATUSES: 36 => Request Voice Channel status. + * * GUILD_SUBSCRIPTIONS_BULK: 37 => ~ Opcode 14 * @typedef {Object} Opcodes */ exports.Opcodes = { @@ -212,7 +214,9 @@ exports.Opcodes = { SPEED_TEST_DELETE: 33, // Payload: null REQUEST_LAST_MESSAGES: 34, // Payload: { guild_id: string, channel_ids: string[] } 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 } | Response: Opcode 14 + // Updated: 23/1/2024 }; /** diff --git a/src/util/Options.js b/src/util/Options.js index 9e0846f..13c940b 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -49,7 +49,6 @@ const Intents = require('./Intents'); /** * Options for a client. * @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} [captchaRetryLimit=3] Captcha retry limit * @property {CaptchaSolver} [captchaSolver] Captcha Solver @@ -154,7 +153,6 @@ class Options extends null { */ static createDefault() { return { - messageCreateEventGuildTimeout: 100, DMChannelVoiceStatusSync: 0, captchaRetryLimit: 3, 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 properties: { os: 'Windows', - browser: 'Discord Client', - release_channel: 'stable', - client_version: '1.0.9023', - os_version: '10.0.19045', - os_arch: 'x64', - app_arch: 'ia32', + browser: 'Chrome', + device: '', system_locale: 'en-US', browser_user_agent: UserAgent, - browser_version: '22.3.26', - client_build_number: 244874, - native_build_number: 39515, + browser_version: '120.0.0.0', + os_version: '10', + referrer: '', + referring_domain: '', + referrer_current: '', + referring_domain_current: '', + release_channel: 'stable', + client_build_number: 260292, client_event_source: null, - design_id: 0, }, compress: false, client_state: { diff --git a/typings/index.d.ts b/typings/index.d.ts index d0c099c..8f26a5c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -5188,7 +5188,6 @@ export interface ClientFetchInviteOptions { export type CaptchaSolver = (captcha: Captcha, UserAgent: string) => Promise; export interface ClientOptions { - messageCreateEventGuildTimeout?: number; DMChannelVoiceStatusSync?: number; captchaRetryLimit?: number; captchaSolver?: CaptchaSolver; @@ -5496,6 +5495,8 @@ export interface ConstantsOpcodes { SPEED_TEST_DELETE: 33; REQUEST_LAST_MESSAGES: 34; SEARCH_RECENT_MEMBERS: 35; + REQUEST_CHANNEL_STATUSES: 36; + GUILD_SUBSCRIPTIONS_BULK: 37; } export interface ConstantsShardEvents {