bettor

module
v0.0.0-...-05eea06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2023 License: MIT

README ¶

bettor 🎲

CI CD

Bettor is a parimutuel betting (or pool betting) Discord bot and API for running your own virtual betting books. Inspired by Twitch Predictions.

Make a fun game out of predictions, document friendly disagreements, and maybe figure out who's the best at seeing the future 🔮🙀! Create bets with your friends on whatever you want right there in the context of a conversation on Discord. Bettor will keep track of everyone's bets and handle pay outs.

Bettor Discord commands Creating a bet Locking a bet

Discord Bot

Bettor provides a bot that can be invited to Discord servers (or "guilds"). It provides commands for creating and managing betting pools like /start-bet, /join-bet, and /bettor. It creates a betting "book" for the Discord server which isolates that server's bets, markets, and users from other servers. Upon first interaction with the bot, users in the server are initialized with a default value of betting points.

The Discord bot must be added to servers with applications.commands scopes granted.

API

Bettor provides a Buf Connect, gRPC-compatible API and server. Web clients can hit this via gRPC-Web generated clients.

Resources are partitioned by betting book.

See docs/ for API documentation.

Note As of 1/23/23 usage, data is persisted using gobs in files. This should be replaced with a proper database eventually.

Warning As of 1/23/23 usage, authn/z and perms are not implemented because access to the API is only possible by the Discord bot which piggybacks on Discord's user identity to restrict requests.

Using Bettor

At the moment, I am not running a public Bettor Discord bot. I built this in a quick sprint as a fun toy for my own Discords and to play with some Go tools.

If you want to run your own Bettor instance, you can adapt or run this project with your own Discord credentials.

  • To deploy to Fly.io:
    • Create your own app with Fly.io and update app in fly.toml.
    • Create a mounted volume for persistence.
    • Create a Discord Bot and provide discordToken as an environment variable using Fly.io secrets.
  • Deploying elsewhere should be easy. Just make sure that discordToken is provided as a flag or environment variable.

I do not expect to work on this anymore or host a public version, but who knows. I'd love to hear from you if you found this cool or have feedback or requests. 😇

Development

APIs are defined using Protocol buffers built with Buf. Server is implemented using Buf Connect.

Integration with Discord API is provided by bwmarrin/discordgo. Tracing and logging are provided using OpenTelemetry and go-kit/log.

My Bettor instance is deployed to Fly.io via Docker. CI/CD is provided by Github Actions.

Dependencies are managed using Nix. Optionally if direnv is installed, a Nix shell will be started automatically when entering the root directory.

Running Locally

Install dependencies using Nix. default.nix defines all development dependencies for the project.

If you want to run the Discord bot, you will need to enable it and provide a Discord bot token as flags in the server main file. For dev testing, you will want to use a different Discord bot than the one used in production, joined to your test Discord servers.

See flags: -runDiscord, -discordToken, -cleanUpDiscordCommands

Go flags can be provided via environment variables and .env files using joho/godotenv.

$ make run-local-server
$ make run-local-bot
Workflow

See development workflow commands in Makefile.

$ make gen
$ make test
$ make lint
$ make docker

Directories ¶

Path Synopsis
api
cmd
internal
app/bettor/discord
Package discord implements a Discord bot that can join and run in guilds.
Package discord implements a Discord bot that can join and run in guilds.
pkg/envflag
Package envflag provides a wrapper around the standard flag package that can fall back to environment variables
Package envflag provides a wrapper around the standard flag package that can fall back to environment variables

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL