From 69e7459939f86b57146c3cf14c792cefb321a441 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Sun, 8 May 2022 10:47:27 +0200 Subject: [PATCH] Revert "workaround for revoltchat/revite#609" This reverts commit 42cb2d7f59c10cd8c5e4324ba3d6e06dcad8be2b. --- bot/src/bot/modules/event_fix.ts | 49 -------------------------------- bot/src/bot/util.ts | 6 ---- bot/src/index.ts | 1 - 3 files changed, 56 deletions(-) delete mode 100644 bot/src/bot/modules/event_fix.ts diff --git a/bot/src/bot/modules/event_fix.ts b/bot/src/bot/modules/event_fix.ts deleted file mode 100644 index 69dcfa7..0000000 --- a/bot/src/bot/modules/event_fix.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Quick and dirty hack for https://github.com/revoltchat/revite/issues/609 -// We periodically poll the `ready` WS event by creating a new client and compare -// the cached server count. If a new server is found, the original client reconnects -// and emits the `member/join` event for itself afterwards. - -import { Client } from "@janderedev/revolt.js"; -import { client } from "../.."; -import logger from "../logger"; -import { awaitClient } from "../util"; - -awaitClient().then(async () => { - setInterval(async () => { - logger.debug('Checking for unknown servers'); - const knownServers = Array.from(client.servers.keys()); - const tmpClient = new Client({ - ...client.options, - }); - - tmpClient.loginBot(process.env['BOT_TOKEN']!); - - tmpClient.once('ready', async () => { - const tmpServers = Array.from(tmpClient.servers.keys()); - if (tmpServers.length != knownServers.length) { - logger.warn('New unknown server(s) detected'); - - client.websocket.disconnect(); - client.websocket.connect(); - - client.once('connected', async () => { - console.info('Client reconnected'); - for (const id of tmpServers) { - if (!knownServers.includes(id)) { - try { - const server = client.servers.get(id) || await client.servers.fetch(id); - const member = server.member; - if (!member) continue; - - client.emit('member/join', member); - } catch(e) { - console.error(e); - } - } - } - }); - } - tmpClient.websocket.disconnect(); - }); - }, 1000 * 15); -}); diff --git a/bot/src/bot/util.ts b/bot/src/bot/util.ts index 445e7d9..9cbba4e 100644 --- a/bot/src/bot/util.ts +++ b/bot/src/bot/util.ts @@ -346,11 +346,6 @@ function dedupeArray(...arrays: T[][]): T[] { return found; } -const awaitClient = () => new Promise(async resolve => { - if (!client.user) client.once('ready', () => resolve()); - else resolve(); -}); - export { getAutumnURL, hasPerm, @@ -368,7 +363,6 @@ export { sendLogMessage, embed, dedupeArray, - awaitClient, EmbedColor, NO_MANAGER_MSG, ULID_REGEX, diff --git a/bot/src/index.ts b/bot/src/index.ts index fc0fd7d..3b03d9e 100644 --- a/bot/src/index.ts +++ b/bot/src/index.ts @@ -68,5 +68,4 @@ logger.info(`\ import('./bot/modules/metrics'); import('./bot/modules/bot_status'); import('./bot/modules/fetch_all'); - import('./bot/modules/event_fix'); })();