Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
open-trivia-db
Advanced tools
open-trivia-db
is a small and simple library for interacting with the OpenTDB API.
Live Demo: https://replit.com/@Elitezenv/open-trivia-db-DEMO?v=1
Documentation: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
Planning a trivia command for your Discord bot?
Checkout discord-trivia
! https://www.npmjs.com/package/discord-trivia
Boolean questions now return their incorrect answer as a BooleanString and not a string[]
Question type now takes a generic of type QuestionTypes | unknown. Default is unknown
Created typings for correct and incorrect values.
Included URL for Session.reset() as it was missing.
import { getQuestions, CategoryNames } from "open-trivia-db";
const questions = await getQuestions({
amount: 10,
category: CategoryNames.Animals,
difficulty: QuestionDifficulties.Easy,
})
[
{
value: 'How many teeth does an adult rabbit have?',
category: { id: 27, name: 'Animals', getData: [Function: getData] },
type: 'multiple',
difficulty: 'easy',
correctAnswer: '28',
incorrectAnswers: [ '30', '26', '24' ],
allAnswers: [ '24', '28', '30', '26' ],
checkAnswer: [Function: checkAnswer]
}
...
]
Questions can be fetched via the getQuestions()
function by supplying options such as amount
, category
, difficulty
, type
, session
and encode
.
type
: The kind of questions, such as multiple choice ("multiple"
) or true/false ("boolean"
).
session
: A session instance or session token. Learn about sessions
encode
: The encoding of the questions such as base64
, urlLegacy
, url3968
or none
which is the default.
You can apply options via their respective enums.
The result will be an array of questions.
import {
CategoryNames,
QuestionDifficulties,
QuestionTypes,
QuestionEncodings
} from "open-trivia-db";
getQuestions({
amount: 50,
category: CategoryNames["Entertainment: Japanese Anime & Manga"],
difficulty: QuestionDifficulties.Hard,
type: QuestionTypes.Multiple,
encode: QuestionEncodings.None
})
A category resolvable can either be a category name or id. Category id's range from 9-32 inclusive, for there are 23 categories.
To jump between resolvables, use Category.idByName()
and Category.nameById()
.
import { Category, CategoryNames } from "open-trivia-db";
Category.idByName('Art'); // 25
Category.nameById(25); // 'Art'
Use Category.getCategory()
to get a category's data such as name, id, and question counts.
import { Category, CategoryNames } from "open-trivia-db"
Category.getCategory(CategoryNames.Geography)
.then(console.log)
{
id: 22,
name: 'Geography',
questionCount: {
total: 275,
easy: 80, medium: 139, hard: 56
}
}
You can also complete a category's data through a question via Question.category.getData()
const targetQuestion = questions[0] // from getQuestions()
targetQuestion.category.getData()
.then(console.log)
A session ensures you are not supplied a question more than once throughout it's lifetime.
Initialize a session and supply the instance into getQuestions()
. Make sure to await or resolve Session.start()
.
import { Session } from "open-trivia-db"
const mySession = new Session();
await mySession.start();
getQuestions({
session: mySession
})
getQuestions()
will return an error once your session has served every single question in OpenTDB. Don't worry, theres thousands of questions! You will likely never come accross a session's end. However, if you wish to reset your session, use Session.reset()
.
await mySession.reset();
Documentation: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
FAQs
A small and simple wrapper for the Open Trivia Database API.
We found that open-trivia-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.