mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
workaround for revoltchat/revite#609
This commit is contained in:
parent
bb79b9d4ab
commit
42cb2d7f59
49
bot/src/bot/modules/event_fix.ts
Normal file
49
bot/src/bot/modules/event_fix.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// 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);
|
||||||
|
});
|
|
@ -346,6 +346,11 @@ function dedupeArray<T>(...arrays: T[][]): T[] {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const awaitClient = () => new Promise<void>(async resolve => {
|
||||||
|
if (!client.user) client.once('ready', () => resolve());
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getAutumnURL,
|
getAutumnURL,
|
||||||
hasPerm,
|
hasPerm,
|
||||||
|
@ -363,6 +368,7 @@ export {
|
||||||
sendLogMessage,
|
sendLogMessage,
|
||||||
embed,
|
embed,
|
||||||
dedupeArray,
|
dedupeArray,
|
||||||
|
awaitClient,
|
||||||
EmbedColor,
|
EmbedColor,
|
||||||
NO_MANAGER_MSG,
|
NO_MANAGER_MSG,
|
||||||
ULID_REGEX,
|
ULID_REGEX,
|
||||||
|
|
|
@ -68,4 +68,5 @@ logger.info(`\
|
||||||
import('./bot/modules/metrics');
|
import('./bot/modules/metrics');
|
||||||
import('./bot/modules/bot_status');
|
import('./bot/modules/bot_status');
|
||||||
import('./bot/modules/fetch_all');
|
import('./bot/modules/fetch_all');
|
||||||
|
import('./bot/modules/event_fix');
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue