Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

err/kick/nope event handlers can't access room properties #60

Open
mat1jaczyyy opened this issue Apr 12, 2024 · 0 comments
Open

err/kick/nope event handlers can't access room properties #60

mat1jaczyyy opened this issue Apr 12, 2024 · 0 comments

Comments

@mat1jaczyyy
Copy link
Contributor

We're setting up err/kick/nope handlers to log an error occurred so a human can investigate later, we're specifically interested in logging the room ID the client was in at the time of death.

Looks like at the time of those event handlers being called, everything in the room is already undefined, including the ID.

We'd like to be able to log what room ID, if any, the bot was in when it received that error and died.

function tetrjsFatal(client, kind, reason) {
    // client.room.id is already undefined here
    logWith(
        client.room?.id? `Room ${client.room.id}` : `Not in room`,
        `FATAL ${kind}: ${reason}`
    );
}

async function newClient() {
    const client = new tetrjs.Client();
    await client.login(creds.token);

    client.on('err', reason => tetrjsFatal(client, 'err', reason));
    client.on('kick', reason => tetrjsFatal(client, 'kick', reason));
    client.on('nope', reason => tetrjsFatal(client, 'nope', reason));
    
    return client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant