Skip to content

DarkMukke/wows-poller

Repository files navigation

wows-poller

A Go service that polls the World of Warships API hourly, tracks player and clan statistics, and feeds data into InfluxDB, Elasticsearch, and PostgreSQL for dashboards and Discord alerts.

Architecture

Discord Bot (Node.js)          wows-poller (Go)
  /wows_track → Postgres  ←→   Hourly tick → WoWS API
  LISTEN pg_notify              → InfluxDB (metrics)
  → Discord alerts              → Elasticsearch (events)
                                → Postgres (state + alerts)

The poller and bot share a Postgres database. The poller writes data; the bot listens for changes via pg_notify and fires Discord alerts.

Requirements

Installation

git clone https://github.com/darkmukke/wows-poller
cd wows-poller
go mod download

Configuration

Copy .env.example to .env and fill in the values:

# Postgres — pgx key-value format (no URL encoding needed)
POSTGRES_DSN="host=localhost port=5432 dbname=yourdb user=wows_poller password=yourpassword sslmode=disable"

# golang-migrate requires URL format
MIGRATION_DSN="postgres://wows_poller:yourpassword@localhost:5432/yourdb?sslmode=disable"

# InfluxDB 3
INFLUX_URL=http://localhost:8182
INFLUX_TOKEN=apiv3_yourtoken
INFLUX_DB=wows

# Elasticsearch
ELASTIC_ADDRESSES=http://localhost:9200
ELASTIC_PREFIX=wows
ELASTIC_USERNAME=wows_poller
ELASTIC_PASSWORD=yourpassword

# WoWS API
WOWS_APP_ID=your_application_id
WOWS_REGION=eu

Supported regions: eu, na, asia

Database setup

Run migrations before first use:

wows-poller migrate

Migrations are in migrations/ and run automatically on serve as well.

CLI reference

wows-poller [command]

Commands:
  serve              Start the hourly poller
  migrate            Run database migrations
  track player       Track a player
  track clan         Track a clan and all its members
  untrack player     Stop tracking a player
  untrack clan       Stop tracking a clan
  list players       List all tracked players
  list clans         List all tracked clans

Tracking a player

wows-poller track player <accountId> <guildId>
wows-poller track player 577479302 123456789

Tracking a clan

Tracking a clan automatically tracks all current members as clan_auto. Members who leave the clan are automatically untracked unless they were manually added.

wows-poller track clan <clanId> <guildId>
wows-poller track clan 500156148 123456789

Listing tracked players

wows-poller list players
ACCOUNT_ID      REGION TRACK_SHIPS
577479302       eu     false
547900642       eu     false

total: 2

Discord slash commands

The Discord bot (wows-bot.js) registers these commands — requires Administrator permission:

Command Description
/wows_track Track a player or clan via wows-numbers.com URL
/wows_untrack Stop tracking a player or clan
/wows_list_players List tracked players with stats
/wows_list_clans List tracked clans with member counts

Commands accept wows-numbers.com URLs directly:

https://wows-numbers.com/player/577479302,D_rkM_kk_/
https://wows-numbers.com/clan/500156148,YEETD-YEETD-FLEET/

What gets tracked

InfluxDB (time-series metrics)

  • PvP stats: battles, wins, losses, XP, damage, frags, ships spotted, planes killed
  • Weapon breakdown: main battery, torpedoes, secondary battery hit rates
  • Personal records: max XP, max damage, max frags per battle
  • Written every hour per tracked player

Elasticsearch (event log)

  • Clan membership changes (joined, left, role changed)
  • Nickname changes
  • Profile visibility changes (hidden/visible)
  • New personal records

PostgreSQL (current state)

  • Latest player snapshot for diffing
  • Tracked player and clan registry
  • Pending alerts queue
  • Ship encyclopedia (name, tier, type, images)
  • Clan membership roster

Alert types

Alert Fires at
clan_left Immediately — poaching window shown as Discord timestamp (3 days)
clan_joined After next full tick (once nickname is resolved)
clan_role_changed After next full tick
nickname_changed After next full tick
profile_hidden After next full tick
profile_visible After next full tick
new_record After next full tick

Docker deployment

# production
docker compose up -d --build

# view logs
docker compose logs -f wows-poller

# rebuild after code changes
docker compose up -d --build --force-recreate

docker-compose.yaml expects .env.production in the project root.

Project structure

wows-poller/
├── cmd/
│   └── poller/
│       ├── main.go         entry point
│       ├── root.go         cobra root command + config init
│       ├── serve.go        hourly poller loop
│       ├── track.go        track player/clan commands
│       ├── untrack.go      untrack player/clan commands
│       ├── list.go         list commands
│       └── migrations.go   migration runner
├── internal/
│   ├── config/             environment variable config
│   ├── notify/             pg_notify LISTEN/NOTIFY
│   ├── poller/             tick loop, diff logic, mappers
│   ├── store/
│   │   ├── elastic/        Elasticsearch event writes
│   │   ├── influx/         InfluxDB 3 metric writes
│   │   └── postgres/       player state, alerts, clans, ships
│   └── wows/               WoWS API client and types
├── migrations/             SQL migration files (.up.sql)
├── sample/                 sample API response JSON files
├── Dockerfile
├── docker-compose.yaml
└── .env.example

Grafana dashboards

Connect three datasources:

Datasource Type Used for
InfluxDB 3 InfluxDB (SQL) Player metrics over time
Elasticsearch Elasticsearch Event log, annotations
PostgreSQL PostgreSQL Player/clan lookups, ship names

Dashboard variables:

  • account_id — player selector (Postgres query, shows [CLAN] nickname)
  • clan_id — clan selector (Postgres query)
  • ship_id — ship selector (Postgres query, shows T7 Mahan (Destroyer))

Feature schema

The bot uses a feature schema system — tables prefixed with wows_ are required for the WoWS feature. If these tables are missing the bot disables WoWS commands gracefully. Required tables:

  • wows_tracked_players
  • wows_tracked_clans
  • wows_player_state
  • wows_pending_alerts
  • wows_clans
  • wows_clan_members
  • wows_ships
  • wows_guild_settings

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors