A Discord.py project. Use !getprice <coin symbol>
in chat to get the latest price of your favorite crypto.
- Python
- Turso
- A CoinMarketCap API key
- A Discord Appliation
TODO - create a setup.sh script
-
Clone the repo:
git clone https://github.com/s-hammon/crypto-craig.git
-
(in your environment) install requirements:
pip install -r requirements.txt
-
Set env vars, install Goose;
source scripts/init.sh
-
CMC_PRO_API_KEY
-- your CMC API key -
DISCORD_TOKEN
-- your Discord bot's API token (typically done athttps://discord.com/developers/applications/<YOUR-APP-ID>/bot
) -
DB_URL
-- Turso database url (database-username.turso.io
)TODO - reconfigure to allow for local db development/testing
-
TURSO_AUTH_TOKEN
-- your Turso API token (recommend using the CLI tool and runningturso auth token
) to run the crawler job -
TURSO_AUTH_TOKEN_DISCORD_CLIENT
-- optional second token for the discord app. May be set to the same value asTURSO_AUTH_TOKEN
-
-
Migrate database:
make up
or
goose -dir sql/schema turso "${DB_URL}?authToken=${TURSO_AUTH_TOKEN}" up
-
Populate the database with
python3 main.py crawler job
- This will query CMC for the latest prices on all coins
After inviting your application to your Discord server(s), run the actual Discord bot with python3 main.py craig
. Supported commands include:
!getprice <coin_symbol>
!all
!history <coin_symbol> [range]
I've created a single Dockerfile whose entrypoint may be overridden to run either the crawler or the bot. You can build an image from this Dockerfile and run them in containers for either job/service.
Note: please ensure that you have the aformentioned environment variables set in your development environment!
- Crawler:
docker run --entrypoint "python3 main.py crawler job" <image_name>:<image_tag>
- Craig:
docker run --entrypoint "python3 main.py craig" <image_name>:<image_tag>
Your help is greatly appreciated.
Before developing, please ensure that you are on a forked repo. Run scripts/setup-dev.sh
to ensure that you have Ruff
and Goose
installed in your environment. Prior to opening a pull request, your code must pass existing tests and linting. The provided Makefile
offers a convenient way to run tests (using the unittest
Python module) and linting:
- Tests:
make test
- Linting:
make pretty