From 21bbfe4aa2852862ef3b6c9aa9333019b93feeee Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Fri, 10 Jun 2022 15:51:31 +0700 Subject: [PATCH] fix(event): userSettingsUpdate memory leak --- src/client/websocket/handlers/READY.js | 11 +++++------ src/client/websocket/handlers/USER_SETTINGS_UPDATE.js | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client/websocket/handlers/READY.js b/src/client/websocket/handlers/READY.js index 981c973..6b5ce8e 100644 --- a/src/client/websocket/handlers/READY.js +++ b/src/client/websocket/handlers/READY.js @@ -88,12 +88,11 @@ module.exports = (client, { d: data }, shard) => { for (const private_channel of data.private_channels) { client.channels._add(private_channel); } - // Start event - client.on(Events.USER_SETTINGS_UPDATE, s => { - if (('status' in s || 'custom_status' in s) && client.options.readyStatus) { - client.customStatusAuto(client); - } - }); + // Remove event because memory leak + + if (client.options.readyStatus) { + client.customStatusAuto(client); + } /** * Read_state: Return Array: diff --git a/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js b/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js index 265a8be..cc105cb 100644 --- a/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +++ b/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js @@ -2,5 +2,8 @@ const { Events } = require('../../../util/Constants'); module.exports = (client, { d: data }) => { client.setting._patch(data); + if (('status' in data || 'custom_status' in data) && client.options.readyStatus) { + client.customStatusAuto(client); + } return client.emit(Events.USER_SETTINGS_UPDATE, data); };