1.9.1 • Published 6 years ago
hqtrivia-api v1.9.1
HQ Trivia API
This is a Node.JS wrapper for HQ Trivia
Installation
npm i hqtrivia-api
API Methods
hq.getUserData()- Get the authenticated user datahq.getShows()- Get the game schedulehq.getLeaderboard()- Get the game leaderboardhq.getUserById()- Get user by IDhq.searchUsers()- Search usershq.getFriends()- Get all friendshq.acceptFriendRequest(userId)- Accept friend requesthq.addFriend(userId)- Add friendhq.getIncomingFriendRequests()- Get incoming friend requestshq.connectToGame()- Connect to the gamehq.disconnectFromGame()- Disconnect from the gamehq.getUpcomingSchedule()- Get upcoming games schedulehq.setToken(token)- Sets token for requestshq.changeUsername(username)- Change usernamehq.checkUsername(username)- Check usernamehq.makePayout(email)- Make payout
Registration methods
hq.sendCode(phone, [method])- Sends the code to the specified phonehq.confirmCode(code, [verificationId])- Confirm codehq.register(username, [referral], [verificationId])- Register an account if it is not registered
Trivia Game Methods
hq.sendAnswer(answerID, questionId)- Send answer to HQhq.sendSurveyAnswer(answerID, questionId)- Send survey answer to HQhq.useExtralive(questionId)- Use extra livehq.sendEraser(questionId)- Use eraserhq.getErasers(friendIds)- Get erasers
Words Game Methods
hq.sendLetter(roundId, showId, letter)- Send letter to HQhq.sendWord(roundId, showId, word)- Send word to HQ
Events
connected- Called when successfully connected to the game (Words, Trivia)disconnected- Called when disconnected from the game (Words, Trivia)question- Called when a question is received from the server (Trivia)questionClosed- Called when a question is closed (Trivia)questionSummary- Called when the summary of a question is received from the server (Trivia)questionFinished- Called when question is finished (Trivia)gameStatus- Called when the game status is received from the server (Words, Trivia)startRound- Called when the round starts (Words)letterReveal- Called when letter reveal (Words)endRound- Called when round ends (Words)showWheel- Called when wheel shows (Words)hideWheel- Called when wheel hideens (Words)guessResponse- Called after sending a letter or word (Words)
Trivia Example 1
const HQTrivia = require('hqtrivia-api')
const hq = new HQTrivia('[token]')
hq.connectToGame()
hq.on('connected', () => {
console.log('Connected to HQ WS')
})
hq.on('question', (data) => {
console.log(`Question #${data.questionNumber}/${data.questionCount}`) // Question #3/12
console.log(data.question) // In a jazz band, which instrument would be in the rhythm section?
console.log(data.answers.map(answer => answer.text).join(' | ')) // Trombone | Guitar | Violin |
hq.sendAnswer(data.answers[1].answerId, data.questionId) // Sends the answer "Guitar"
})
hq.on('disconnected', (code) => {
console.log('Disconnected from HQ WS')
})Words Example 1
const HQTrivia = require('hqtrivia-api')
const hq = new HQTrivia('[token]')
hq.connectToGame()
hq.on('connected', () => {
console.log('Connected to HQ WS')
})
hq.on('startRound', (data) => {
console.log(`Round Number #${data.roundNumber}/${data.totalRounds}`) // Round Number #9/10
console.log(`Hint: ${data.hint}`) // Hint: Circus Performance
console.log(`Puzzle: `) // Puzzle:
console.log(data.puzzleState.join(' | ')) // ******** | ******** | C********
hq.sendWord(data.roundId, data.showId, 'JUGGLING') // Send the letters "J", "U", "G", ...etc
hq.sendWord(data.roundId, data.showId, 'MULTIPLE') // Send the letters "M", "U", "L", ...etc
hq.sendWord(data.roundId, data.showId, 'CHAINSAWS') // Send the letters "C", "H", "I", ...etc
// or
hq.sendLetter(data.roundId, data.showId, 'J') // Send the letter "J"
hq.sendLetter(data.roundId, data.showId, 'U') // Send the letter "U"
hq.sendLetter(data.roundId, data.showId, 'G') // Send the letter "G"
})
hq.on('disconnected', (code) => {
console.log('Disconnected from HQ WS')
})Register example
const HQTrivia = require('hqtrivia-api')
const hq = new HQTrivia()
await hq.sendCode('+11111111111')
const response = await hq.confirmCode('0228')
if (response.accountRegistred) {
console.log(`token: ${response.token}`)
hq.setToken(response.token)
} else {
const token = await hq.register('jsoplox', 'machuita')
console.log(`token: ${token}`)
hq.setToken(token)
}