Rising Storm 2: Vietnam

Rising Storm 2: Vietnam

Not enough ratings
[DEPRECATED] Unranked Bug Discord Alerts For Server Admins
By fluudah
Setting up unranked server alerts with Discord for server admins. The "unranked bug" causes servers to spontaneously become unranked, potentially causing multiple people to disconnect and preventing new players from connecting.
   
Award
Favorite
Favorited
Unfavorite
Basics
This guide can also be viewed at https://github.com/tuokri/rs2wapy-examples, where all the source code may also be found.

Terminology
  • Python:
    the programming language, which rs2wapy is
    written in.

  • rs2wapy https://github.com/tuokri/rs2wapy:
    Rising Storm 2: Vietnam WebAdmin Python Interface
    (the library powering this example application).

  • Heroku https://www.heroku.com:
    Platform as a Service (PaaS) provider. Used to
    host some of the example applications.

  • GitHub https://www.github.com:
    software development platform. All the code you see here
    is hosted on GitHub.

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.
Setting up GitHub
1. Create a GitHub account at https://github.com/join.

2. Fork this example repository https://github.com/tuokri/rs2wapy-examples.



After forking, you will have a copy of this repository in your GitHub account.
Setting up Heroku
1. 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.

2. Verify your Heroku account with a credit card (optional, but recommended).
Create a Discord Webhook
1. Perform the steps in the MAKING A WEBHOOK section of this article
https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks

2. 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 guide!
Setup Discord Developer Mode and Role IDs
1. Enable Discord Developer Mode.



2. Copy desired role ID(s).

Find the role(s) you want to ping when the server
goes unranked, right click and copy their IDs.



3. Add role ID(s) to ranked_alert.py.



Make sure you edit the file in the repository you just forked, in YOUR GitHub profile!

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.

4. In ranked_alert.py set RUN = True on line number 8.





5. Save (commit) the changes.


Deploy on Heroku
1. Setup a new Heroku app & deploy from GitHub.




  • Enable automatic deploys.



- Connect to GitHub & choose your repository (the one you forked and edited).

2. 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_# and WEBADMIN_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 earlier.
  • 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
All done & extras!
Extras require a tiny bit of Python programming skills.

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")