0.0.1 • Published 2 years ago

jsquizizz v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

jsQuizizz

NPM

GitHub release

Overview

jsQuizizz is a NodeJS Wrapper for the Quizizz API.

Installing

This package can be installed using NodeJS's package manager, npm.

npm install jsquizizz

To use the new esm syntax, set your type to module in your package.json. Click me for more information

  • You can import the entire package into a single variable (esm)
    import * as Quizizz from 'jsquizziz'
  • You can import certain parts of the package into different variables (esm)
    import {MemeSet, Quiz, Tag, User, Game} from 'jsquizziz'
  • You can also import this package into non-esm modules (commonjs)
    var Quizizz = await import("jsquizizz")
  • MemeSet

    Quizizz shows the players memes after every question answered. These memes are stored in MemeSets, and the MemeSet class allows us to get these MemeSets

    • Methods

      staticgetByID | Parameter | Type | Default | Description | |---------------|----------|-|----------------| | id | string | Required | The MemeSet ID | | save | boolean| false | Whether to save the memes to memory for faster recall |

      staticgetFromUser | Parameter | Type | Description | |---------------|----------|-----------------| | id | string | The User ID |

      staticgetFeaturedNonePromise<MemeSet[]>Gets the currently featured MemeSets

      await MemeSet.getFeatured()

      dynamicgetMemes | Parameter | Type | Default | Description| |---------------|-----------|-------------|------------------------------------------------------| | save | boolean | false | Whether to save the data to memory for faster recall |

      dynamicMeme.getCreatorNonePromise<User>Gets the meme's creator.

      await (await myMemeSet.getMemes(false))[0].getCreator();
    • Properties

  • Quiz

    Quizizz is a service based of many, many quizzes. The Quiz class helps to fetch these quizzes.

    • Methods
    • Properties
  • Tag

    User's can tag their quizzes to group them into sections. The Tag class can process these sections and quizzes

    • Methods

      Promise<Tag>Gets a tag via it's ID

      await Tag.getByID("abcdef", false)

      dynamicgetItems | Parameter | Type | Default | Description | |-----------|-----------|---------|------------------------------------------------------| | save | boolean | false | Whether to save the data to memory for faster recall |

    • Properties

  • User

    The User class is a class that holds several aliases to the other class methods that get content based on a user id

    • Methods
    • Properties
  • Game

    The Game class is probably the most complex class in this package. This class allows you to join a Quizizz game as a client.

    • Methods
    • Properties

      powerupsPropertyPowerup TitleDescriptiondouble-jeopardyDouble Jeopardy

      Players get double points if they choose the answer correctly but lose it all if they choose the wrong answer

      This powerup serves no real purpose, as we custom set our points in the options parameter2xx2

      Players get twice the points for answering a question right

      This powerup serves no real purpose, as we custom set our points in the options parameter50-5050-50

      Eliminates half of the incorrect options

      Adds half of the incorrect options to the ia property, and the incorrectAnswers property from the question event dataeraserEraser

      Eliminates one wrong option

      Adds one incorrect option to the ai property, and the incorrectAnswers property from the question event dataimmunityImmunity

      2 attempts are allowed for answering the same question

      Gives you another attempt to answer the current question if you get it wrong, you can use this as many times as you wanttime-freezeTime Freeze

      The timer is frozen to allow players to answer 1 question

      This powerup serves no real purpose, as we custom set our time in the options parameterpower-playPower Play

      All players in the quiz get 50% more points in 20 seconds

      This powerup applies to all players except the client, as the client's points are custom set in the options parametersupersonicSupersonic

      Get 1.5x points for 20 seconds with ultra fast gameplay

      This powerup serves no real purpose, as we custom set our points in the options parameterstreak-saverStreak Saver

      Ensures a player’s streak against an incorrect answer

      This powerup serves no real purpose, as the streak saver is only client side (for points), and we custom set our points in the options parameterglitchGlitch

      All players' screens glitch for 10 seconds (does not add to scores)

      Nothing more needs to said about this.add-points+1000pt

      No description

      This powerup serves no real purpose, as we custom set our points in the options parameterstreak-boosterStreak Booster

      Apply to boost your streak counter by +6

      This powerup serves no real purpose, as the streak booster is only client side (for points), and we custom set our points in the options parametersend-giftGift

      Players can send another player an extra 800 points

      This powerup requires you to specify the targets parameter for the activatePowerup method. If you send a player more than 9 gifts in a single question cycle, their game will crash when they try to answer.The available powerupsroomRoom (See types.d.ts:78 for Room types)The game roomia(number|number[]|string)[]The list of invalid answers for the current question, this array is populated when the following powerups are used: 50-50, eraser, immunity namestringThe client's nameoptionsobjectThe game options. This object has the same content as the options parameter, but fully populatedsocketWebSocketThe websocket that the client uses to connect to the roomindexnumberThe current question's indexavatarIDnumberThe client's avatar id

    • Events

      The powerup event is fired when a powerup has been successfully activatedgameEndedLeaderboard[] The gameEnded event is fired when the game has endedkick | Type | Description | |----------|-----------------| | string | The player's ID |

  • Types

    - <a id="questioncontent"></a> **QuestionContent**
        <table><thead><tr><th>Property</th><th>Types</th><th>Description</th></tr></thead><tbody><tr><td>
        
        `type`</td><td>`string`</td><td>The content type</td></tr><tr><td>`media`</td><td>An array of `Media` objects:<table><thead><tr><th>Property</th><th>Types</th><th>Description</th></tr></thead><tbody><tr><td>`type`</td><td>`string`</td><td>The media type</td></tr><tr><td>`video`</td><td>`string`</td><td>The media's video</td></tr><tr><td>`meta`</td><td>
        | Property     | Types     | Description                            |
        |--------------|-----------|----------------------------------------|
        | `width`      | `number`  | The media's width                      |
        | `height`     | `number`  | The media's height                     |
        | `layout`     | `string`  | The layout of the media                |
        | `text`       | `string`  | The media's text content               |
        | `bgColor`    | `string`  | The media's background color           |
        | `videoId`    | `string`  | The video ID associated with the media |
        | `start`      | `number`  | The start time of the media            |
        | `end`        | `number`  | The end time of the media              |
        | `duration`   | `number`  | How long should the media run for?     |
        | `kind`       | `string`  | The kind of media                      |
        | `embeddable` | `boolean` | Whether the media is embeddable        |
        | `title`      | `string`  | The media's title                      |
        | `lat`        | `number`  | The latitude of the media              |
        | `long`       | `number`  | The longitude of the media             |
        | `heading`    | `string`  | The heading of the media               |
        | `pitch`      | `number`  | The pitch of the media                 |
        </td><td>The media's metadata</td></tr></tbody></table></td><td>The content's media</td></tr><tr><td>
    
        `text`</td><td>`string[]` `string`</td><td>The content text</td></tr><tr><td>`hasMath`</td><td>`boolean`</td><td>Whether the content has math</td></tr><tr><td>`math`</td><td>
        | Property   | Types      | Description    |
        |------------|------------|----------------|
        | `latex`    | `string[]` | The latex math |
        | `template` | `string`   | The template   |
        
        </td><td>The question's latex math</td></tr></tbody></table>
    - <a id="leaderboard"></a> **Leaderboard**
        | Property | Types    | Description              |
        |----------|----------|--------------------------|
        | `name`   | `string` | The player's name        |
        | `rank`   | `number` | The player's rank        |
        | `score`  | `number` | The player's final score |

Examples

  • A basic Quizziz Game client

// The only class we need is Game
import { Game } from './src/index.js';

// Everything is async, so we make a holder function
(async function() {
    // Create a new game
    const myGame = new Game();

    // setup the events
    myGame.on("disconnect", data => {
        console.log(`Oh no! You disconnected with exit code ${data.code}.\n The reason for disconnect was ${data.reason.toString()}`);
    })

    myGame.on('start', () => console.log("The game is starting"));

    myGame.on("doneAnswering", () => console.log("You answered all the questions!"));

    myGame.on("join", () => console.log("You're in!"));

    myGame.on("powerup", data => {
        console.log(`You used the ${data.name} powerup!`);
        if (["50-50","eraser"].includes(data.name)) {
            console.log(`Now, the possible answers are: ${data.visibleOptions.join(', ')}`)
        } else if (data.name === "streak-booster") {
            console.log(`Your streak has been boosted by ${data.streakChangeBy}!`)
        }
    });

    myGame.on("gameEnded", data => {
        data.forEach(leaderboard => {
            console.log(`${leaderboard.name} finished with a rank of #${leaderboard.rank} and a score of ${leaderboard.score}`)
        })
    });

    myGame.on("kick", data => console.log(`${data} was kicked from the game`));

    myGame.on("answer", data => {
        console.log(`You answered ${data.isCorrect ? "" : "in"}correctly on attempt #${data.attempt}. ${data.score} has been added to your score. Your streak is ${data.streak.currentStreak}.`)
    });

    myGame.on("question", data => {
        switch (data.type) {
            case "MATCH":
            case "MSQ":
            case "REORDER":
                myGame.answer(/* my answer */ Array(data.answers.length).fill(0).map((_0, index) => index))
                break;
            case "MCQ":
                myGame.answer(/* my answer */ 0)
                break;
            case "DRAW":
            case "BLANK":
                myGame.answer("I <3 RedYetiDev")
                break;
            default:
                console.log(data.type + ": Skipped");
                myGame.skip();
        }
    })

    // join the game
    myGame.joinGame("560018", "RedYetiDev", 1, {
        correctPoints: 2000,
        incorrectPoints: 500
    })
})();
0.0.1

2 years ago