tin

tinyslacktriviabot

Configurable slack bot that posts trivia questions. Has support for various question providers, from classic trivia questions to guessing country flags and even evaluating javascript code answers.

Showing:

Popularity

Downloads/wk

19

GitHub Stars

0

Maintenance

Last Commit

4yrs ago

Contributors

2

Package

Dependencies

8

Size (min+gzip)

528.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

tinyslacktriviabot

A tiny, extensible slack trivia bot

version dependencies

Requirements

node v8

Installation

npm i tinyslacktriviabot

Usage

Create a file trivia.js and run it with node trivia.js

Minimum configuration
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 as trivia.js

All databases included configuration
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)

Advanced configuration

Configuration details

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'}]
    

RepositorySettings

Base settings

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
JsonRepository.js dbPath: 'jeopardy.json'
dbPath: 'questions.json'
dbPath: 'wow.json'
dbPath: 'capitals.json'
dbPath: 'flags.json'
DbRepository.js dbPath: 'trivia.db'
HsRepository.js dbPath: 'hs.json'
JsRepository.js dbPath: 'jsQuestions.json'
TriviaDbRepository.js dbPath: 'https://opentdb.com/api.php?amount=50&type=multiple&encode=url3986'

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

JsonRepositorySettings

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

DbRepositorySettings

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'

History

v4.0.0

  • 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

v3.0.0

  • configure multiple repositories
  • JsRepository (js questions with evaluator)
  • JsonRepository (questions from json file)

v2.0.0

  • opentdb support

v1.0.0

  • Initial version

License

© 2017 MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100