diff --git a/README.md b/README.md index ebf62d5..95dba72 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,96 @@ # POAP Reddit Bot: Code distribution for POAP events +# Table of Contents +- [Usage](#usage) + * [Attendees](#attendees) + * [Admin via Reddit](#admin-via-reddit) + - [Create Event](#create-event) + - [Update Event](#update-event) + - [Create Claims](#create-claims) + * [Admin via API](#admin-via-api) +- [Setup](#setup) + * [Clone](#clone) + * [Configuration](#configuration) + * [Deploy](#deploy) + + [Docker](#docker) + + [Python](#python) + +# Usage +## Attendees +todo + +## Admin via Reddit +Administration of the bot can be performed using commands issued via Reddit private messages (not the newer reddit chat feature). The permission model for this is currently rudimentary. It consists of only a whitelist of reddit usernames controlling access to these commands. This whitelist can only be updated via the API. + +To issue a command simply send a private message to the bot user following the formats outlined below. The following link will show you an example: [Example Command](https://www.reddit.com/message/compose?to=/u/YourPOAPBot&subject=command&message=create_event%20event_id%20event_name%20event_code%202021-05-01T00%3A00%3A00%202021-05-02T00%3A00%3A00%2030%2010) + +The bot is strict about the format of these commands. +#### Create Event +``` +create_event event_id event_name event_code start_date expiry_date minimum_age minimum_karma +``` +#### Update Event +``` +update_event event_id event_name event_code start_date expiry_date minimum_age minimum_karma +``` +#### Create Claims +``` +create_claims event_id code1,code2,code3 +``` +... more commands coming + +## Admin via API + +todo + # Setup +## Clone +First, clone the repository and change into the directory ```bash git clone https://github.com/badinvestment/poap-reddit-bot.git cd poap-reddit-bot ``` +## Configuration + Configure [settings.yaml](settings.yaml) with reddit auth information ```yaml reddit: auth: - username: + username: # It's recommended to create a dedicated account, but you can use a personal account password: client_id: - client_secret: - user_agent: "POAPbot by /u/Bad_Investment https://github.com/badinvestment/poap-reddit-bot" + client_secret: + user_agent: "POAPbot by /u/Bad_Investment https://github.com/badinvestment/poap-reddit-bot" # Optionally change this, but you don't need to + +db: + url: sqlite:///poap.db # Optionally rename sqlite db file (Postgres support coming soon) + +poap: + url: https://poap.xyz/claim/ # Optionally change POAP claim link. This link is forced when adding claims via Reddit DMs ``` -## Docker +## Deploy -Coming soon - -## Python -To start the app server, run: -```bash -pip3 install -r requirements.txt # setup a virtual environment first, if desired -uvicorn app:app #optional flags: --host 0.0.0.0 --port 8000 -``` -This will start a webserver on your machine and by default expose the API at [localhost:8000](http://localhost:8000) +Both of the below methods will start a webserver on your machine and by default expose the API at [localhost:8000](http://localhost:8000) To interact with the API, the OpenAPI (Swagger) interface is available at [localhost:8000/docs](http://localhost:8000/docs) -ReDoc is also available at [localhost:8000/redoc](http://localhost:8000/redoc) \ No newline at end of file +ReDoc is also available at [localhost:8000/redoc](http://localhost:8000/redoc) + +### Docker + +To start the app server using docker-compose, run: +```bash +docker-compose up +``` + +### Python +To start the app server directly, run: +```bash +pip3 install -r requirements.txt # setup a virtual environment first, if desired +uvicorn poapbot.app:app #optional flags: --host 0.0.0.0 --port 8000 +``` \ No newline at end of file diff --git a/db_init.py b/db_init.py new file mode 100644 index 0000000..2f0c7ef --- /dev/null +++ b/db_init.py @@ -0,0 +1,6 @@ +import sqlalchemy + +from poapbot.db import metadata, DB_SETTINGS + +engine = sqlalchemy.create_engine(DB_SETTINGS.url) +metadata.create_all(engine) \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..4d14ecb --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,16 @@ +version: "3" +services: + poapbot: + logging: + driver: "json-file" + options: + max-size: "100m" + restart: always + build: + context: . + dockerfile: ./Dockerfile + command: bash -c "python db_init.py && uvicorn poapbot.app:app --host 0.0.0.0 --port 8000" + ports: + - 8000:8000 + volumes: + - "./:/app" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f038a74..715fab8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,11 @@ pydantic==1.8 fastapi==0.63.0 -databases -uvicorn[standard] +databases==0.4.1 +uvicorn[standard]==0.13.4 asyncpraw==7.2.0 pyyaml==5.4.1 fastapi-crudrouter==0.7.1 ormar[sqlite]==0.10.5 python-multipart==0.0.5 -pandas -colorlog \ No newline at end of file +pandas==1.2.4 +colorlog==5.0.1 \ No newline at end of file