This example application sends a message to Discord when the RS2 server goes unranked. Server ranked status is checked every 5 seconds. If the server is unranked, the first message is sent instantly and after that a message is sent every 15 minutes until the server is ranked again.
Make sure you read the general example README first.
There are unlimited ways to deploy applications using rs2wapy
.
This particular example uses Heroku
to host the unranked alert bot.
You may also read this guide at RS2 Community Hub.
Brief explanation of the files in this directory.
ranked_alert.py # example application source code
README.md # this readme file
Detailed steps on setting up this example application.
-
Create a GitHub account at https://github.com/join.
-
Fork this example repository https://github.com/tuokri/rs2wapy-examples.
After forking, you will have a copy of this repository in your GitHub account.
-
Create a free Heroku account. https://signup.heroku.com/
Free Heroku account allows you to setup free dynos with 550 run hours each month. If you verify your account with a credit card, you'll receive 1000 free dyno hours each month. This means you can run this example application 24/7 for free on Heroku. A dyno is a worker, which executes application code.
-
Verify your Heroku account with a credit card (optional, but recommended).
-
Perform the steps in the 'MAKING A WEBHOOK' section of this article https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks
-
Give your Webhook a name and a picture and choose the channel.
We will use the Webhook URL later in this guide.
DO NOT perform the steps explained in the 'QUICK EXAMPLE: GITHUB WEBHOOK INTEGRATION' section! Those steps are irrelevant for this example!
-
Enable Discord Developer Mode.
-
Copy desired role ID(s).
Find the role(s) you want to ping when the server goes unranked, right click and copy their IDs.
-
Add role ID(s) to
ranked_alert.py
.Make sure you edit the file in the repository you just forked!
Open the file and look at lines 31 to 41. The role IDs are stored in the
PING_DISCORD_ROLES
variable. Read the comment lines starting with#
for instructions. -
In
ranked_alert.py
setRUN = True
on line number 8. -
Save (commit) the changes.
-
Setup a new Heroku app & deploy from GitHub.
- Go to https://dashboard.heroku.com/apps.
- Click 'New' (top right corner).
- Create new app.
- Give your app a name & choose region.
- Deployment method: GitHub
- Enable automatic deploys.
- Connect to GitHub & choose your repository (the one you forked and edited).
-
Setup environment variables.
- From the top bar, navigate to your app's settings.
- In settings, choose 'Reveal Config Vars'. Config Vars are your environment variables.
- Setup your environment variables.
- You have to setup
WEBADMIN_USERNAME_#
,WEBADMIN_PASSWORD_#
andWEBADMIN_URL_#
for each RS2 server you want to track. - The
#
starts from 1 and should be increased by 1 for every server you set up. - The example image has variables set up for 2 servers.
DISCORD_WEBHOOK_URL_#
is the URL we created in part 3 of this guide.- If you only have a single webhook URL, you can use the same webhook URL multiple times.
- You may create new RS2 WebAdmin admin accounts for this bot, just make sure the accounts have access to the "Current Game" tab.
- Finally, enable the dyno.
- If you can't see the enable dyno buttons, go to 'Deploy' tab, and at the end of the page, click 'Deploy Branch' (choose master branch).
- Check your app logs.
- If everything was set up correctly, you should have the following lines in your app log:
2020-03-13T11:50:50.047845+00:00 app[worker.1]: running app: <module 'ranked_alert' from 'examples/unranked_discord_alert/ranked_alert.py'> 2020-03-13T11:50:51.492858+00:00 app[worker.1]: 2 RS2WebAdmin instances initialized
There are also some extra features in ranked_alert.py
that are commented
by prefixing with #
, disabling them. You may uncomment these lines if you
wish to enable the extra features. Make sure the lines "line up" i.e. the
uncommented line is not intended by an extra whitespace.
E.g.
# We could also change the map automatically.
# change_map(wa, "VNTE-Resort")
would be changed to:
# We could also change the map automatically.
change_map(wa, "VNTE-Resort")