A serverless function for fetching, notifying BOJ group judge status
Before using Discord notify feature, you have to create your own Discord Bot with send message permission and add it to your channel. Create Discord bot here
There are two methods to use this function. You can choose one of these methods to get started.
Simply use deployed Vercel function is the easiest way. It is deployed when this repository is updated. You can use latest version of this API without any manual update.
API Endpoint: https://boj-group-judge-status-discord-bot.vercel.app/api/status
You can customize API behavior and others by modifying and deploying function to your Vercel server. Click on the Deploy button to start.
By default, This function will quit after response. So, you need setup for continous status update using cron job.
Thankfully, GitHub Actions provides scheduled workflow. Here is example GitHub Actions config.
NOTE: You need to set repository secrets to protect sensetive information.
name: Update group judge status
on:
workflow_dispatch:
# Call this function every 5 minutes
schedule:
- cron: '*/5 * * * *'
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Update group judge status
run: |
curl -G -L https://boj-group-judge-status-discord-bot.vercel.app/api/status \
-d 'boj_token=${{ secrets.BOJ_TOKEN }}' \
-d 'boj_group_code=${{ secrets.BOJ_GROUP_CODE }}' \
-d 'discord_token=${{ secrets.DISCORD_TOKEN }}' \
-d 'discord_channel_id=${{ secrets.DISCORD_CHANNEL_ID }}'
ANY /api/status
name | description | required |
---|---|---|
boj_token | BOJ token (cookie name: OnlineJudge) | Y |
boj_group_code | BOJ Group ID | Y |
discord_token | Discord access token | Y |
discord_channel_id | Discord channel ID | Y |
HTTP 200 OK
{
"status": "OK",
"data": {
"originals": [
{
"id": string,
"user_id": string,
"problem": {
"num": string,
"name": string,
};
"result": string,
"timestamp": number,
},
],
"sent": [
{
"id": string,
"user_id": string,
"problem": {
"num": string,
"name": string,
};
"result": string,
"timestamp": number,
},
]
}
]
HTTP <ERROR CODE>
{
"status": <ERROR NAME>,
"error": <ERROR MESSAGE>,
}
You can run and test serverless function using Vercel CLI
# Install Vercel CLI if not installed.
yarn global add vercel
# move to project's root directory
cd BOJ-group-judge-status-discord-bot
# Start vercel dev server with localhost mode
yarn start
MIT License