Fix: implement explicit sync wait to resolve M_INVALID_PARAM
This commit is contained in:
25
index.js
25
index.js
@@ -49,15 +49,24 @@ function loadQuotes() {
|
||||
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 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}`));
|
||||
}
|
||||
console.log(` ... Waiting for UserID (Attempt ${attempts + 1})`);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
attempts++;
|
||||
});
|
||||
});
|
||||
|
||||
if (!client.user || !client.user.userId) {
|
||||
throw new Error('User identity not resolved after sync.');
|
||||
}
|
||||
|
||||
console.log(`👤 Bot Identity: ${client.user.userId}`);
|
||||
|
||||
Reference in New Issue
Block a user