Skip to main content

Rising Storm 2: Vietnam WebAdmin Python Interface

Project description

rs2wapy

Rising Storm 2: Vietnam WebAdmin Python Interface

Provides a Python interface for performing RS2 WebAdmin tasks programmatically.

The library uses PycURL internally to communicate with RS2 WebAdmin.

Work in progress; interface will change!

Brief Usage Examples

This section contains some brief usage examples. For more comprehensive tutorials, check out the examples repository.

Installation
# Requires Python=>3.9
pip install rs2wapy
Steam Web API key (optional)

Setting your Steam Web API key as an environment variable allows rs2wapy to offer some extra functionality.

Unix:

export STEAM_WEB_API_KEY="TOPSECRETKEY"

Windows:

set STEAM_WEB_API_KEY="TOPSECRETKEY"
Quickstart

It is recommended to create a new WebAdmin account for rs2wapy.

from rs2wapy import RS2WebAdmin

wa = RS2WebAdmin(
    username="AutoModerator",
    password="topsecret123",
    webadmin_url="http://localhost:8080/",
)
Poll server ranked status and switch map automatically
while True:
    if not wa.get_current_game().ranked:
        wa.post_chat_message("Unranked bug happened! Changing map in 5 seconds!")
        time.sleep(5)
        wa.change_map("VNTE-Resort")
    time.sleep(1)
Forward in-game chat to a Discord webhook with discord.py.
import time

from discord import RequestsWebhookAdapter
from discord import Webhook
from discord.utils import escape_markdown
from discord.utils import escape_mentions

from rs2wapy import RS2WebAdmin
from rs2wapy.models import AllTeam
from rs2wapy.models import BlueTeam
from rs2wapy.models import RedTeam

# Discord webhook info.
webhook = Webhook.partial(
    id=123456,
    token="abcdefg",
    adapter=RequestsWebhookAdapter()
)

# Webadmin credentials.
USERNAME = "Admin"
PASSWORD = "adminpassword"
URL = "http://127.0.0.1:8080/ServerAdmin"

TEAM_TO_EMOJI = {
    BlueTeam: ":blue_square:",
    RedTeam: ":red_square:",
    AllTeam: ":white_square_button:",
}

TEAM_TO_TEAMNAME = {
    BlueTeam: "SOUTH",
    RedTeam: "NORTH",
    AllTeam: "ALL",
}


def get_team_emoji(team):
    try:
        return TEAM_TO_EMOJI[team]
    except KeyError:
        return "?"


def get_team_name(team):
    try:
        return TEAM_TO_TEAMNAME[team]
    except KeyError:
        return "?"


def main():
    webadmin = RS2WebAdmin(USERNAME, PASSWORD, URL)
    messages = []

    while True:
        try:
            messages.extend(webadmin.get_chat_messages())
        except Exception as e:
            print(f"error getting messages: {e}")
            print("attempting to reconnect...")
            webadmin = RS2WebAdmin(USERNAME, PASSWORD, URL)

        if messages:
            for message in messages:
                text = message.text
                sender = message.sender
                team = message.team

                team_name = get_team_name(team)
                team_emoji = get_team_emoji(team)

                # Prevent pinging @everyone from in-game chat
                # and other "funny" stuff.
                text = escape_markdown(text)
                text = escape_mentions(text)
                sender = escape_markdown(sender)
                sender = escape_mentions(sender)

                try:
                    webhook.send(f"**{sender}** [{team_name}] {team_emoji}: {text}")
                except Exception as e:
                    print(f"error sending message: {e}")

        messages = []
        time.sleep(3)

The above are just simple examples of how to use the library. In the future, the library will be able to automate all tasks which RS2 WebAdmin offers. You can check the status of currently implemented WebAdmin features here: https://github.com/tuokri/rs2wapy/issues/9.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rs2wapy-0.7.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rs2wapy-0.7.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file rs2wapy-0.7.0.tar.gz.

File metadata

  • Download URL: rs2wapy-0.7.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for rs2wapy-0.7.0.tar.gz
Algorithm Hash digest
SHA256 1374e377583ffa4da869200b7c6b281908df218063e44d99bee2dbed12cb9bc1
MD5 d9899c870233ca57bb0ea8422c65ae45
BLAKE2b-256 0227872bd7ab6bb5f5e54b71d5c89581445ddbda01742365512515228318d7cf

See more details on using hashes here.

File details

Details for the file rs2wapy-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: rs2wapy-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for rs2wapy-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34bc52dead78e36afeb7b24b394e6a9bc487caa733bcec41418bdebe59f3fc1a
MD5 d12b8b877cfd63a1ed0bd5a06d8120ab
BLAKE2b-256 7ddde15ee53be55611fb5a6b3b4bcf65cc0461f1844266ef0ee816b191cd427e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page