A tiny, extensible slack trivia bot
node v8
npm i tinyslacktriviabot
const { TinySlackTriviaBot } = require('tinyslacktriviabot');
const config = {
name: 'trivia',
token: 'SLACK_BOT_TOKEN',
channels: ['SLACK_CHANNEL_ID']
}
TinySlackTriviaBot.run(config)
Get a
<SLACK_BOT_TOKEN>
here https://my.slack.com/services/new/bot
Note: configuration can also be stored in a file
config.json
in the same folder astrivia.js
const { TinySlackTriviaBot } = require('tinyslacktriviabot');
const config = {
name: 'trivia',
token: 'SLACK_BOT_TOKEN',
channels: ['SLACK_CHANNEL_ID'],
repository: [
{
'ignore': false,
'path': 'DbRepository.js'
},
{
'ignore': false,
'path': 'TriviaDbRepository.js'
},
{
'ignore': false,
'path': 'JsonRepository.js'
},
{
'ignore': false,
'path': 'HsRepository.js'
},
{
'ignore': false,
'path': 'JsRepository.js'
},
{
'ignore': false,
'path': 'JsonRepository.js',
'dbPath': 'wow.json'
},
{
'ignore': false,
'path': 'JsonRepository.js',
'dbPath': 'jeopardy.json'
},
{
'ignore': false,
'path': 'JsonRepository.js',
'dbPath': 'capitals.json',
'questionPath': ['text'],
'answerPath': [['answers', 0, 'text', 0]]
},
{
'ignore': false,
'path': 'JsonRepository.js',
'dbPath': 'flags.json',
'questionPath': ['text'],
'answerPath': [['answers', 0, 'text', 0]]
}]
}
TinySlackTriviaBot.run(config)
Name | Type | Description | Default |
---|---|---|---|
name | string | Bot name (will appear in channels, overrides the name set when the SLACK_BOT_TOKEN was created) | trivia |
showScoreInterval | number | Number of correct questions after which the scores will be automatically shown, scores command resets this counter | 10 |
nextQuestionGap | number | Delay(ms) until next question is shown (eg. after correct answer or skip) | 5000 |
skipCount | number | Required skips to change question | 2 |
hintDelay | number | How often the hint command can be called | 10000 |
autoSkipAfter | number | Delay until question is automatically skipped | 30000 |
filters | array of string | each string is parsed as a regex with default flags 'ig' | [ ] |
repository | array of RepositorySettings | Configure preferred repositories | [{'path':'DbRepository.js'}, {'path':'TriviaDbRepository.js'}, {'path':'JsonRepository.js'}, {'path':'HsRepository.js'}, {'path':'JsRepository.js'}] |
Name | Type | Description | Example | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path | string | Absolute or relative path to repository (.js) |
'path': 'JsonRepository.js' (relative to tinyslacktriviabot repository folder) 'path': 'C:\\CustomRepository.js' When using absolute paths the '\' character needs to be escaped OOTB repositories 'path': 'JsonRepository.js' 'path': 'DbRepository.js' 'path': 'HsRepository.js' 'path': 'JsRepository.js' 'path': 'TriviaDbRepository.js' |
||||||||||
dbPath | string | Absolute or relative path to a database |
OOTB databases
|
||||||||||
ignore | boolean? | If set to true the repository is not loaded |
'ignore': true |
Note: The settings bellow allow you to use the OOTB repositories with alternative databses. Internally the question object needs to have this structure { question, answer, category, ... }
and these settings allow you to map a custom databse to the correct fields
Assume the question object from JSON has the following format
question = {
"text":"question text",
"answers":["first answer", "second answer"],
"parent": { "group":"category name" }
}
Note: Property paths are evaluated using object-path. Internally, tinyslacktriviabot uses the coalesce
function.
Name | Type | Description | Example | Result |
---|---|---|---|---|
questionPath | array? of string | Read a top-level property |
questionPath: ['text']
|
question.text |
answerPath | array? of string | Select first array item |
answerPath: ['answers', 0]
|
question.answers[0] |
categoryPath | array? of string | Selected nested properties. |
categoryPath: ['parent', 'group']
|
question.parent.group |
Name | Type | Description | Example |
---|---|---|---|
query | string | SQLite query to read 1 random question |
The default query for trivia.db is query: 'SELECT q as question, a as answer FROM QUESTIONS ORDER BY random() LIMIT 1'
|
- Each repository has it's own settings now
- Hearthstone respository
- World of warcraft, Jeopardy, country flags and country capitals json databases
- Export base models for easier extensibility
- configure multiple repositories
- JsRepository (js questions with evaluator)
- JsonRepository (questions from json file)
- opentdb support
- Initial version
© 2017 MIT