Auto heal for Rabona

in #rabona3 years ago (edited)

This script checks if there are injured players in the squad and auto-heal them with the RBN (if available).

config.py


ACCOUNTS = [
    {
        "username": "your_user",
        "posting_key": "<pkey>"
    },
    {
        "username": "other_user",
        "posting_key": "<pkey>",
    }
]


auto-heal.py


import logging
import json
from lighthive.client import Client
from lighthive.datastructures import Operation

from rabona_python import RabonaClient

from config import ACCOUNTS

logger = logging.getLogger("Auto heal")
logger.setLevel(logging.DEBUG)
logFormatter = logging.Formatter(
    '%(asctime)s %(name)s %(levelname)s: %(message)s')
consoleHandler = logging.StreamHandler()
fileHandler = logging.FileHandler("autoheal.log")
consoleHandler.setFormatter(logFormatter)
fileHandler.setFormatter(logFormatter)
logger.addHandler(consoleHandler)
logger.addHandler(fileHandler)

r = RabonaClient()


def create_custom_json_op(username, pid):
    train_json = json.dumps(
         {
             "username": username,
             "type": "heal_for_RBN",
             "command": {"tr_var1": pid}
         }
    )

    train_op = Operation('custom_json', {
        'required_auths': [],
        'required_posting_auths': [username, ],
        'id': 'rabona',
        'json': train_json,
    })
    return train_op


def auto_heal(team, pk):

    rbn_balance = r.userinfo(user=team).get("currency")
    logger.info("Checking \"%s\" for injured players.", team)
    players = r.team(user=team).get("players", [])
    injured_players = [p for p in players if int(p["games_injured"]) > 0]

    if not injured_players:
        logger.info(
            "\t\"%s\" doesnt have any injured players. Skipping.",
            team,
        )
        return
    else:
        logger.info("\tAvailable RBN: %s", round(rbn_balance))
        max_heal_games = round(rbn_balance) / 10000
        for p in injured_players:
            logger.info(
                "\t%s (%s) is injured for %s matches. Trying to heal." % (
                    p["name"], p["uid"], p["games_injured"]
                ))

            if p["games_injured"] <= max_heal_games:
                op = create_custom_json_op(team, p["uid"])
                c = Client(keys=[pk, ])
                c.broadcast(op=op)
                logger.info("\t Transaction is broadcasted. Enjoy.")
                max_heal_games -= p["games_injured"] * 10000
            else:
                logger.info(
                    "\tNot enough RBN to heal %s (%s) for %s matches.",
                    p["name"], p["uid"], p["games_injured"]
                )


def main():
    for team in ACCOUNTS:
        auto_heal(team["username"], team["posting_key"])


main()

Example output:


Screen Shot 20210130 at 13.11.37.png


Requires Python3.6. lighthive, rabona_client python libraries must be installed. I use it with a crontab entry - so it checks injured players once every hour.

Sort:  

"I do not know how to run this and I am not joining a game to be beaten up by guys that do know."

This is one way to look at it. The way I look at this, I actually give these players a fair chance.

Any person can spend one night, at most two nights, to learn how to execute Python scripts and use this. That would not be possible if I use this silently. (Probably like other players)