Falchoin bot and api. https://sh.cfbrk.de/fc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Markus Becker dea7a818fb Allow CORS on API 5 months ago
choin Allow CORS on API 5 months ago
.gitignore Documentation and docker 11 months ago
Dockerfile Documentation and docker 11 months ago
README.md Add webhooks 5 months ago
setup.py Add requests to Dockerfile 5 months ago

README.md

falchoin

Falchoin bot and api.

Usage

pip3 install git+ssh://git@cfbrk.de/code.mtib.dev/falchoin.git#egg=falchoin

Move into a working directory that falchoin is supposed to use and create a secrets.json file, then run falchoin.

Contributing

  1. Check out the repo.
pip3 install -e .
  1. Create a feature branch.
  2. Do changes.
  3. Commit.
  4. Create a merge request.

Docker

Build

TAG=0.0.1
docker build -t "falchoin:$TAG" .

Run

You need to create a directory for falchoin to use for storing the database and a file in that directory for configuration. The following commands assume this directory is $PWD/secrets.

CONF_DIR="$PWD/secrets"
OUT_PORT=7473
TAG=0.0.1
docker run -it -v $CONF_DIR:/app -p 7473:$OUT_PORT --rm falchoin:$TAG

Assuming you have a file "secrets.json" the form:

{
	"client_id": "[client_id]",
	"client_secret": "[discord-secret]",
	"client_token": "<discord-token>"
}

running the container will create a "fcoin.db" in your secrets folder. This allows persistence between runs.

API

GET

/v1/transaction/transaction-id

Returns transaction details and status.

/v1/user/user-id

Returns user details, balance and outstanding (unaccepted) transactions.

/v1/users

Returns list of all users.

/v1/logs

Returns list of all transactions.

POST

/v1/send

Sends money using your secret key.

With body:

{
  "from": "sender-id",
  "to": "receiver-id",
  "key": "sender-key",
  "amount": 1337
}

/v1/request

Posts a request for money transfer.

With body:

{
  "from": "sender-id",
  "to": "receiver-id",
  "key": "receiver-key",
  "webhook": "url (optional)",
  "amount": 1337
}

Will cause the bot to contact the sender with the info and require authentication.

Immediate Response

{
  "success": true,
  "id": "transaction-id"
}

Then the application will have to regularly check the transaction ID for fulfilment (before sending whatever was paid). The server will send a POST request to the provided webhook as soon as the sender has accepted or refused. The body is identical to the updated /v1/transactions/transaction-id.

/v1/respond

Responds to a requested money transfer.

This way if someone requests you to send them money you can programmatically accept. Maybe we could even let users register webhooks for when they receive a request. This uses the secret key of the money-sender. This key can only be received from the discord bot by using the secret command.

{
  "id": "transaction-id",
  "key": "sender-key",
  "accept": true
}