/tag-youre-it-backend

🌐 A real world FastAPI example

Primary LanguagePythonMIT LicenseMIT

GitHub Actions status Coverage Release Status Docs Badge Site Badge Style Badge MyPy Badge License Shield

tag-youre-it-backend 🏃

tag

FastAPI backend for Reddit's TagYoureItBot

Project was scaffolded with cookiecutter-fastapi-backend

How To Play (beta)

For now, this bot will only supports subreddit-level play (one active game per sub). This prevents trolls from locking a global game to a (private)subreddit (See the TODO for future enhancements):

Invoke u/TagYoureItBot by replying to a Reddit post or comment with the phrase !tag e.g. u/TagYoureItBot !tag. 1 of 2 things can happen:

  • There is no active game. u/TagYoureItBot will reply to the same post or comment notifying the author they are now "it". A countdown will start and this author will have an allotted time to "tag" another Reddit user (within the same sub). If the countdown expires and the author has not tagged another user, the game will end. Otherwise...
  • There is an active game. If you are the "it" user, the game will continue (see previous paragraph). If you're not it, the bot will reply to your comment stating such. The comment will include a countdown time of how much longer the current tagged user has to tag someone until the game automatically ends.

Rules

You can't tag...

  1. yourself
  2. back....yet
  3. a user who has opted out of playing
  4. u/TagYoureItBot

To opt out of playing, send u/TagYoureItBot a private message which contains 'i dont want to play tag' as the subject ❤️

If you would like to opt back in, send u/TagYoureItBot a private message with 'i want to play tag again' as the subject

Why did I build this?

a) A few years ago I read a reddit blog post, where they outlined how r/Place was built. I got inspired by the community aspect of the project, and wanted to create something similar (obviously no where near the scale/volume). So I started to create a digital version of Tag that can be played on Reddit. I pushed a closed source v1 last year, but the game logic was coupled to the web api code (FastApi). I decided to decompose the bot logic into an open source package and keep the web api closed source.

b) Want keep my Python skills fresh since I've been doing a lot of full-stack development in my previous role (React/Java).

c) Showcase the ecosystem of my open source projects and how they work together: Create Release GHA, FastAPI Backend Base, Reddit Bot Base.

d) I'm curious to see stats of user engagement (how long did a game chain last, how many users did it contain, which subreddit plays the most, etc)

See r/TagYoureItBot for more updates.

Architecture

Architecture Workflow

Development

  1. make up
  2. visit http://localhost:8666/v1/ping for uvicorn server, or http://localhost for nginx server
  3. Backend, JSON based web API based on OpenAPI: http://localhost/v1/
  4. Automatic interactive documentation with Swagger UI (from the OpenAPI backend): http://localhost/docs

The entrypoint to the bot can be found in src.core.bot. In short, for each sub which the bot is enabled, an async process will be pushed onto the event loop (each sub gets their own game engine).

Migrations

Every migration after that, you can create new migrations and apply them with

$ make alembic-make-migrations "cool comment dude"
$ make alembic-migrate

pre-commit hooks

If you haven't already done so, download pre-commit system package and install. Once done, install the git hooks with

$ pre-commit install
pre-commit installed at .git/hooks/pre-commit

Made with ❤️ from Cali