Attempt to find the answer most likely to be correct from a question given on HQ Trivia. It will attempt to utilise various APIs, and create a "score" based on the results.
Connecting to the HQ Trivia API, we are able to see when a broadcast
will be taking place. If the bot finds a websocketUrl
available, it will create a new session, and begin monitoring that data. If a question is passed through, it will then clean the question and answers, and use third party services to try and find results.
A scoring system will be used to determine how likely that any one of the answers is the correct one. This won't be full-proof, but will hopefully give a better indicator of a correct answer. Below is a summary of how each part of the system works. This will need to be updated as time goes on. Numbers will need to be updated to try and give the best representational score possible.
Resource | Scoring type | Weight |
---|---|---|
Google Search | no. of results | 20% |
Google Search | Number of "hits" | 40% |
Wikipedia | Number of "hits" | 40% |
Using Google's custom search engine REST API, we are able to return a list of results based upon a query. This gives us important data that we can validate our question against. We will take:
- The number of results
- The number of "hits" returned, checking each relevant word in the question against the descriptions from the results.
We can that use that information and compare it to each answer, creating a score.
Similarly to Google, we will use Wikipedia's API to search for each answer. Using the question, we will check for "hits" matching relevant words.
git clone
the repositorycd hqt
touch .env
, and in that file enter:GOOGLE_KEY
- Your Google Custom Search API KeyGOOGLE_ENGINE_ID
- Your Google Custom Search Engine IDBEARER_TOKEN
- Your bearer token retrieved from the HQ Trivia API
npm install
npm run start
HQT
β README.md
β package.json
β package-lock.json
β .gitignore // Files we don't want to commit to the repo
β .babelrc // Babel configuration
β .eslintrc.json // ESLint configuration
β
ββββdata
β ββββquestions.json // Questions recieved through the open websocket connection
β
ββββdist // Transpiled code will end up here
β
ββββexamples
β β api-data.json // Example data directly from the API, when a broadcast is in progress
β β curl.txt // Example curl request to the API
β ββββwebsocket-data.json // Example websocket data from the broadcast
β
ββββsrc
β init.js // Initialiser script
β
ββββhelpers
β β index.js
β β formatNumber.js // Parse floats and turn them into integers
β ββββgetHits.js // Find the number of matches an array of words has in a text
β
ββββlog
β β index.js
β β success.js // console.log success formatting
β β warn.js // console.log warn formatting
β β error.js // console.log error formatting
β ββββreset.js // Clear the console
β
ββββreader
β β index.js
β β scan.js // Read image, and grab text from it
β β wordlist.js // List of words to strip out of a question
β ββββparse.js // Prepare text for search using resolvers
β
ββββresolvers
β index.js
β wikipedia.js // Results returned from Wikipedia's API
ββββgoogle.js // Results returned from Googles search API