Fix: implement explicit sync wait to resolve M_INVALID_PARAM

This commit is contained in:
unfunny
2026-09-13 15:41:46 -04:00
parent fadb6235fe
commit 9444ba8be5

View File

@@ -48,16 +48,25 @@ function loadQuotes() {
console.log('⏳ Connecting to Matrix...');
await client.startClient();
console.log('✅ MatrixClient connected and authenticated\n');
console.log('⏳ Waiting for User Identity to resolve...');
let attempts = 0;
while (!client.user || !client.user.userId) {
if (attempts > 30) {
throw new Error('Timeout waiting for Matrix User ID resolution (30s).');
}
console.log(` ... Waiting for UserID (Attempt ${attempts + 1})`);
await new Promise(resolve => setTimeout(resolve, 1000));
attempts++;
console.log('⏳ Waiting for initial sync to complete...');
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Sync timeout: Initial sync took too long.'));
}, 45000);
client.on('sync', (sync) => {
if (sync.result === 'ok') {
clearTimeout(timeout);
resolve();
} else if (sync.result === 'error') {
reject(new Error(`Sync failed with error: ${sync.error}`));
}
});
});
if (!client.user || !client.user.userId) {
throw new Error('User identity not resolved after sync.');
}
console.log(`👤 Bot Identity: ${client.user.userId}`);