tetrjs / tetr.js Goto Github PK
View Code? Open in Web Editor NEWAn API Wrapper For TETR.IO
Home Page: https://tetr.js.org/
License: MIT License
An API Wrapper For TETR.IO
Home Page: https://tetr.js.org/
License: MIT License
if a room has 10+ people it's possible to hit rate limit on channelApi here, which takes down the entire node process:
tetr.js/src/ws/commands/room.update.ts
Lines 92 to 94 in 226bf41
/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)
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;
}
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.
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
This will fix a lot of bugs, would be a little hard to implement tho
Note: might need to check if errors trigger right after the function and in the order of the function triggered
Player data currently doesn't contain 40L/Blitz record information because it's in a separate Tetra Channel API endpoint.
We're currently hacking this together in EU Cannon.
support new ribbon system
Tracking issue for:
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.