- Notifications
You must be signed in to change notification settings - Fork134
A Discord bot to streamline running D&D 5e.
License
avrae/avrae
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Avrae is a Discord bot designed to help you and your friends play D&D online.
You can join the Avrae Development Discordhere, and invite Avrae to your own Discordserverhere!
With a custom dice parser, Avrae is one of the most advanced dice rollers on Discord, capable of supporting pretty muchevery type of roll needed to play D&D. Advantage, disadvantage, and crits are built in, you can keep, drop, or rerolldice as needed, dice can explode, and dice can be bounded.
Want to use the dice roller in your own code? Check outthe code!
Avrae can read character sheets from D&D Beyond, Dicecloud, or a Google Sheet, automatically generating macros to rollattacks, ability checks, and saving throws. A player can then simply use a command to make a check, save, attack, orcast, and all necessary rolls will be resolved automatically.
The initiative tracker is a fast way to track combat in a text channel. It supports automatic combatant sorting, HP, AC,resistance, and status effect tracking, and integration with the character sheet manager and 5e content to furtherstreamline combat.
Have a feature in mind that isn't already in Avrae? Avrae provides a fully-featured modding API to write your owncommands, and a place to share them with the community!
Check outthe docs and theAlias Workshop!
There are a few options to run Avrae locally. Docker is easier to get started with with less managment of dependencies,but slower and more resource-intensive.
Check outREADME-docker.md.
Services/OS
- Ubuntu 18.04+ or other UNIX system (Windows is compatible but untested)
- Redis Server 4+ (https://redis.io/download)
- MongoDB Community Server 3.6+ (https://www.mongodb.com/try/download/community)
- Python 3.8+ (https://www.python.org/downloads/)
Support Files
You'll need to create a Google Drive Service Account. You can find instructions on how to dothishere.
Follow steps 1-7 in theFor Bots: Using Service Account portion. Rename the JSONavrae-google.json
and put it inthe project root.
Python Packages
We recommend using aVirtual Environment for Avrae development to preventpackage installs from polluting the global Python install. You can create and active a virtual environment by running:
$ python3 --version# to ensure that you are creating a venv from the right python version$ python3 -m venv venv$source venv/bin/activate# if the venv was set up correctly, you should see (venv) before your username in the terminal# run these commands to check the installed version and path(venv) $ python --versionPython 3.X.X(venv) $ pip --versionpip X.Y.Z from (project root)/venv/lib/python3.X/site-packages/pip (python 3.X)
To install the dependencies, run:
(venv) $ pip install -r requirements.txt
Optional - You can install theavrae-automation-common
anddraconic
dependencies from your local filesystemrather than pip+git, to make working on depended libraries in parallel easier:
(venv) $ pip install /path/to/automation-common -e(venv) $ pip install /path/to/draconic -e
Any changes to the library will immediately be picked up in avrae without requiring a reinstall of the library.
Name | Description | Used For | Set By (dev) | Set By (prod) | Required? |
---|---|---|---|---|---|
DISCORD_BOT_TOKEN | The bot token used to authenticate to the Discord API. See "Discord Bot Token", below. | Connecting to the Discord API | you | AWS Secrets Manager via Terraform | yes |
TESTING | Whether the bot is running in a dev environment. See "Testing Env Var", below. Also set iftest arg supplied in CLI. | Enabling certain debug logs | you | N/A | no |
ENVIRONMENT | The environment the bot is running in. Defaults todevelopment ifTESTING is set, orproduction otherwise. | Logs (e.g. Datadog) | set todevelopment | Terraform | yes |
GIT_COMMIT_SHA | The commit SHA of the running deploy. | Cluster coordination key | N/A | Docker via GH Actions | prod only |
NUM_CLUSTERS | The number of clusters (ECS tasks) Avrae is running across. Defaults to 1. | Cluster coordination | N/A | Terraform | prod only |
NUM_SHARDS | An explicit override for the number of shards to run across all shards. Defaults to dynamic value from Discord. | Cluster coordination | N/A | Terraform (nightly/stg) | no |
RELOAD_INTERVAL | An interval to automatically reload gamedata at, in seconds. Defaults to 0. This should be set to 0. | Loading gamedata | N/A | N/A | no |
ECS_CONTAINER_METADATA_URI | https://docs.aws.amazon.com/AmazonECS/latest/userguide/task-metadata-endpoint-v3-fargate.html | Cluster coordination | N/A | AWS Fargate | prod only |
MONSTER_TOKEN_ENDPOINT | The base URL that monster token paths defined in monster gamedata are relative to. | !token | N/A | Terraform | prod only |
DDB_MEDIA_S3_BUCKET_DOMAIN | The S3 bucket domain for DDB media assets, such as character avatars. | !token | N/A | Terraform | prod only |
DRACONIC_SIGNATURE_SECRET | The secret used to sign signatures in the Draconic API'ssignature() function. Defaults tosecret . | Aliasing | optional | AWS Secrets Manager via Terraform | prod only |
MONGO_URL | The connection URL used to connect to MongoDB. Defaults tomongodb://localhost:27017 . | Connecting to database | you | AWS Secrets Manager via Terraform | yes |
MONGODB_DB_NAME | The name of the database in Mongo to use. Defaults toavrae . | Connecting to database | optional | Terraform | no |
REDIS_URL | The connection URL used to connect to Redis. Defaults toredis://localhost:6379/0 . | Connecting to database | you | Terraform | yes |
REDIS_DB_NUM | The database number to use in Redis. Defaults to0 . | Connecting to database | optional | Terraform | no |
DEFAULT_PREFIX | The default command prefix. Defaults to! . | Running commands | optional | Terraform | no |
DD_SERVICE | The name of the service, used for DataDog. If not set, disables DataDog tracing and profiling. | Monitoring | optional | Terraform | prod only |
NO_DICECLOUD | If set, disables Dicecloud v1 connections in the running bot. Defaults to true ifDICECLOUD_USER is not set. | CI | optional | N/A | no |
DICECLOUD_USER | TheDicecloud v1 username of the bot account. | Sheet Import | you | Terraform | yes |
DICECLOUD_PASS | The Dicecloud v1 password of the bot account. | Sheet Import | you | AWS Secrets Manager via Terraform | yes |
DICECLOUD_TOKEN | The Dicecloud v1 API key of the bot account. | Sheet Import | you | AWS Secrets Manager via Terraform | yes |
NO_DICECLOUDV2 | If set, disables Dicecloud v2 connections in the running bot. | CI | optional | N/A | no |
DCV2_NO_AUTH | If set, connects to Dicecloud v2 without any form of authentication. As such, any imported sheets must be public. Defaults to true ifDICECLOUDV2_USER is not set. | CI | optional | N/A | no |
DICECLOUDV2_USER | TheDicecloud v2 username of the bot account. | Sheet Import | you | Terraform | yes |
DICECLOUDV2_PASS | The Dicecloud v2 password of the bot account. | Sheet Import | you | AWS Secrets Manager via Terraform | yes |
GOOGLE_SERVICE_ACCOUNT | The contents of theGoogle Drive Service Account JSON key file. Defaults to a file namedavrae-google.json if not set. | Sheet Import | you | AWS Secrets Manager via Terraform | yes |
DDB_AUTH_SECRET | The secret used to sign JWT claims to exchange Discord user info for a STT via the Auth Service. | Entitlements | 1Password | AWS Secrets Manager via Terraform | DDB team only |
DDB_AUTH_WATERDEEP_SECRET | The secret used to verify JWTs returned from the Auth Service. | Entitlements | 1Password | AWS Secrets Manager via Terraform | DDB team only |
DDB_AUTH_AUDIENCE | Override a verification for theaud claim of an Auth Service JWT. Defaults toavrae.io . | Entitlements | N/A | N/A | no |
DDB_AUTH_ISSUER | Override a verification for theiss claim of an Auth Service JWT. Defaults todndbeyond.com . | Entitlements | N/A | N/A | no |
DDB_AUTH_EXPIRY_SECONDS | Override a JWT's lifetime for the Discord -> STT exchange. Defaults to 5 minutes (300). | Entitlements | N/A | N/A | no |
DDB_AUTH_SERVICE_URL | The base URL for requests to the DDB Auth Service. If not set, all entitlements code is disabled. | Entitlements | 1Password | Terraform | DDB team only |
DYNAMO_REGION | The AWS region to search for resources in. This controls more than Dynamo. Defaults tous-east-1 . | Entitlements | 1Password | Terraform | DDB team only |
DYNAMO_ENTITLEMENTS_TABLE | The name of the DynamoDB table to query for entitlements data. Defaults toentitlements-live . | Entitlements | 1Password | Terraform | DDB team only |
AWS_ACCESS_KEY_ID | The AWS Access Key ID to connect to AWS resources. | Entitlements | 1Password | AWS Fargate | DDB team only |
AWS_SECRET_ACCESS_KEY | The AWS Secret Access Key to connect to AWS resources. | Entitlements | 1Password | AWS Fargate | DDB team only |
NLP_KINESIS_DELIVERY_STREAM | The name of the AWK Kinesis Firehose delivery stream used to ingest NLP events. | UPenn NLP | N/A | Terraform | no |
CHARACTER_COMPUTATION_ENDPOINT | The API endpoint used to call the Character Computation lambda. | Sheet Import | you | Terraform | DDB team only |
DDB_WATERDEEP_URL | The base URL for requests to the Waterdeep monoloth. Defaults tohttps://www.dndbeyond.com . | Campaign Link | 1Password | Terraform | no |
DDB_GAMELOG_ENDPOINT | The endpoint used to post Game Log events to the Game Log. Defaults tohttps://game-log-rest-live.dndbeyond.com/v1 . | Campaign Link | 1Password | Terraform | no |
DDB_CHARACTER_SERVICE_URL | The base URL for requests to the Character Service. Defaults tohttps://character-service.dndbeyond.com/character/v5 . | Campaign Link | 1Password | Terraform | no |
DDB_SCDS_SERVICE_URL | The base URL for requests to the Simple Character Data Store. Defaults tohttps://character-service-scds.dndbeyond.com/v2 . | Campaign Link | 1Password | Terraform | no |
LAUNCHDARKLY_SDK_KEY | TheLaunchDarkly SDK Key. | Feature Flags | 1Password | AWS Secrets Manager via Terraform | DDB team only |
DBL_TOKEN | The Discord Bot List API token. | Updating server count | N/A | AWS Secrets Manager via Terraform | no |
Discord Bot Token
To create a Discord bot user, go to theDiscord Developer Portal.
New Application
, give it a cool name,Create
.Bot
>Add Bot
.- (Optional but recommended): Switch off
Public Bot
so only you can add this bot to servers. - Scroll down to
Privileged Gateway Intents
, and enable the switches to the right ofServer Members Intent
andMessage Content Intent
. Click to Reveal Token
, this is yourDISCORD_BOT_TOKEN
.
Testing Env Var
TheTESTING
env var, if present, enables/disables the following:
- Dicecloud Client: Meteor debug logs enabled
- cogs.publicity: Discord Bot List update disabled
- config:
ENVIRONMENT
set todevelopment
by default if not manually set - Discord Application Commands: enables command sync debug logs and command testing guilds
(venv) $ python dbot.pytest
VSCode launch.json Template
{"version":"0.2.0","configurations": [ {"name":"Run Avrae","type":"python","request":"launch","program":"dbot.py","console":"integratedTerminal","env": {"DISCORD_BOT_TOKEN":"","DISCORD_OWNER_USER_ID":"","DICECLOUD_USER":"","DICECLOUD_PASS":"","DICECLOUD_TOKEN":"","DICECLOUDV2_USER":"","DICECLOUDV2_PASS":"","MONGO_URL":"","REDIS_URL":"","ENVIRONMENT":"","DDB_AUTH_SECRET":"","DYNAMO_REGION":"","DYNAMO_ENTITLEMENTS_TABLE":"","DDB_AUTH_SERVICE_URL":"","AWS_ACCESS_KEY_ID":"","AWS_SECRET_ACCESS_KEY":"","DDB_AUTH_WATERDEEP_SECRET":"","CHARACTER_COMPUTATION_ENDPOINT":"","DDB_WATERDEEP_URL":"","DDB_GAMELOG_ENDPOINT":"","DDB_CHARACTER_SERVICE_URL":"","DDB_SCDS_SERVICE_URL":"","LAUNCHDARKLY_SDK_KEY":"" } } ] }
This repo contains a pytest test suite that mocks a number of interactions between Avrae and the Discord API, and runsend-to-end tests between user input, bot output, and database state.
These tests can be found intests/
.
(venv) $ pip install -r tests/requirements.txt
Tests can either be run using Docker Compose, or manually.
Docker
docker-compose -f docker-compose.ci.yml -p avrae up -d --builddocker logs -f avrae_tests_1
Once tests complete, it is recommended to clean up the containers withdocker-compose down
.
Manually
(venv) $ TESTING=1 pytest tests/
In either case, you should setNO_DICECLOUD=1
.
Avrae uses Sphinx to generate documentation for the Aliasing API and Automation Engine. The source for thisdocumentation can be found indocs/
.
By default, each push tomaster
will trigger a new build of the docs athttps://avrae.readthedocs.io/en/latest/.
You can also build the docs manually:
# install dependencies(venv) $cd docs(venv) $ pip install -r requirements.txt# build and open browser(venv) $ make preview# build(venv) $ make html
Avrae usesBlack to format and lint its Python code.Black is automatically run on every commit via pre-commit hook, and takes its configuration options from thepyproject.toml
file.
The pre-commit hook is installed by by runningpre-commit install
from the repo root.The hook's configuration is governed by the.pre-commit-config.yaml
file.
In order to runpre-commit
orblack
, they must be installed.These dependencies are contained within thetest/requirements.txt
file, and can be installed like so:
(venv) $ pip install -r test/requirements.txt
About
A Discord bot to streamline running D&D 5e.