Coder Social home page Coder Social logo

nickatnight / tag-youre-it-backend Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 1.0 102 KB

๐ŸŒ A real world FastAPI example

License: MIT License

Makefile 1.38% Dockerfile 1.13% Python 92.84% Mako 0.61% Shell 1.20% Jinja 2.83%
api asyncio ci fastapi fastapi-sqlalchemy github-actions nginx postgresql reddit reddit-bot ruff

tag-youre-it-backend's Introduction

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

tag-youre-it-backend's People

Contributors

nickatnight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

siem2l

tag-youre-it-backend's Issues

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.