Created
August 3, 2020 22:38
-
-
Save JavadocMD/49309d286ba24dc3eb2d25236263afd8 to your computer and use it in GitHub Desktop.
Follow a Blaseball game for the given team and print updates to the console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { default as Socket } from 'socket.io-client' | |
// dependencies: socket.io-client | |
// Usage example: | |
// $ node ./dist/index.js "Philly Pies" | espeak-ng -v en-us -s 120 | |
function main() { | |
const team = process.argv[2] || 'Philly Pies' | |
const socket = Socket('https://blaseball.com') | |
socket.on('connect', () => { | |
console.log('> connected') | |
}) | |
let prevUpdate = '' | |
socket.on('gameDataUpdate', data => { | |
const game = data.schedule.find(x => x.awayTeamName === team || x.homeTeamName === team) | |
let currUpdate = prevUpdate | |
if (game) { | |
currUpdate = game.lastUpdate || '(No update.)' | |
} else { | |
currUpdate = `No game in progress for team "${team}"` | |
} | |
if (currUpdate !== prevUpdate) { | |
console.log(currUpdate) | |
prevUpdate = currUpdate | |
} | |
}) | |
socket.on('disconnect', reason => { | |
console.log(`> disconnected (${reason})`) | |
}) | |
process.on('SIGINT', () => { | |
socket.close() | |
process.exit() | |
}) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment