Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blooket.js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blooket.js - npm Package Compare versions

Comparing version 0.6.0 to 1.0.0

19

blooket.js
const ws = require('ws');
const EventEmitter = require("events");
const socketcheck = require('./modules/socket');
const getdata = require('./modules/getdata')
const {getdata, getquestions} = require('./modules/getdata')
const message = require('./modules/messageHandler')
const getquestions = require('./modules/questions')
const answerHandler = require("./modules/answerHandler")
const goldchance = require("./modules/goldchance")
const goldHandler = require("./modules/goldHandler")
const {goldHandler, goldchance} = require("./modules/goldHandler")
const delay = ms => new Promise(res => setTimeout(res, ms));

@@ -27,3 +25,3 @@ class Blooket extends EventEmitter {

this.options.blookcash = options.blookcash || 100
// Battle Royale Only Options
// Battle Royale and Classic mode Only Options
this.options.answertime = options.answertime || 1

@@ -67,2 +65,3 @@ // All Game Modes

this.mode = data[1].toLowerCase()
console.log(this.mode)
if (this.mode == 'factory') {

@@ -81,3 +80,3 @@ this.mode = 'fact'

})
if (this.mode == "royale") {
if (this.mode == "royale" || this.mode == "classic") {
this.socket.on('message', (data) => {

@@ -113,4 +112,4 @@ if (data.includes("q-")) {

async startquestion() {
if (this.mode != "royale") {
this.socket.removeAllListeners()
if (this.mode != "royale" & this.mode != "classic") {
this.socket.removeAllListeners()
}

@@ -132,3 +131,5 @@ if (this.CurrentIndex == this.TotalIndex & this.options.repeat == true) {

this.socket.send(`{"t":"d","d":{"r":1,"a":"p","b":{"p":"/${this.pin}/a/${this.name}","d":{"a":${a},"t":${this.options.answertime}}}}}`)
} else {
} else if (this.mode == "classic") {
this.socket.send(`{"t":"d","d":{"r":1,"a":"p","b":{"p":"/${this.pin}/c/${this.name}","d":{"a":${a},"t":${this.options.answertime}}}}}`)
} else {
await answerHandler(a-1, this).then((correct) => {

@@ -135,0 +136,0 @@ this.correct = correct

@@ -5,2 +5,3 @@ /**

*/
const got = require('got')
async function getdata(self) {

@@ -22,2 +23,14 @@ return new Promise((resolve,reject) => {

}
module.exports = getdata
/**
* @params {number} id - The game ID, used for retreived question data
* @returns {promise} - returns a promise containing the game question data
* @requires got
*/
function getquestions(id) {
return new Promise(async(resolve, reject) => {
res = await got(`https://www.blooket.com/api/games?gameId=${id}`)
questiondata = JSON.parse(res.body)
return resolve(questiondata)
});
}
module.exports = {getdata, getquestions}
/**
* @returns {array} - Returns an array containing 3 random prizes.
*/
function goldchance() {
return new Promise((resolve,reject) => {
const probability = [ // Help form https://stackoverflow.com/questions/66141403/javascript-chance-with-decimals/66141958 on probability
{ "gold": "l50" , "chance": 1 }, // 1.0 * 2 = 2 | [ 0, 1 ]
{ "gold": "swap" , "chance": 2 }, // 2.0 * 2 = 4 | [ 2, 5 ]
{ "gold": 0 , "chance": 2 }, // 2.0 * 2 = 4 | [ 6, 9 ]
{ "gold": "l25" , "chance": 3 }, // 3.0 * 2 = 6 | [ 10, 15 ]
{ "gold": "t10" , "chance": 4 }, // 4.0 * 2 = 8 | [ 16, 23 ]
{ "gold": "t25" , "chance": 4 }, // 4.0 * 2 = 8 | [ 24, 31 ]
{ "gold": "triple" , "chance": 4 }, // 4.0 * 2 = 8 | [ 32, 39 ]
{ "gold": 10 , "chance": 5 }, // 5.0 * 2 = 10 | [ 40, 49 ]
{ "gold": 100 , "chance": 7.5 }, // 7.5 * 2 = 15 | [ 50, 64 ]
{ "gold": "double" , "chance": 9 }, // 9.0 * 2 = 18 | [ 65, 82 ]
{ "gold": 20 , "chance": 12.5 }, // 12.5 * 2 = 25 | [ 83, 107 ]
{ "gold": 50 , "chance": 13.5 }, // 13.5 * 2 = 27 | [ 108, 134 ]
{ "gold": 40 , "chance": 15 }, // 15.0 * 2 = 30 | [ 135, 164 ]
{ "gold": 30 , "chance": 17.5 } // 17.5 * 2 = 35 | [ 165, 199 ]
];
const lookupIndex = (n) => {
if (n >= 0 && n < 2) return 0;
if (n >= 2 && n < 6) return 1;
if (n >= 6 && n < 10) return 2;
if (n >= 10 && n < 16) return 3;
if (n >= 16 && n < 24) return 4;
if (n >= 24 && n < 32) return 5;
if (n >= 32 && n < 40) return 6;
if (n >= 40 && n < 50) return 7;
if (n >= 50 && n < 65) return 8;
if (n >= 65 && n < 83) return 9;
if (n >= 83 && n < 108) return 10;
if (n >= 108 && n < 135) return 11;
if (n >= 135 && n < 165) return 12;
if (n >= 165 && n < 200) return 13;
};
const roll = () => lookupIndex(Math.floor(Math.random() * 200));
result = []
for (let i = 0; i < 3; i++) {
const rollIndex = roll();
result.push(probability[rollIndex].gold)
}
return resolve(result)
})
}
/**
* @param {number} p - The prize number

@@ -67,2 +116,2 @@ * @param {object} self - the client

}
module.exports = goldHandler
module.exports = {goldHandler, goldchance}

@@ -1,8 +0,19 @@

/**
* @params {number} pin - The game PIN
* @requires ws
* @returns {promise} Returns a promise containing the websocket use for the game.
*/
const got = require("got")
async function Sockets() {
return new Promise(async(resolve) => {
result = []
var {body} = await got("https://blooket-2020.firebaseio.com/.lp")
result.push("wss://" + JSON.parse(body.split('(0,')[1].split(/\n/)[0].split("]);")[0].split("[")[1]).d.d + "/.ws?v=5&ns=blooket-2020")
var {body} = await got("https://blooket-2021.firebaseio.com/.lp")
result.push("wss://" + JSON.parse(body.split('(0,')[1].split(/\n/)[0].split("]);")[0].split("[")[1]).d.d + "/.ws?v=5&ns=blooket-2021")
var {body} = await got("https://blooket-2022.firebaseio.com/.lp")
result.push("wss://" + JSON.parse(body.split('(0,')[1].split(/\n/)[0].split("]);")[0].split("[")[1]).d.d + "/.ws?v=5&ns=blooket-2022")
var {body} = await got("https://blooket-2023.firebaseio.com/.lp")
result.push("wss://" + JSON.parse(body.split('(0,')[1].split(/\n/)[0].split("]);")[0].split("[")[1]).d.d + "/.ws?v=5&ns=blooket-2023")
var {body} = await got("https://blooket-2024.firebaseio.com/.lp")
result.push("wss://" + JSON.parse(body.split('(0,')[1].split(/\n/)[0].split("]);")[0].split("[")[1]).d.d + "/.ws?v=5&ns=blooket-2024")
return resolve(result)
})
}
const WebSocket = require('ws');
const Sockets = require("./socketDetector")
function socketcheck(pin) {

@@ -9,0 +20,0 @@ return new Promise(async(resolve, reject) => {

{
"name": "blooket.js",
"version": "0.6.0",
"version": "1.0.0",
"description": "This is a terminal client for the quiz service known as Blooket",

@@ -5,0 +5,0 @@ "main": "blooket.js",

# Blooket.JS
## Version 0.5.0 Beta
## Version 0.6.0 Alpha
This version is **STILL** in beta. Classic Game Mode is not yet supported.

@@ -4,0 +4,0 @@ #### Table Of Contents

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc