Skip to content

iluha168/obcb-api-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSR Deno TypeScript CI License: MIT

An API wrapper for One Billion Checkboxes

Implements 100% of the protocol.

Examples

/** A bot that disables all checkboxes in a chunk and quits
 * @module
 */
import { Client } from "jsr:@iluha168/obcb";

// Note: the website starts indexes from 1, while the API - from 0.
// This would correspond to page 51 on the site.
const CHUNK_INDEX = 50

new Client({
    // Called when the server has initialized our connection
    // You can safely call API methods past this point
    onHello(client) {
        client.chunkRequest(CHUNK_INDEX)
    },

    // Called when a chunk has been received
    onChunkUpdateFull(chunk) {
        // Iterate over received checkboxes
        for(const [i, checkbox] of chunk.boxes.entries()){
            // If the checkbox is on, disable it
            if(checkbox) chunk.toggle(i)
        }
        console.log("Chunk", chunk.index, "is now off")
        // Close the WebSocket once we are done
        // This should automatically stop this script
        chunk.client.disconnect()
    },
})
// Don't forget to connect!
.connect()

For more examples, such as rendering the entire bitmap as a square image, visit examples folder on GitHub.

Compatibility

Depends on WebSocket from WebAPI in the global scope. Every runtime that satisfies this requirement can use this library. It is possible to polyfill WebSocket in before calling Client.prototype.connect.

About

(WebSocket) API wrapper for One Billion Checkboxes by Alula

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors