DrSpy Serverless is a Discord bot built using Cloudflare Workers and the discord-hono
library. It provides commands to fetch and display the online player count for the OGAT game with graph support.
Special thanks to discord-hono for the library and cominu for the api.
Follow these steps to deploy your own instance of DrSpy Serverless:
-
Clone the Repository:
git clone <repository_url> cd drspy-serverless
-
Install Dependencies:
bun install
-
Configuring the Database
This project uses Cloudflare D1 as its database.
- Sample data is provided in
sample_data.sql
. - The database schema is defined in
db/schema.sql
. - Refer to the Cloudflare D1 documentation for setup instructions.
Note: The local database does not sync with the remote database, and changes made to one will not reflect in the other.
- Sample data is provided in
-
Configure Environment Variables:
Create two
.vars
files:.dev.vars
for local development and.prod.vars
for production deployment. These files will store your secrets and configuration values.Example
.dev.vars
and.prod.vars
:DISCORD_APPLICATION_ID=<YOUR_DISCORD_APPLICATION_ID> DISCORD_TOKEN=<YOUR_DISCORD_BOT_TOKEN> DISCORD_PUBLIC_KEY=<DISCORD_BOT_PUBLIC_KEY> OGAT_API=<YOUR_OGAT_API_ENDPOINT> DISCORD_UPDATE_CHANNEL=<YOUR_DISCORD_CHANNEL_ID>
Replace the placeholder values with your actual Discord Application ID, bot token, OGAT API endpoint, and the Discord channel ID where bot's status will be updated.
-
Register the Discord Commands:
This step registers the bot commands (
/get-player-count
,/configure
) with Discord. You need to run this only when the commands change or for the first time.-
For Development:
bun run register:dev
-
For Production:
bun run register:prod
-
-
Deploy to Cloudflare Workers:
Set Secrets using Wrangler:
You'll need to set these secrets for both your
dev
andprod
environments using the Wrangler CLI. This encrypts the values and stores them securely. Make sure you have Wrangler cli installed and logged into your account.- For Development:
-
Create db as mentioned in
wrangler.json
and add those values.wrangler secret put DISCORD_APPLICATION_ID --env dev wrangler secret put DISCORD_TOKEN --env dev wrangler secret put DISCORD_PUBLIC_KEY --env dev wrangler secret put OGAT_API --env dev wrangler secret put DISCORD_UPDATE_CHANNEL --env dev
Follow the prompts to enter each secret value.
- For Production:
-
Create db as mentioned in
wrangler.json
and add those values.wrangler secret put DISCORD_APPLICATION_ID --env prod wrangler secret put DISCORD_TOKEN --env prod wrangler secret put DISCORD_PUBLIC_KEY --env prod wrangler secret put OGAT_API --env prod wrangler secret put DISCORD_UPDATE_CHANNEL --env prod
Follow the prompts to enter each secret value. Important: Make sure you use the production values for your production deployment.
-
For Development:
bun run deploy:dev
This will deploy to your Cloudflare Workers environment using the
.dev.vars
file. -
For Production:
bun run deploy:prod
This will deploy to your Cloudflare Workers environment using the
.prod.vars
file.
-
Enable and Invite the Bot:
-
Go to the Discord Developer Portal.
-
Enter the cloudflare worker endpoint to the INTERACTIONS ENDPOINT URL.
-
Create an invite URL from Dashboard.
YOUR_APP
>OAuth2
tab >OAuth2 URL Generator
> Check SCOPES:bot
> URLCopy
Paste the URL into the browser.
-
- For local development you can use
bun run dev
, it will use the variables in.dev.vars
. - You might want to proxy with
ngrok
to get ahttps
endpoint.- Install
ngrok
and runngrok http <port>
- Now copy and paste the endpoint to the INTERACTIONS ENDPOINT URL.
- Install