Giter Club home page Giter Club logo

sphinx's Introduction

Sphinx

A simple quiz bot template. Participants have to answer all questions correctly to succeed.

Commands

commands are structured like sphinx.scope.option [...arg]. Replace "sphinx" with the username of the Discord bot account used. All commands require the user to have the ADMINISTRATOR permission, as all implemented commands reset and debug values.

  • sphinx.setup Post the quiz message (can be in a locked channel)
  • sphinx.reset.cooldown <userid> Reset the cooldown for the supplied user
  • sphinx.reset.level <userid> Reset the level for the supplied user
  • sphinx.check <userid> Display the user's current colldown, level and next backoff time
  • sphinx.reload Reload quiz questions (run after changing ./questions folder content)
  • sphinx.debug.backoff Display the Backoff table and function as seen above

Role Gate

If supplied with the key .env key QUIZ_ROLE the application will add the specified role to users successfully taking the quiz and check for it to already be present before allowing the quiz to start. This feature is optional (remove the key from .env to disable).

Questions

Questions are supplied as a .toml file (the filename is arbitrary and can be descriptive) to the ./questions folder, following the following format:

# unique ID
id = "1"
# correct choice value (question answer)
correct = "A"

# dropdown choices
choices = [
	{ value = "A", description = "Option A (this is correct)" },
	{ value = "B", description = "Option B" },
	{ value = "C", description = "Option C" }
]

# (optional) description to display above the codeblock
description = """
Pick
A\
"""

# (optional) code to display in a codeblock
code = """
function hello() {
	console.log("Hello World")
}
"""
# (optional) language to use for the codeblock highlight
codelanguage = "js"

Note that the id key value needs to be unique between all questions, else a later entry will overwrite the previous with the same id.

Customize

The file constants.ts holds the configurable user-facing messages, responses, constants, symbols, and emojis used in the application.

Backoff

The default backoff function is

function backoffInMs(level: number): number {
	return (2 ** level / 4) * 60 * 60 * 1_000;
}

and results in the following values:

Lv: 0 | Backoff: 15m
Lv: 1 | Backoff: 30m
Lv: 2 | Backoff: 1h
Lv: 3 | Backoff: 2h
Lv: 4 | Backoff: 4h
Lv: 5 | Backoff: 8h
Lv: 6 | Backoff: 16h
Lv: 7 | Backoff: 1d
Lv: 8 | Backoff: 3d
Lv: 9 | Backoff: 5d

After the first attempt, a user will have to wait for 15 minutes, 30 minutes after the second, etc. (note that the return value, as suggested by the function name, should be wait time in milliseconds). Users gain a level as soon as the quiz starts to prevent aborting without consequence.

Should a user reach MAX_LVL their level is reset (by default 9).

Setup

Sphinx can run as a standard node process with

npm run build
npm run start

Alternatively, you can set up a docker ๐Ÿ‹ container with docker-compose up.

Note that in either case restarting the application will reset the level and cooldown of every involved user and reload all questions.

sphinx's People

Contributors

almostsouji avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.