A small Ruby script and cron job for my World of Tanks clan, from 2022. It automatically activates our Stronghold reserves — Battle Payments and Military Maneuvers — twice a day, so nobody has to be online at the exact right moment to hit "activate" before clan battles.
Prolong the token first, always. The Wargaming API access token has a TTL and goes stale — it has to be carried over and refreshed regularly, or the next run's reserve activation just fails with an expired token. So before doing anything else, every run trades the current token for a fresh one via the API's own prolongate endpoint, and only then uses that fresh token to activate the reserves. That's the whole trick that lets this run unattended indefinitely.
It started as program.rb,
run via a plain crontab entry twice a day, with the refreshed token written
back to a local file so the next cron run could pick it up. Eventually I moved it to AWS
Lambda instead — but Lambda invocations don't share a filesystem between runs, so writing
the token to a local file no longer carries it over. The
lambda_function.rb
version solves that by calling back into its own configuration via
aws-sdk-lambda and rewriting its own access_token environment
variable with the freshly prolonged token on every invocation. Same idea as the file-based
version — the token has to be handed off to "future me" somehow — just moved from a file
on disk to the function's own config.
The source is open, at jane-natucci/reserves.
Reserves (Wargaming calls them "boosters") are documented in the WoT Encyclopedia API: developers.wargaming.net — Boosters. That's where the reserve types and levels this script uses come from.