Jingle Jam Discord bot built on Cloudflare Workers, providing stats commands and automatic announcements
- Create your test Discord application at https://discord.com/developers/applications (this does not need a bot account, just the application).
- Create your
.dev.varsfile.- Copy
.dev.vars.exampleand fill out the information from your Discord application, plus the ID of your test server/guild where you'll use the bot. - Optionally,
DISCORD_SUMMARY_CHANNEL+DISCORD_MILESTONE_CHANNELcan be set to channel IDs for testing the scheduled messages, as well as theDISCORD_BOT_TOKENto send the messages as. - Optionally,
DISCORD_CAUSES_EMOJI+DISCORD_REGULAR_EMOJIcan be set to a JSON object mapping the cause names + regular emoji (seeconst regularinsrc/util/emoji.ts) to custom emoji Markdown (which can be uploaded directly to the Discord application).
- Copy
- Authenticate with Wrangler by running
npx wrangler login. - Update
wrangler.tomlfor your account.- Use
npx wrangler whoamito get your account ID, update the value inwrangler.tomlto match. - Use
npx wrangler kv:namespace create "STORE"to create the KV namespace, update theidandpreview_idinwrangler.tomlto match.
- Use
- Develop with the worker by running
npm run dev.- To test the CRON functionality, hit the
/__scheduled?cron=*+*+*+*+*endpoint.
- To test the CRON functionality, hit the
- (Optional) Start an HTTP tunnel to your local development server by running
npm run tunnel, using cloudflared.- To use a custom hostname in your Cloudflare account, first make sure you're authenticated with
cloudflared login, then runnpm run tunnel -- --overwrite-dns --hostname <hostname> --name <name>(where<name>can be any convenient name for the tunnel).
- To use a custom hostname in your Cloudflare account, first make sure you're authenticated with
wrangler.toml and this repository is currently designed for a staging deployment and a production deployment.
Ensure that the environment in wrangler.toml has been updated with your chosen for the worker.
Ensure that the KV namespaces are created for staging/production environments and are configured in wrangler.toml. Use npx wrangler kv:namespace create "STORE" -e <staging/production>.
You'll also want to set DISCORD_CLIENT_ID + DISCORD_PUBLIC_KEY + STATS_API_ENDPOINT (optionally, DISCORD_SUMMARY_CHANNEL + DISCORD_MILESTONE_CHANNEL + DISCORD_BOT_TOKEN + DISCORD_CAUSES_EMOJI + DISCORD_REGULAR_EMOJI + WORKER_BASE_URL) as secrets for the worker, which you can do with npx wrangler secret put <var name> -e <staging/production> (the channel secrets can contain multiple IDs, separated by a comma).
If you're deploying for local, make sure that you've got the appropriate environment variables set for DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET + DISCORD_GUILD_ID (otherwise, they'll default to the values in .dev.vars).
To deploy from local, run npm run publish:staging to deploy to staging, and npm run publish:production to deploy to the production environment.
To deploy using GitHub, run make deploy-staging to force push and deploy to staging, and make deploy-production to force push and deploy to the production environment.
Live logs for both environments can be accessed with npm run logs:staging and npm run logs:production as needed.