GithubHelp home page GithubHelp logo

tetrjs / tetr.js Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 2.0 10.4 MB

An API Wrapper For TETR.IO

Home Page: https://tetr.js.org/

License: MIT License

TypeScript 99.67% JavaScript 0.33%
tetr-js tetr-io api-wrapper tetrjs tetrio ribbon ws websocket osk osk-sh

tetr.js's People

Contributors

actions-user avatar bumpybill avatar cankyre avatar mat1jaczyyy avatar proximitynow19 avatar snyk-bot avatar sup3rfire avatar zudob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tetr.js's Issues

Rate limit on fetching Tetra Channel information for players in room

if a room has 10+ people it's possible to hit rate limit on channelApi here, which takes down the entire node process:

data.players.map(async ({ _id, bracket }: any) => {
return [_id, { user: await client.fetchUser(_id), bracket }];
})

/srv/eucannon-prod/bot/node_modules/tetr.js/dist/util/channelApi.js:34
            throw Error((yield response).error);
                  ^

Error: Rate limit exceeded! | You are doing that far too quickly.
    at /srv/eucannon-prod/bot/node_modules/tetr.js/dist/util/channelApi.js:34:19
    at Generator.next (<anonymous>)
    at fulfilled (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/util/channelApi.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

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

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;
}

Ribbon sends `nope` on logout while in room

Since TETR.IO 6.4.3, logging out of a client while inside a room now causes the server to nope us out which takes down the entire node process with the following stack trace:

/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/commands/nope.js:7
    throw new Error(reason);
          ^

Error: ribbon expired
    at default_1 (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/commands/nope.js:7:11)
    at WebSocketManager.<anonymous> (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:193:23)
    at Generator.next (<anonymous>)
    at /srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:4:12)
    at WebSocketManager.receive (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:185:16)
    at WebSocket.<anonymous> (/srv/eucannon-prod/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:139:30)
    at WebSocket.emit (node:events:518:28)
    at Receiver.receiverOnMessage (/srv/eucannon-prod/bot/node_modules/ws/lib/websocket.js:1209:20)
const client = new tetrjs.Client();
await client.login(creds.token);

const room = await client.room.create("private");
setTimeout(() => client.logout(), 2000);

I have not tested this repro, but it should reproduce based off of EU Cannon bot code.

Disconnecting right after a round finishes leaves round victor unknown

If a player wins a round and then immediately disconnects before the room.game.on("score", event can fire, then victor will be undefined.

/srv/eucannon-test/bot/index.js:453
                .input('winner', room.tournament_match.players.indexOf(victor.user.id) + 1)
                                                                              ^

TypeError: Cannot read properties of undefined (reading 'user')
    at Game.<anonymous> (/srv/eucannon-test/bot/index.js:453:79)
    at Game.emit (node:events:518:28)
    at /srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:60:29
    at Generator.next (<anonymous>)
    at /srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:4:12)
    at default_1 (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:14:12)
    at WebSocketManager.<anonymous> (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:187:23)
    at Generator.next (<anonymous>)

In EU Cannon code:

https://github.com/EUCannon/bot/blob/94b0a303cb1f6771537fba8d711d16a07a6913de/index.js#L447-L454

Expose event to handle server-issued disconnects

A client can be disconnected by the server due to various reasons, including regular TETR.IO maintenance, which poses a problem for long-running bots.

Expose an event to notify bots when they've been disconnected and why, allowing them to handle reconnecting and re-setting up any bot state / in-game actions (such as opening rooms) themselves upon successful reconnection.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.