Notifies you when Dr. Purtilo makes a new blog post by sending a message to a discord text channel.
First, make sure you have Node installed. You should be using node v10
or higher. However, because this project uses TypeScript, you can change the target ECMAScript version to suit your needs. Secondly, we're also using the yarn package manager instead of npm
. You'll need v1.2.x
installed.
Once that's sorted out, get the code and build it.
git clone https://github.com/DanRowe/cmsc435-discord-bot.git
cd cmsc435-discord-bot
yarn --frozen-lockfile
yarn build
You'll also need to make a discord webhook url. Check here
for how to create one. You then need to make it available to the bot through the
WEBHOOK_URL
environment variable. You can set this however you'd like, but we
recommend creating a .env
file in the folder root. Your file should look like
this:
WEBHOOK_URL=<your_discord_webhook_url>
You can then run the program using yarn start
. If you're deploying this on your VM, you're gonna want to set up a cron job. This will make the program check for updates periodically. To edit your cronjobs, run crontab -e
. For root-level cronjobs, prefix this with sudo
, but a user-level one will work fine for our purposes.
Make your cronjob file look something like this:
SHELL=/bin/bash
# Optional. Cronjob status updates are sent to this email
[email protected]
# Make sure node and yarn are available on the path. Adjust as necessary
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
*/15 * * * * (cd /path/to/your/cmsc435-discord-bot; yarn start) 2>&1 | logger -t DiscordBot
This makes the bot run every 15 minutes. For more info on how to configure this, see this helpful article or use man crontab
. To view bot logs, run grep DiscordBot /var/log/syslog
.
Optionally, you can automatically rebuild the bot when pulling from the git repository by creating a post-merge hook.
#!/usr/bin/env bash
yarn build
Then make it executable by running chmod +x post-merge
.