Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
382a23b661 | ||
|
|
98107291f5 | ||
|
|
c6779a714b | ||
|
|
ef8f0fd72d | ||
|
|
b42df81b48 | ||
|
|
536fed5448 | ||
|
|
d4c0b01343 | ||
|
|
af67126156 | ||
|
|
9930360405 | ||
|
|
4fb61d6dbd | ||
|
|
bcb7ca5c4c | ||
|
|
2be4dbea7a | ||
|
|
b951c81bf5 | ||
|
|
8c221a1295 | ||
|
|
c41f721a96 | ||
|
|
1a92cbd951 | ||
|
|
54c5faf929 | ||
|
|
d1d9e9e4d1 | ||
|
|
5ca64f839e | ||
|
|
4e7cd6f681 | ||
|
|
ba9f593716 | ||
|
|
9d3d74c7c5 | ||
|
|
aae26523ff | ||
|
|
338a2a14bf | ||
|
|
1a66cab435 | ||
|
|
3363c9ab58 | ||
|
|
10f64902aa | ||
|
|
25e1f4caa4 | ||
|
|
222fa89422 | ||
|
|
750e145f03 | ||
|
|
3bbbbfa402 | ||
|
|
f728751fa9 | ||
|
|
f5425d0e54 | ||
|
|
debaaccf4c | ||
|
|
a3e20501af | ||
|
|
c87a75f3fd | ||
|
|
55729c5eda | ||
|
|
06cbcc2339 | ||
|
|
1afe860e76 | ||
|
|
c0ac935652 | ||
|
|
7c76b0f5a5 | ||
|
|
42091c54b7 | ||
|
|
396b48d017 | ||
|
|
bb1c0c7625 | ||
|
|
1170676141 | ||
|
|
7baaaa9db9 | ||
|
|
c1ecef0179 | ||
|
|
032d98e6bd | ||
|
|
f4a90cd531 | ||
|
|
82f03583fe | ||
|
|
81c1a50052 | ||
|
|
c7207799e2 | ||
|
|
e0a719ee93 | ||
|
|
ee6d2e7d82 | ||
|
|
14710b5218 | ||
|
|
4b5e0d1c1c | ||
|
|
9968e8346c | ||
|
|
bc4da17f10 | ||
|
|
da56c563fc | ||
|
|
95f4dbf6a0 | ||
|
|
6c36f343ea | ||
|
|
9257ebdd1e | ||
|
|
8f1017195f | ||
|
|
20da294b36 | ||
|
|
a63415461a | ||
|
|
2bb4c78551 | ||
|
|
2909e61721 | ||
|
|
171da2a194 | ||
|
|
933c468e2d | ||
|
|
0d1eb9b12e | ||
|
|
02a03b4d68 | ||
|
|
ef9f3bd361 | ||
|
|
f18b6ee754 | ||
|
|
deb9e463e1 | ||
|
|
c799534009 | ||
|
|
aea01072fb | ||
|
|
ca8dd5a702 | ||
|
|
e79c4a1e3f | ||
|
|
e19d0d948a | ||
|
|
a160ccd095 | ||
|
|
d2d0477186 | ||
|
|
c742c0725d | ||
|
|
9e6343a111 | ||
|
|
faf33b5f2d | ||
|
|
8a78ac7d82 | ||
|
|
d7c7814b3a | ||
|
|
15bf02f829 | ||
|
|
4f62a594b3 | ||
|
|
64253d0120 | ||
|
|
286936131d | ||
|
|
95588ef6b6 | ||
|
|
daef04ccd8 | ||
|
|
86e385c548 | ||
|
|
cc193b99d6 | ||
|
|
c026007937 | ||
|
|
dbc117a9d4 | ||
|
|
34665bd97a | ||
|
|
6d05e607b3 | ||
|
|
14bfc3018b | ||
|
|
7e4f195f94 | ||
|
|
4b6de934a5 | ||
|
|
14fbb595fd | ||
|
|
18a5fb80d0 | ||
|
|
551ef79f03 | ||
|
|
81aec6bad2 | ||
|
|
d08949c597 | ||
|
|
212aee0373 | ||
|
|
059b78c9fb | ||
|
|
11ba5fc28e | ||
|
|
fbde9ec64f | ||
|
|
6600bba58c | ||
|
|
9e340d2e16 | ||
|
|
6f784e9e94 | ||
|
|
62f6aabf05 | ||
|
|
46457a8bdc | ||
|
|
1081e836f5 | ||
|
|
dfe1e37592 | ||
|
|
0b9db21c10 | ||
|
|
57527115d4 | ||
|
|
8d2679c458 | ||
|
|
ca00f18a6a | ||
|
|
466f68701f | ||
|
|
1bb83da253 | ||
|
|
bd1e17bac9 | ||
|
|
322f95e42e | ||
|
|
3ea77f5899 | ||
|
|
882e61ff44 | ||
|
|
d991be4934 | ||
|
|
dfba8bd15f | ||
|
|
87e23673fb | ||
|
|
8fbd1acf4a | ||
|
|
d7dfbaa799 | ||
|
|
04ce20857e | ||
|
|
4550246d63 | ||
|
|
dd673f44ae | ||
|
|
3245284ecc | ||
|
|
3d9872a671 | ||
|
|
f02db2a2d8 | ||
|
|
d1ebb79432 | ||
|
|
44f03a1fce | ||
|
|
6b6ee94d9b | ||
|
|
81c2ca80bc | ||
|
|
c83cec8ed7 | ||
|
|
93ffe5c507 | ||
|
|
8cd1a70333 | ||
|
|
06ae024c2c | ||
|
|
ce8fd0f22f | ||
|
|
7dc1aff1dc | ||
|
|
a60003127f | ||
|
|
7d1ba58806 | ||
|
|
963d71e221 | ||
|
|
2a804fda1c | ||
|
|
597a1a04d2 | ||
|
|
aec6f49ea1 | ||
|
|
e1ad710de5 | ||
|
|
edc8447617 | ||
|
|
f726d4f8e8 | ||
|
|
1f333f6b88 | ||
|
|
9b855fca47 | ||
|
|
c5f433fdf4 | ||
|
|
fd61dae1c1 | ||
|
|
2c45f9759f | ||
|
|
0d3261f748 | ||
|
|
d38e873800 | ||
|
|
ca38914095 | ||
|
|
ee5beeea45 | ||
|
|
a9d40d9f49 | ||
|
|
b8be916c18 | ||
|
|
24d0313fd3 | ||
|
|
c3d2a81327 | ||
|
|
dfeb117663 | ||
|
|
495a830506 | ||
|
|
a730f67ca5 | ||
|
|
9a3867770d | ||
|
|
f8a66bb5e7 | ||
|
|
4b00e1342e | ||
|
|
f9e0584f00 | ||
|
|
900c290e75 | ||
|
|
69e1577d18 | ||
|
|
a6d9044c3a | ||
|
|
9e23d60ef1 | ||
|
|
f12449119c | ||
|
|
533bfc4458 | ||
|
|
1317c2879c | ||
|
|
f9e51f894a | ||
|
|
6fdd4ba833 | ||
|
|
9495ae2336 | ||
|
|
43f634e198 | ||
|
|
ad51be7afc | ||
|
|
15b8bfdf8f | ||
|
|
cb8ae47be6 | ||
|
|
db846c0680 | ||
|
|
630a37025e | ||
|
|
d3bbc7f2b0 | ||
|
|
4e0321ca5f | ||
|
|
ec00bdf9de | ||
|
|
01dd7ad9c6 | ||
|
|
d726005c38 | ||
|
|
4f3e868367 | ||
|
|
ed8bab7df8 | ||
|
|
9bdb14e13a | ||
|
|
b827f7f730 | ||
|
|
07e3660388 | ||
|
|
970ab9004e | ||
|
|
862445259e | ||
|
|
e96538bae0 | ||
|
|
7447ccc487 | ||
|
|
bcd3a00f91 | ||
|
|
8c3675546f | ||
|
|
ec64dab720 | ||
|
|
db976c4ae9 | ||
|
|
0db96795b3 | ||
|
|
59bae96c1b | ||
|
|
d062a0da1b | ||
|
|
d2668974f7 | ||
|
|
78e4c82f20 | ||
|
|
f965452c5d | ||
|
|
be644bb3d9 | ||
|
|
97cc9509c0 | ||
|
|
6dc7a10c2e | ||
|
|
19298b9ad6 | ||
|
|
97d427a6a8 | ||
|
|
bff6eb0503 | ||
|
|
dc9ab2067d | ||
|
|
e8e1f7bafb | ||
|
|
e50a456025 | ||
|
|
d442bbca1a | ||
|
|
e3864b86a4 |
No files matched your search
@@ -1,34 +0,0 @@
|
|||||||
name: CD Asia Ratings Latest
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 0 * * *"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
host:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Use node
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
cache: "npm"
|
|
||||||
|
|
||||||
- name: Install Yarn
|
|
||||||
run: npm install --location=global yarn
|
|
||||||
|
|
||||||
- name: Use node_modules cache
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: "**/node_modules"
|
|
||||||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: yarn
|
|
||||||
|
|
||||||
- name: Generate leaderboard
|
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia --latest
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
name: CD Asia Ratings Leaderboards
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 17 * * *"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
host:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Use node
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
cache: "npm"
|
|
||||||
|
|
||||||
- name: Install Yarn
|
|
||||||
run: npm install --location=global yarn
|
|
||||||
|
|
||||||
- name: Use node_modules cache
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: "**/node_modules"
|
|
||||||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: yarn
|
|
||||||
|
|
||||||
- name: Generate leaderboard
|
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia
|
|
||||||
@@ -2,7 +2,7 @@ name: CD Docs
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ name: CD Host
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */5 * * *'
|
- cron: '0 */6 * * *'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
@@ -29,4 +29,4 @@ jobs:
|
|||||||
unzip bot.zip
|
unzip bot.zip
|
||||||
|
|
||||||
- name: Run bot
|
- name: Run bot
|
||||||
run: NODE_ENV=production GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} node --enable-source-maps --trace-warnings index.cjs
|
run: NODE_ENV=production GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DISCORD_BLITZ_DB=${{ secrets.DISCORD_BLITZ_DB }} node --enable-source-maps index.cjs
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
name: CD Europe Ratings Latest
|
name: CD Ratings Asia
|
||||||
|
|
||||||
|
# latest: '0 0 * * *'
|
||||||
|
# asia midnight: '0 17 * * *'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * *"
|
- cron: '0 0 * * *'
|
||||||
|
- cron: '0 17 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
host:
|
host:
|
||||||
@@ -16,7 +20,7 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: "npm"
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install Yarn
|
- name: Install Yarn
|
||||||
run: npm install --location=global yarn
|
run: npm install --location=global yarn
|
||||||
@@ -24,11 +28,11 @@ jobs:
|
|||||||
- name: Use node_modules cache
|
- name: Use node_modules cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: "**/node_modules"
|
path: '**/node_modules'
|
||||||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu --latest
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
name: CD North America Ratings Latest
|
name: CD Ratings Europe
|
||||||
|
|
||||||
|
# latest: '0 0 * * *'
|
||||||
|
# eu midnight: '0 23 * * *'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
- cron: '0 0 * * *'
|
||||||
|
- cron: '0 23 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
host:
|
host:
|
||||||
@@ -31,4 +35,4 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na --latest
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
name: CD Europe Ratings Leaderboards
|
name: CD Ratings North America
|
||||||
|
|
||||||
|
# latest: '0 0 * * *'
|
||||||
|
# na midnight: '0 5 * * *'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 23 * * *"
|
- cron: '0 0 * * *'
|
||||||
|
- cron: '0 5 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
host:
|
host:
|
||||||
@@ -16,7 +20,7 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: "npm"
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install Yarn
|
- name: Install Yarn
|
||||||
run: npm install --location=global yarn
|
run: npm install --location=global yarn
|
||||||
@@ -24,11 +28,11 @@ jobs:
|
|||||||
- name: Use node_modules cache
|
- name: Use node_modules cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: "**/node_modules"
|
path: '**/node_modules'
|
||||||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu
|
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
name: CI Build Bot
|
name: CI Build Bot
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: push
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: CI Build Docs
|
name: CI Build Docs
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: push
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: CI Build Website
|
name: CI Build Website
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: push
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
name: CD North America Ratings Leaderboards
|
name: CI Version
|
||||||
|
|
||||||
on:
|
on: push
|
||||||
schedule:
|
|
||||||
- cron: '0 5 * * *'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
host:
|
host:
|
||||||
@@ -31,4 +29,4 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Generate leaderboard
|
- name: Generate leaderboard
|
||||||
run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na
|
run: yarn lint:version
|
||||||
@@ -13,4 +13,5 @@ test.*
|
|||||||
/docs/.vitepress/cache
|
/docs/.vitepress/cache
|
||||||
servers.csv
|
servers.csv
|
||||||
.next/
|
.next/
|
||||||
tsconfig.tsbuildinfo
|
tsconfig.tsbuildinfo
|
||||||
|
temp/
|
||||||
@@ -5,15 +5,22 @@
|
|||||||
"bepaint",
|
"bepaint",
|
||||||
"blitzstars",
|
"blitzstars",
|
||||||
"cleandist",
|
"cleandist",
|
||||||
|
"cockroackdb",
|
||||||
|
"corsproxy",
|
||||||
"customperiod",
|
"customperiod",
|
||||||
"deburr",
|
"deburr",
|
||||||
"diacriticless",
|
"diacriticless",
|
||||||
"Everytime",
|
"Everytime",
|
||||||
"fullstats",
|
"fullstats",
|
||||||
"fuzzysort",
|
"fuzzysort",
|
||||||
|
"immer",
|
||||||
"kranvagn",
|
"kranvagn",
|
||||||
|
"krieg",
|
||||||
"Leaderboard",
|
"Leaderboard",
|
||||||
"leaderboards",
|
"leaderboards",
|
||||||
|
"MURICA",
|
||||||
|
"Oopsy",
|
||||||
|
"outdir",
|
||||||
"outfile",
|
"outfile",
|
||||||
"ownedtanks",
|
"ownedtanks",
|
||||||
"playerachievements",
|
"playerachievements",
|
||||||
@@ -33,15 +40,18 @@
|
|||||||
"subnation",
|
"subnation",
|
||||||
"tankaverages",
|
"tankaverages",
|
||||||
"tankopedia",
|
"tankopedia",
|
||||||
|
"tankopedias",
|
||||||
"tankstats",
|
"tankstats",
|
||||||
"tresabhi",
|
"tresabhi",
|
||||||
"Unicum",
|
"Unicum",
|
||||||
"Unregistering",
|
"Unregistering",
|
||||||
"vickers",
|
"vickers",
|
||||||
"vitepress",
|
"vitepress",
|
||||||
|
"Vovko",
|
||||||
"wargaming",
|
"wargaming",
|
||||||
"webp",
|
"webp",
|
||||||
"winrate",
|
"winrate",
|
||||||
|
"wotblitz",
|
||||||
"zustand"
|
"zustand"
|
||||||
],
|
],
|
||||||
"deno.enable": false,
|
"deno.enable": false,
|
||||||
|
|||||||
@@ -14,31 +14,10 @@ Go to [application directory for Blitzkrieg](https://discord.com/application-dir
|
|||||||
|
|
||||||
### https://blitz-krieg.vercel.app/
|
### https://blitz-krieg.vercel.app/
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Visit the documentation website
|
## Visit the documentation website
|
||||||
|
|
||||||
### https://tresabhi.github.io/blitzkrieg/
|
### https://tresabhi.github.io/blitzkrieg/
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Run the bot
|
|
||||||
|
|
||||||
### Install dependencies
|
|
||||||
|
|
||||||
```bash
|
|
||||||
yarn
|
|
||||||
```
|
|
||||||
|
|
||||||
### Create `.env`
|
|
||||||
|
|
||||||
```env
|
|
||||||
GH_TOKEN={YOUR_GITHUB_TOKEN_HERE}
|
|
||||||
DISCORD_TOKEN={YOUR_DISCORD_TOKE_HERE}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Run the command
|
|
||||||
|
|
||||||
```bash
|
|
||||||
yarn dev:bot
|
|
||||||
```
|
|
||||||
@@ -8,5 +8,7 @@
|
|||||||
"sklld_peasant_role": "896878529512370228",
|
"sklld_peasant_role": "896878529512370228",
|
||||||
|
|
||||||
"tres_guild_id": "734786591205359697",
|
"tres_guild_id": "734786591205359697",
|
||||||
"tres_log_channel": "1109262265850544148"
|
"tres_log_channel": "1109262265850544148",
|
||||||
|
|
||||||
|
"test_guild_id": "1124729294829142116"
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ export default defineConfig({
|
|||||||
themeConfig: {
|
themeConfig: {
|
||||||
nav: [
|
nav: [
|
||||||
{ text: 'Home', link: '/' },
|
{ text: 'Home', link: '/' },
|
||||||
{ text: 'Guide', link: '/guide/about' },
|
{ text: 'Guide', link: '/guide/introduction' },
|
||||||
],
|
],
|
||||||
|
|
||||||
sidebar: [
|
sidebar: [
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Blitzkrieg 1.13.3
|
||||||
|
|
||||||
|
Streamer's delight!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added config context menu for the session tracker embed
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# Blitzkrieg 1.14.0
|
||||||
|
|
||||||
|
Elegance has never been met like this before
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added `/link`
|
||||||
|
- Unlike `/verify`, `/link` links you Discord and Blitz accounts across all servers
|
||||||
|
- This command does not change your nickname
|
||||||
|
- `/link` now simply displays a deprecation message
|
||||||
|
- Usernames can still be inputted per-command to override your linked account
|
||||||
|
- `/stats` and `/full-stats` are now way simpler
|
||||||
|
- `/stats <type> <period>` has been replaced with `/stats <30|60|90|...>` (likewise, `/full-stats`)
|
||||||
|
- These commands now have filters without having to opt into `multi-tank`
|
||||||
|
- Added `/breakdown`
|
||||||
|
- Unlike `/today`, `/breakdown` lets you select any period of time
|
||||||
|
- `/breakdown` now simply displays a deprecation message
|
||||||
|
- `/about commands` are now sorted alphabetically
|
||||||
|
- Added a `/reset` button to the options dropdown and embed context-menu
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Simplified no ongoing ratings season edge case
|
||||||
|
- Updated welcome message for Skilled server to use `/link` and other up-to-date information
|
||||||
|
- Tier weights are now reported in Arabic numerals instead of Roman
|
||||||
|
- Removed tank images from `/owned-tanks`
|
||||||
|
- Wargaming messed up their API and almost no tanks have any images anymore
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Banners now use a more economical `.webp` format just like the home page
|
||||||
|
- Removed unused color palettes
|
||||||
|
|
||||||
|
## Technical changes
|
||||||
|
|
||||||
|
- Guild commands are now handled more efficiently
|
||||||
|
- Removed nickname-based Blitz username inference
|
||||||
|
- Code split a lot of common functionalities
|
||||||
|
- Re-arranged `core` folder
|
||||||
|
- Added midnight and latest ratings leaderboard caches
|
||||||
|
- Merged renderers into their primary user files
|
||||||
|
- Added sharding
|
||||||
|
- Disabled for now but good for future proofing
|
||||||
|
- Switched to a way cleaner logging schema
|
||||||
|
- Hosting is now done in 6 hour periods instead of 5
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Blitzkrieg 1.14.1
|
||||||
|
|
||||||
|
Oopsy daisy, a memory leak!
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Simplified message for users to use `/link`
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Fixed a memory leak in the render thread manager
|
||||||
|
|
||||||
|
## Technical changes
|
||||||
|
|
||||||
|
- Added `UserError` extending `Error`
|
||||||
|
- This lets the bot avoid spamming the debug console for mistakes users make
|
||||||
|
- Reduced render threads to 2
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Blitzkrieg 1.14.2
|
||||||
|
|
||||||
|
A late night hot fix for my homies
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Clan info is now fetched using `clan_id` instead of `account_id`
|
||||||
|
- Generic stats row names are now bounded by a max width
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Blitzkrieg 1.14.3
|
||||||
|
|
||||||
|
Pull your brush out and start polishing.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Rows in `/breakdown` are now chunked into `8` per image
|
||||||
|
- This is true unless the number of pages exceeds `10` in which case the rows are even distributed across all `10` pages
|
||||||
|
- `10` is the maximum number of images that Discord allows
|
||||||
|
- Short region names are used in username autocomplete instead of their full names
|
||||||
|
- Example: "North America" is "NA" now
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Removed reference to username inference in the username option description
|
||||||
|
- Removed an unnecessary type `asd` that did absolutely nothing used nowhere
|
||||||
|
|
||||||
|
## Technical changes
|
||||||
|
|
||||||
|
- Image orders are now preserved even if processed in parallel and all completed out of order
|
||||||
|
- `fetchBlitz` is now throttled to `10` requests per second
|
||||||
|
- Request overflows are managed by queueing
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Blitzkrieg 1.14.4
|
||||||
|
|
||||||
|
Streamers get some knowledge today
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Added a video in the embed button prompt
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# Blitzkrieg 1.15.0
|
||||||
|
|
||||||
|
Ratings will never be the same.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Blitzkrieg ratings leaderboard
|
||||||
|
- Available at https://blitz-krieg.vercel.app/tools/ratings
|
||||||
|
- **Highly experimental; [please report bugs on Discord server](https://discord.gg/nDt7AjGJQH)**
|
||||||
|
- Current season leaderboards are live meaning that there may be scores and positions that are out of order
|
||||||
|
- Options
|
||||||
|
- Regions can be swapped between NA, EU, and Asia
|
||||||
|
- The current season and all archived season (from 49 and onwards) are available
|
||||||
|
- Jump: used to jump to certain players
|
||||||
|
- Score: finds the first player with at least your desired score
|
||||||
|
- Position: finds the player at that position
|
||||||
|
- League: finds the top-most player in that league
|
||||||
|
- Player: finds the player
|
||||||
|
- **Jumping to scores and positions for the current season is a compounding function (hence the loading screen) and is limited to the speed of Wargaming's APIs which is pretty darn slow**
|
||||||
|
- Page controls
|
||||||
|
- Flip between pages left and right
|
||||||
|
- 33 players are loaded at once
|
||||||
|
- Left control is disabled on the first page and vice versa
|
||||||
|
- Page turning controls are also disabled if the next/previous page hasn't loaded yet
|
||||||
|
- Page numbers can be manually typed in the text field too
|
||||||
|
- This is available both at the top and the bottom of the screen
|
||||||
|
- Players
|
||||||
|
- Shows the position of the player
|
||||||
|
- Shows the player nickname and clan name
|
||||||
|
- "Deleted player ID" us shown when loading a deleted player
|
||||||
|
- A skeleton is shown when the player and clan is loading
|
||||||
|
- Shows the player percentile
|
||||||
|
- Shows reward for the position
|
||||||
|
- This is blank when there is no reward
|
||||||
|
- This column isn't available for archived seasons
|
||||||
|
- Shows the score
|
||||||
|
- A skeleton is shown when loading
|
||||||
|
- Click on a row to highlight it
|
||||||
|
- Using a jump button also highlights a row
|
||||||
|
- `/credits`: thanks who helped made this project
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Error messages that user face are now even more simplified
|
||||||
|
- Increased username and clan autocomplete size limits to `25`
|
||||||
|
- Added capability for per-page accent theming
|
||||||
|
- Example: the ratings page is red while the session tracker is blue
|
||||||
|
- Simplified welcome message for SKLLD clan server
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Isolated tankopedia info
|
||||||
|
- Implemented `corsproxy.io` for non-timeout tolerant endpoints
|
||||||
|
- Latest archived season number is now data driven
|
||||||
|
- Ratings archives are now public
|
||||||
|
- This eliminates the need of `octokit`
|
||||||
|
- Ratings leaderboard archiver is now error tolerant
|
||||||
|
- Fetch attempts are made every `1000ms`
|
||||||
|
- Blitz errors are now managed better freeing up the queue faster
|
||||||
|
- Isolated first archived season number
|
||||||
|
- Added more advanced PSAs
|
||||||
|
- These can now feature images or embeds
|
||||||
|
- These can now modify message contents
|
||||||
|
- These can also now be secret
|
||||||
|
|
||||||
|
## Experimental Changes
|
||||||
|
|
||||||
|
- Added tankopedia extractor
|
||||||
|
- Retrieves tankopedia data from the game files
|
||||||
|
- This is not utilized as of right now
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Blitzkrieg 1.15.1
|
||||||
|
|
||||||
|
'MURICA!
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- "Neighbor" is now spelled in the American way
|
||||||
|
- Updated documentation website with the latest information
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Fixed the guide link on the documentation website
|
||||||
|
|
||||||
|
## Technical features
|
||||||
|
|
||||||
|
- Added capability to fetch patiently while also parsing the JSON
|
||||||
|
|
||||||
|
## Technical changes
|
||||||
|
|
||||||
|
- Removed neighbor relative position caching
|
||||||
|
|
||||||
|
## Technical fixes
|
||||||
|
|
||||||
|
- `/ratings` now uses the non-caching APIs
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Blitzkrieg 1.15.2
|
||||||
|
|
||||||
|
Infinity reduced to a finite value.
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Added a maximum value to the jump to position button
|
||||||
|
- Removed neighbor checking for the seeding player
|
||||||
|
- This fixes the jump to position button not loading at all
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Blitzkrieg 1.15.3
|
||||||
|
|
||||||
|
The bot now gets more expressive!
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- The bot can now have presence messages; examples:
|
||||||
|
- "Living in {number} servers"
|
||||||
|
- "Server {number} users"
|
||||||
|
- "Observing {number} channels"
|
||||||
|
- More will be added in the future! Give me some ideas
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Moved `/credits` to `/about creators`
|
||||||
|
- `/debug` command now ditches embeds and has better information to serve
|
||||||
|
|
||||||
|
## Technical Features
|
||||||
|
|
||||||
|
- Added a workflow and lint for package and changelog version miss match
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Removed manual trigger for Asian latest ratings leaderboard archiver
|
||||||
|
- Leaderboard archiver now accepts an explicit target like `midnight` or `latest`
|
||||||
|
- Combined midnight and latest leaderboard archival workflow into one file
|
||||||
|
|
||||||
|
## Technical Fixed
|
||||||
|
|
||||||
|
- Reviewed all workflow triggers and updated them
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Blitzkrieg 1.15.4
|
||||||
|
|
||||||
|
Unlocking future potential
|
||||||
|
|
||||||
|
## Technical Changes
|
||||||
|
|
||||||
|
- Moved the word "Ratings" to the front of the workflow name
|
||||||
|
- Renamed `blitzkrieg-db` to `blitzkrieg-assets`
|
||||||
|
- Moved the region folders from the root to `regions`
|
||||||
|
|
||||||
|
## Technical Fixes
|
||||||
|
|
||||||
|
- The ratings leaderboard archiver now correctly skips undefined players
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Blitzkrieg 1.15.5
|
||||||
|
|
||||||
|
Oops, this should've been in the last patch.
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- User and channel cache is now guild cache exhaustive
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Blitzkrieg 1.15.6
|
||||||
|
|
||||||
|
This should have also been in the last update lol.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Changed the format of `/about creators` and added one more person
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Archived ratings leaderboards are now fetched from the correct URL path
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Blitzkrieg 1.15.7
|
||||||
|
|
||||||
|
Simple yet powerful theming options for the session tracker
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- The accent color of the session tracker (hence the embed too) can now be tweaked
|
||||||
|
- Access this setting via the dropdown from Options > Accent color
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
- Reimplemented the commas for last numbers in the overflow count of the ratings leaderboard
|
||||||
|
- For example, "+1234567 more" will now read "+1,234,567 more"
|
||||||
|
|
||||||
|
## Technical Features
|
||||||
|
|
||||||
|
- Added class names for more in-depth customization for those who are comfortable with CSS
|
||||||
|
- `session-tracker-root`
|
||||||
|
- `session-tracker-row`
|
||||||
|
- `session-tracker-row-stat`
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Blitzkrieg 1.15.8
|
||||||
|
|
||||||
|
A request fulfilled \:\)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Added custom titles in session tracker
|
||||||
|
- Change the title through Options > Edit title...
|
||||||
|
- Colors are shown when selecting a theme color for the session tracker
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Creators
|
||||||
|
|
||||||
|
- **TrèsAbhi** `@tresabhi`: Creator and main programmer
|
||||||
|
- **Prince_NA** `@prince_na`: Game advisor & tester
|
||||||
|
- **Vovko**: Technical advisor
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Installing Blitzkrieg
|
|
||||||
|
|
||||||
It's easy as 1, 2, 3!
|
|
||||||
|
|
||||||
## Step 1
|
|
||||||
|
|
||||||
Join a server that already has Blitzkrieg or [join our official Discord server](https://discord.gg/nDt7AjGJQH).
|
|
||||||
|
|
||||||
## Step 2
|
|
||||||
|
|
||||||
View the bot's profile and click "Add to Server".
|
|
||||||
|
|
||||||
<video src="https://i.imgur.com/Zq0P3m2.mp4" autoplay loop muted width=320 title="how to install"></video>
|
|
||||||
|
|
||||||
## Step 3
|
|
||||||
|
|
||||||
Review the permissions the bot is asking for and add it to your server!
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
Blitzkrieg is a multipurpose bot for anything and everything World of Tanks Blitz.
|
🎉 Services for everything and anything World of Tanks Blitz
|
||||||
|
|
||||||
|
## Bot
|
||||||
|
|
||||||
|
Blitzkrieg is available as a Discord bot and can be [installed very easily](/guide/invite).
|
||||||
|
|
||||||
- Track statistics
|
- Track statistics
|
||||||
- Find inactive players in a clan
|
- Find inactive players in a clan
|
||||||
@@ -8,3 +12,11 @@ Blitzkrieg is a multipurpose bot for anything and everything World of Tanks Blit
|
|||||||
- Create embeds for streams
|
- Create embeds for streams
|
||||||
- Track a player/tanks statistical evolution
|
- Track a player/tanks statistical evolution
|
||||||
- ...and a variety of other similar things
|
- ...and a variety of other similar things
|
||||||
|
|
||||||
|
## Website
|
||||||
|
|
||||||
|
Provides a bunch of very helpful tools; https://blitz-krieg.vercel.app/
|
||||||
|
|
||||||
|
- Session tracker
|
||||||
|
- Ratings leaderboard
|
||||||
|
- Way more to come
|
||||||
@@ -12,10 +12,10 @@ hero:
|
|||||||
actions:
|
actions:
|
||||||
- theme: brand
|
- theme: brand
|
||||||
text: Add to Discord Server
|
text: Add to Discord Server
|
||||||
link: guide/install
|
link: /guide/invite
|
||||||
- theme: alt
|
- theme: alt
|
||||||
text: Guide
|
text: Guide
|
||||||
link: /guide/about
|
link: /guide/introduction
|
||||||
|
|
||||||
features:
|
features:
|
||||||
- title: Clean and Efficient UI
|
- title: Clean and Efficient UI
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 183 KiB |
@@ -7,6 +7,7 @@ const nextConfig = {
|
|||||||
...withVanillaExtract(),
|
...withVanillaExtract(),
|
||||||
|
|
||||||
distDir: 'dist/website',
|
distDir: 'dist/website',
|
||||||
|
reactStrictMode: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --enable-source-maps --trace-warnings server.cjs"
|
"start": "node --enable-source-maps server.cjs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "blitzkrieg",
|
"name": "blitzkrieg",
|
||||||
"version": "1.13.2",
|
"version": "1.15.8",
|
||||||
"description": "🎉 Tools for everything World of Tanks Blitz",
|
"description": "🎉 Tools for everything World of Tanks Blitz",
|
||||||
"main": "src/server.ts",
|
"main": "src/server.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -9,10 +9,11 @@
|
|||||||
"build:website": "next build",
|
"build:website": "next build",
|
||||||
"build:docs": "vitepress build docs",
|
"build:docs": "vitepress build docs",
|
||||||
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
||||||
|
"build:tankopedia": "vite-node --script scripts/buildTankopedia",
|
||||||
"dev:bot": "yarn build:bot && yarn start:bot",
|
"dev:bot": "yarn build:bot && yarn start:bot",
|
||||||
"dev:docs": "vitepress dev docs",
|
"dev:docs": "vitepress dev docs",
|
||||||
"dev:website": "next dev",
|
"dev:website": "next dev",
|
||||||
"start:bot": "node --enable-source-maps --trace-warnings dist/bot/index.cjs",
|
"start:bot": "node --enable-source-maps dist/bot/index.cjs",
|
||||||
"start:website": "next start",
|
"start:website": "next start",
|
||||||
"host:docs": "vitepress preview docs",
|
"host:docs": "vitepress preview docs",
|
||||||
"publish:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard --publish",
|
"publish:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard --publish",
|
||||||
@@ -20,24 +21,28 @@
|
|||||||
"lint": "npx tsc",
|
"lint": "npx tsc",
|
||||||
"lint:website": "next lint",
|
"lint:website": "next lint",
|
||||||
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
|
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
|
||||||
|
"lint:version": "vite-node --script scripts/checkVersionMissMatch",
|
||||||
"knip": "knip",
|
"knip": "knip",
|
||||||
"update": "yarn upgrade --latest"
|
"update": "yarn upgrade --latest"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/rest": "^20.0.1",
|
"@octokit/rest": "^20.0.1",
|
||||||
|
"@prisma/client": "^5.4.1",
|
||||||
"@radix-ui/colors": "^3.0.0-rc.4",
|
"@radix-ui/colors": "^3.0.0-rc.4",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/themes": "^1.1.2",
|
"@radix-ui/themes": "^1.1.2",
|
||||||
"@resvg/resvg-js": "^2.4.1",
|
"@resvg/resvg-js": "^2.4.1",
|
||||||
"@vanilla-extract/css": "^1.13.0",
|
"@vanilla-extract/css": "^1.13.0",
|
||||||
"bepaint": "^0.1.0-beta.3",
|
"bepaint": "^0.1.0-beta.3",
|
||||||
|
"decompress": "^4.2.1",
|
||||||
"discord.js": "^14.13.0",
|
"discord.js": "^14.13.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"esbuild": "^0.19.3",
|
"esbuild": "^0.19.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fuzzysort": "^2.0.4",
|
"fuzzysort": "^2.0.4",
|
||||||
"immer": "^10.0.2",
|
"immer": "^10.0.2",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"markdown-escape": "^2.0.0",
|
"markdown-escape": "^2.0.0",
|
||||||
"next": "^13.5.2",
|
"next": "^13.5.2",
|
||||||
@@ -48,12 +53,15 @@
|
|||||||
"vite-node": "^0.34.5",
|
"vite-node": "^0.34.5",
|
||||||
"vitepress": "^1.0.0-rc.20",
|
"vitepress": "^1.0.0-rc.20",
|
||||||
"vitepress-plugin-auto-sidebar": "^1.1.0",
|
"vitepress-plugin-auto-sidebar": "^1.1.0",
|
||||||
|
"xml-js": "^1.6.11",
|
||||||
"zustand": "^4.4.1"
|
"zustand": "^4.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@total-typescript/ts-reset": "^0.5.1",
|
"@total-typescript/ts-reset": "^0.5.1",
|
||||||
|
"@types/decompress": "^4.2.6",
|
||||||
"@types/escape-html": "^1.0.2",
|
"@types/escape-html": "^1.0.2",
|
||||||
"@types/express": "^4.17.18",
|
"@types/express": "^4.17.18",
|
||||||
|
"@types/js-yaml": "^4.0.8",
|
||||||
"@types/lodash": "^4.14.199",
|
"@types/lodash": "^4.14.199",
|
||||||
"@types/markdown-escape": "^1.1.0",
|
"@types/markdown-escape": "^1.1.0",
|
||||||
"@types/node": "^20.6.5",
|
"@types/node": "^20.6.5",
|
||||||
@@ -62,6 +70,7 @@
|
|||||||
"compare-versions": "^6.1.0",
|
"compare-versions": "^6.1.0",
|
||||||
"knip": "^2.27.1",
|
"knip": "^2.27.1",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
|
"prisma": "^5.4.1",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "discord_blitz" (
|
||||||
|
"discord" INT8 NOT NULL,
|
||||||
|
"region" STRING NOT NULL,
|
||||||
|
"blitz" INT4 NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "discord_blitz_pkey" PRIMARY KEY ("discord")
|
||||||
|
);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Please do not edit this file manually
|
||||||
|
# It should be added in your version-control system (i.e. Git)
|
||||||
|
provider = "cockroachdb"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "cockroachdb"
|
||||||
|
url = env("DISCORD_BLITZ_DB")
|
||||||
|
}
|
||||||
|
|
||||||
|
model discord_blitz {
|
||||||
|
discord BigInt @id
|
||||||
|
region String
|
||||||
|
blitz Int
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 2.6 MiB After Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 8.2 MiB After Width: | Height: | Size: 5.4 MiB |
|
Before Width: | Height: | Size: 2.0 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 3.8 MiB After Width: | Height: | Size: 2.4 MiB |
|
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
|
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 1.3 MiB |
@@ -1,27 +1,44 @@
|
|||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
|
import { cp, readdir } from 'fs/promises';
|
||||||
|
|
||||||
console.log('Building bot...');
|
readdir('src/workers').then((workers) => {
|
||||||
|
const files = [
|
||||||
|
'bot',
|
||||||
|
'index',
|
||||||
|
|
||||||
await build({
|
...workers.map((file) => `workers/${file.replace('.ts', '')}`),
|
||||||
entryPoints: ['src/bot.ts'],
|
];
|
||||||
outfile: 'dist/bot/index.cjs',
|
|
||||||
|
|
||||||
platform: 'node',
|
build({
|
||||||
tsconfig: 'tsconfig.esbuild.json',
|
entryPoints: files.map((file) => `src/${file}.ts`),
|
||||||
loader: {
|
outdir: 'dist/bot',
|
||||||
'.node': 'copy',
|
|
||||||
'.ttf': 'file',
|
|
||||||
},
|
|
||||||
format: 'cjs',
|
|
||||||
jsx: 'transform',
|
|
||||||
|
|
||||||
bundle: true,
|
platform: 'node',
|
||||||
sourcemap: true,
|
tsconfig: 'tsconfig.esbuild.json',
|
||||||
minifyIdentifiers: false, // cause goofy errors
|
loader: {
|
||||||
minifySyntax: true,
|
'.node': 'copy',
|
||||||
minifyWhitespace: true,
|
'.ttf': 'file',
|
||||||
|
},
|
||||||
|
format: 'cjs',
|
||||||
|
jsx: 'transform',
|
||||||
|
outExtension: {
|
||||||
|
'.js': '.cjs',
|
||||||
|
},
|
||||||
|
|
||||||
logLevel: 'info',
|
bundle: true,
|
||||||
|
sourcemap: true,
|
||||||
|
minifyIdentifiers: false, // causes goofy errors
|
||||||
|
minifySyntax: true,
|
||||||
|
minifyWhitespace: true,
|
||||||
|
|
||||||
|
logLevel: 'info',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Built bot');
|
// copy schema.prisma
|
||||||
|
cp('prisma/schema.prisma', 'dist/bot/schema.prisma');
|
||||||
|
readdir('node_modules/prisma').then((files) =>
|
||||||
|
files
|
||||||
|
.filter((file) => file.endsWith('.node'))
|
||||||
|
.map((file) => cp(`node_modules/prisma/${file}`, `dist/bot/${file}`)),
|
||||||
|
);
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
RatingsNeighbors,
|
RatingsNeighbors,
|
||||||
RatingsPlayer,
|
RatingsPlayer,
|
||||||
} from '../src/commands/ratings';
|
} from '../src/commands/ratings';
|
||||||
|
import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON';
|
||||||
import commitMultipleFiles from './commitMultipleFiles.js';
|
import commitMultipleFiles from './commitMultipleFiles.js';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -13,25 +14,27 @@ import commitMultipleFiles from './commitMultipleFiles.js';
|
|||||||
* Central European Time (UTC+1): use 0 23 * * *.
|
* Central European Time (UTC+1): use 0 23 * * *.
|
||||||
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
||||||
*
|
*
|
||||||
* na/ratings/49/info.json: season info like rewards, start & end time, etc.
|
* [region]/ratings/[season]/info.json: season info like rewards, start & end time, etc.
|
||||||
* na/ratings/49/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
* [region]/ratings/[season]/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
||||||
* na/ratings/49/midnight.json: last midnight's leaderboard relative to the region
|
* [region]/ratings/[season]/midnight.json: last midnight's leaderboard relative to the region
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type BlitzkriegRatingsLeaderboard = { id: number; score: number }[];
|
export type BlitzkriegRatingsLeaderboardEntry = { id: number; score: number };
|
||||||
|
export type BlitzkriegRatingsLeaderboard = BlitzkriegRatingsLeaderboardEntry[];
|
||||||
|
|
||||||
const publish = argv.includes('--publish');
|
const publish = argv.includes('--publish');
|
||||||
const latest = argv.includes('--latest');
|
const target = argv
|
||||||
|
.find((arg) => arg.startsWith('--target='))
|
||||||
|
?.split('=')[1] as 'midnight' | 'latest' | undefined;
|
||||||
const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1];
|
const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1];
|
||||||
|
|
||||||
|
if (!target) throw new Error('Target parameter not specified');
|
||||||
if (!server) throw new Error('Region parameter not specified');
|
if (!server) throw new Error('Region parameter not specified');
|
||||||
|
|
||||||
const NEIGHBORS = 1000;
|
const NEIGHBORS = 2 ** 8;
|
||||||
const PLAYERS = await fetch(
|
const PLAYERS = await patientFetchJSON<RatingsInfo>(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
)
|
).then((data) => (data.detail === undefined ? data.count : undefined));
|
||||||
.then((response) => response.json() as Promise<RatingsInfo>)
|
|
||||||
.then((data) => (data.detail === undefined ? data.count : undefined));
|
|
||||||
|
|
||||||
if (PLAYERS === undefined) {
|
if (PLAYERS === undefined) {
|
||||||
throw new Error('No current ratings season running');
|
throw new Error('No current ratings season running');
|
||||||
@@ -42,9 +45,9 @@ const leaderboard: BlitzkriegRatingsLeaderboard = [];
|
|||||||
let registered = 0;
|
let registered = 0;
|
||||||
|
|
||||||
async function branchFromPlayer(id: number) {
|
async function branchFromPlayer(id: number) {
|
||||||
const { neighbors } = await fetch(
|
const { neighbors } = await patientFetchJSON<RatingsNeighbors>(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
||||||
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
);
|
||||||
|
|
||||||
const firstPlayer = neighbors[0];
|
const firstPlayer = neighbors[0];
|
||||||
const lastPlayer = neighbors[neighbors.length - 1];
|
const lastPlayer = neighbors[neighbors.length - 1];
|
||||||
@@ -73,9 +76,9 @@ async function branchFromPlayer(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function branchFromLeague(id: number) {
|
async function branchFromLeague(id: number) {
|
||||||
const { result } = await fetch(
|
const { result } = await patientFetchJSON<{ result: RatingsPlayer[] }>(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
||||||
).then((response) => response.json() as Promise<{ result: RatingsPlayer[] }>);
|
);
|
||||||
|
|
||||||
const firstPlayer = result[0];
|
const firstPlayer = result[0];
|
||||||
const lastPlayer = result[result.length - 1];
|
const lastPlayer = result[result.length - 1];
|
||||||
@@ -98,7 +101,10 @@ await Promise.all([
|
|||||||
console.log('Converting to an array...');
|
console.log('Converting to an array...');
|
||||||
for (let index = 0; index < PLAYERS; index++) {
|
for (let index = 0; index < PLAYERS; index++) {
|
||||||
const listing = players[index + 1];
|
const listing = players[index + 1];
|
||||||
if (!listing) console.warn(`Position ${index + 1} had no player`);
|
if (!listing) {
|
||||||
|
console.warn(`Position ${index + 1} had no player`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
leaderboard[index] = {
|
leaderboard[index] = {
|
||||||
id: listing.spa_id,
|
id: listing.spa_id,
|
||||||
@@ -110,26 +116,19 @@ const leaderboardJSON = JSON.stringify(leaderboard);
|
|||||||
|
|
||||||
if (publish) {
|
if (publish) {
|
||||||
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
||||||
|
const info = await patientFetchJSON<RatingsInfo & { detail: undefined }>(
|
||||||
const info = await fetch(
|
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
).then(
|
|
||||||
(response) =>
|
|
||||||
response.json() as Promise<RatingsInfo & { detail: undefined }>,
|
|
||||||
);
|
);
|
||||||
const normalizedServer = server === 'na' ? 'com' : server;
|
const normalizedServer = server === 'na' ? 'com' : server;
|
||||||
|
const infoPath = `regions/${normalizedServer}/ratings/${info.current_season}/info.json`;
|
||||||
const infoPath = `${normalizedServer}/ratings/${info.current_season}/info.json`;
|
const leaderboardPath = `regions/${normalizedServer}/ratings/${info.current_season}/${target}.json`;
|
||||||
const leaderboardPath = `${normalizedServer}/ratings/${info.current_season}/${
|
|
||||||
latest ? 'latest' : 'midnight'
|
|
||||||
}.json`;
|
|
||||||
const infoJSON = JSON.stringify(info);
|
const infoJSON = JSON.stringify(info);
|
||||||
|
|
||||||
console.log(`Publishing to season ${info.current_season}...`);
|
console.log(`Publishing to season ${info.current_season}...`);
|
||||||
commitMultipleFiles(
|
commitMultipleFiles(
|
||||||
octokit,
|
octokit,
|
||||||
'tresabhi',
|
'tresabhi',
|
||||||
'blitzkrieg-db',
|
'blitzkrieg-assets',
|
||||||
'main',
|
'main',
|
||||||
new Date().toString(),
|
new Date().toString(),
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import decompress from 'decompress';
|
||||||
|
import { readFile, readdir, rm, writeFile } from 'fs/promises';
|
||||||
|
import { load } from 'js-yaml';
|
||||||
|
import { ElementCompact, xml2js } from 'xml-js';
|
||||||
|
import { NATION_IDS } from '../src/constants/nations';
|
||||||
|
|
||||||
|
const REWRITE = false;
|
||||||
|
const VEHICLE_DEFS = 'assets/Data/XML/item_defs/vehicles';
|
||||||
|
const APK_FILE = 'temp/blitz.apk';
|
||||||
|
const STRINGS = 'assets/Data/Strings';
|
||||||
|
const LANGUAGE = 'en';
|
||||||
|
const DIRECTORIES_OF_INTEREST = [VEHICLE_DEFS, STRINGS];
|
||||||
|
|
||||||
|
if (REWRITE) {
|
||||||
|
await rm('temp/blitz', { recursive: true, force: true });
|
||||||
|
decompress(APK_FILE, 'temp/blitz', {
|
||||||
|
filter: (file) =>
|
||||||
|
DIRECTORIES_OF_INTEREST.some((dir) => file.path.startsWith(dir)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BlitzkriegTankopedia {
|
||||||
|
id: number;
|
||||||
|
nation: string;
|
||||||
|
name: string;
|
||||||
|
name_short?: string;
|
||||||
|
is_premium: boolean;
|
||||||
|
is_collector: boolean;
|
||||||
|
tier: number;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const strings = await readFile(
|
||||||
|
`temp/blitz/${STRINGS}/${LANGUAGE}.yaml`,
|
||||||
|
'utf-8',
|
||||||
|
).then((data) => load(data) as Record<string, string>);
|
||||||
|
const tankopedia: Record<number, BlitzkriegTankopedia> = {};
|
||||||
|
const nations = await readdir(`temp/blitz/${VEHICLE_DEFS}`);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
nations
|
||||||
|
.filter((nation) => nation !== 'common')
|
||||||
|
.map(async (nation) => {
|
||||||
|
const listXML = await readFile(
|
||||||
|
`temp/blitz/${VEHICLE_DEFS}/${nation}/list.xml`,
|
||||||
|
'utf-8',
|
||||||
|
);
|
||||||
|
const list = xml2js(listXML, { compact: true }) as ElementCompact;
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
Object.entries<ElementCompact>(list.root).map(
|
||||||
|
async ([vehicle, vehicleData]) => {
|
||||||
|
// const vehicleXML = await readFile(
|
||||||
|
// `temp/blitz/${VEHICLE_DEFS}/${nation}/${vehicle}.xml`,
|
||||||
|
// 'utf-8',
|
||||||
|
// ).then((xml) => xml2js(xml, { compact: true }) as ElementCompact);
|
||||||
|
const nationVehicleId = parseInt(list.root[vehicle].id._text);
|
||||||
|
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
|
||||||
|
// TODO: use userString property instead
|
||||||
|
const name = strings[`#${nation}_vehicles:${vehicle}`];
|
||||||
|
const name_short = strings[`#${nation}_vehicles:${vehicle}_short`];
|
||||||
|
const is_premium = 'gold' in vehicleData.price;
|
||||||
|
const is_collector = vehicleData.sellPrice
|
||||||
|
? 'gold' in vehicleData.sellPrice
|
||||||
|
: false;
|
||||||
|
const tier = parseInt(vehicleData.level._text);
|
||||||
|
const tags = vehicleData.tags._text.split(' ');
|
||||||
|
const type = tags[0];
|
||||||
|
|
||||||
|
tankopedia[id] = {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
name_short,
|
||||||
|
nation,
|
||||||
|
is_premium,
|
||||||
|
is_collector,
|
||||||
|
tier,
|
||||||
|
type,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
writeFile('dist/tankopedia.json', JSON.stringify(tankopedia, null, 2));
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { readdir } from 'fs/promises';
|
||||||
|
import packageJSON from '../package.json';
|
||||||
|
|
||||||
|
const { version } = packageJSON;
|
||||||
|
const changelogs = await readdir('docs/changelogs');
|
||||||
|
const hasVersion = changelogs.includes(`${version}.md`);
|
||||||
|
|
||||||
|
if (hasVersion) {
|
||||||
|
console.log(`Version ${version} found in changelogs`);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Version ${version} not found in changelogs`);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { Region } from '../../../../../../constants/regions';
|
||||||
|
import getRatingsInfo from '../../../../../../core/blitz/getRatingsInfo';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { region: Region } },
|
||||||
|
) {
|
||||||
|
return NextResponse.json(await getRatingsInfo(params.region));
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { Region } from '../../../../../../../constants/regions';
|
||||||
|
import { getRatingsLeague } from '../../../../../../../core/blitz/getRatingsLeague';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { region: Region; league: number } },
|
||||||
|
) {
|
||||||
|
return NextResponse.json(
|
||||||
|
await getRatingsLeague(params.region, params.league, true),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { Region } from '../../../../../../../constants/regions';
|
||||||
|
import { searchCurrentRatingsPlayers } from '../../../../../../../core/blitz/searchCurrentRatingsPlayers';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { region: Region; username: string } },
|
||||||
|
) {
|
||||||
|
return NextResponse.json(
|
||||||
|
await searchCurrentRatingsPlayers(params.region, params.username),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { tankopedia } from '../../../core/blitz/tankopedia';
|
import { tankopedia } from '../../../core/blitzstars/tankopedia';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
return NextResponse.json(await tankopedia);
|
return NextResponse.json(await tankopedia);
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { ContextMenu } from '@radix-ui/themes';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import * as Breakdown from '../../../components/Breakdown';
|
import * as Breakdown from '../../../components/Breakdown';
|
||||||
import { TreeTypeEnum } from '../../../components/Tanks';
|
import { TreeTypeEnum } from '../../../components/Tanks';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||||
import calculateWN8 from '../../../core/blitz/calculateWN8';
|
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||||
import { diffNormalizedTankStats } from '../../../core/blitz/diffNormalizedTankStats';
|
|
||||||
import getWN8Percentile from '../../../core/blitz/getWN8Percentile';
|
|
||||||
import getWargamingResponse from '../../../core/blitz/getWargamingResponse';
|
|
||||||
import { TankopediaEntry, tankopedia } from '../../../core/blitz/tankopedia';
|
|
||||||
import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
||||||
import { useSession } from '../../../stores/session';
|
import {
|
||||||
|
TankopediaEntry,
|
||||||
|
tankopedia,
|
||||||
|
} from '../../../core/blitzstars/tankopedia';
|
||||||
|
import calculateWN8 from '../../../core/statistics/calculateWN8';
|
||||||
|
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
|
||||||
|
import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
|
||||||
|
import { resetSession, useSession } from '../../../stores/session';
|
||||||
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
||||||
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
||||||
|
import { Menu } from '../../tools/session/components/Menu';
|
||||||
|
|
||||||
const REFRESH_RATE = 1 / 5;
|
const REFRESH_RATE = 1 / 5;
|
||||||
|
|
||||||
@@ -71,7 +76,7 @@ export default function SessionPage() {
|
|||||||
async function recalculateDiff() {
|
async function recalculateDiff() {
|
||||||
if (session.isTracking) {
|
if (session.isTracking) {
|
||||||
const { id, region } = session;
|
const { id, region } = session;
|
||||||
const careerRaw = await getWargamingResponse<TanksStats>(
|
const careerRaw = await fetchBlitz<TanksStats>(
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
const career = careerRaw[id].reduce<
|
const career = careerRaw[id].reduce<
|
||||||
@@ -109,7 +114,7 @@ export default function SessionPage() {
|
|||||||
|
|
||||||
list: (
|
list: (
|
||||||
Object.values(
|
Object.values(
|
||||||
diffNormalizedTankStats(session.tankStats, career),
|
deltaTankStats(session.tankStats, career),
|
||||||
) as IndividualTankStats[]
|
) as IndividualTankStats[]
|
||||||
).map((stats) => {
|
).map((stats) => {
|
||||||
return {
|
return {
|
||||||
@@ -193,118 +198,128 @@ export default function SessionPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Breakdown.Root>
|
<ContextMenu.Root>
|
||||||
{session.showTotal &&
|
<ContextMenu.Trigger>
|
||||||
session.isTracking &&
|
<div>
|
||||||
since !== undefined &&
|
<Breakdown.Root>
|
||||||
diff !== undefined && (
|
{session.showTotal &&
|
||||||
<Breakdown.Row
|
session.isTracking &&
|
||||||
minimized={!session.showCareer}
|
since !== undefined &&
|
||||||
title={`Since ${since.toLocaleString(undefined, {
|
diff !== undefined && (
|
||||||
hour: 'numeric',
|
<Breakdown.Row
|
||||||
minute: 'numeric',
|
color={session.color}
|
||||||
hour12: true,
|
minimized={!session.showCareer}
|
||||||
month: 'short',
|
title={session.title}
|
||||||
year: 'numeric',
|
stats={session.customColumns.map((customColumn) => {
|
||||||
day: 'numeric',
|
const rowStat = totalRowStats[customColumn.display];
|
||||||
})}`}
|
|
||||||
stats={session.customColumns.map((customColumn) => {
|
|
||||||
const rowStat = totalRowStats[customColumn.display];
|
|
||||||
|
|
||||||
if (!rowStat) return undefined;
|
if (!rowStat) return undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...rowStat,
|
...rowStat,
|
||||||
delta:
|
delta:
|
||||||
customColumn.showDelta && rowStat.percentile === undefined
|
customColumn.showDelta &&
|
||||||
? rowStat.delta
|
rowStat.percentile === undefined
|
||||||
: undefined,
|
? rowStat.delta
|
||||||
};
|
: undefined,
|
||||||
})}
|
};
|
||||||
/>
|
})}
|
||||||
)}
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{diff?.list
|
{diff?.list
|
||||||
.sort((a, b) => b.stats.last_battle_time - a.stats.last_battle_time)
|
.sort(
|
||||||
.map(({ stats, tankopedia, career, careerWN8, currentWN8 }) => {
|
(a, b) => b.stats.last_battle_time - a.stats.last_battle_time,
|
||||||
const rowStats: Record<
|
)
|
||||||
CustomColumnDisplay,
|
.map(({ stats, tankopedia, career, careerWN8, currentWN8 }) => {
|
||||||
Breakdown.RowStatItem | undefined
|
const rowStats: Record<
|
||||||
> = {
|
CustomColumnDisplay,
|
||||||
battles: {
|
Breakdown.RowStatItem | undefined
|
||||||
title: 'Battles',
|
> = {
|
||||||
current: stats.all.battles.toLocaleString(),
|
battles: {
|
||||||
career: career.all.battles.toLocaleString(),
|
title: 'Battles',
|
||||||
},
|
current: stats.all.battles.toLocaleString(),
|
||||||
winrate: {
|
career: career.all.battles.toLocaleString(),
|
||||||
title: 'Winrate',
|
},
|
||||||
current: `${(100 * (stats.all.wins / stats.all.battles)).toFixed(
|
winrate: {
|
||||||
2,
|
title: 'Winrate',
|
||||||
)}%`,
|
current: `${(
|
||||||
career: `${(100 * (career.all.wins / career.all.battles)).toFixed(
|
100 *
|
||||||
2,
|
(stats.all.wins / stats.all.battles)
|
||||||
)}%`,
|
).toFixed(2)}%`,
|
||||||
delta:
|
career: `${(
|
||||||
stats.all.wins / stats.all.battles -
|
100 *
|
||||||
career.all.wins / career.all.battles,
|
(career.all.wins / career.all.battles)
|
||||||
},
|
).toFixed(2)}%`,
|
||||||
wn8: {
|
delta:
|
||||||
title: 'WN8',
|
stats.all.wins / stats.all.battles -
|
||||||
current:
|
career.all.wins / career.all.battles,
|
||||||
currentWN8 === undefined
|
},
|
||||||
? undefined
|
wn8: {
|
||||||
: Math.round(currentWN8).toLocaleString(),
|
title: 'WN8',
|
||||||
career:
|
current:
|
||||||
careerWN8 === undefined
|
currentWN8 === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: Math.round(careerWN8).toLocaleString(),
|
: Math.round(currentWN8).toLocaleString(),
|
||||||
percentile:
|
career:
|
||||||
currentWN8 === undefined
|
careerWN8 === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: getWN8Percentile(currentWN8),
|
: Math.round(careerWN8).toLocaleString(),
|
||||||
},
|
percentile:
|
||||||
damage: {
|
currentWN8 === undefined
|
||||||
title: 'Damage',
|
? undefined
|
||||||
current: Math.round(
|
: getWN8Percentile(currentWN8),
|
||||||
stats.all.damage_dealt / stats.all.battles,
|
},
|
||||||
).toLocaleString(),
|
damage: {
|
||||||
career: Math.round(
|
title: 'Damage',
|
||||||
career.all.damage_dealt / career.all.battles,
|
current: Math.round(
|
||||||
).toLocaleString(),
|
stats.all.damage_dealt / stats.all.battles,
|
||||||
delta:
|
).toLocaleString(),
|
||||||
stats.all.damage_dealt / stats.all.battles -
|
career: Math.round(
|
||||||
career.all.damage_dealt / career.all.battles,
|
career.all.damage_dealt / career.all.battles,
|
||||||
},
|
).toLocaleString(),
|
||||||
none: undefined,
|
delta:
|
||||||
};
|
stats.all.damage_dealt / stats.all.battles -
|
||||||
|
career.all.damage_dealt / career.all.battles,
|
||||||
return (
|
},
|
||||||
<Breakdown.Row
|
none: undefined,
|
||||||
key={stats.tank_id}
|
|
||||||
minimized={!session.showCareer}
|
|
||||||
title={tankopedia?.name ?? `Unknown tank ${stats.tank_id}`}
|
|
||||||
type="tank"
|
|
||||||
tankType={tankopedia?.type}
|
|
||||||
treeType={(() => {
|
|
||||||
if (tankopedia?.is_collectible) return TreeTypeEnum.Collector;
|
|
||||||
if (tankopedia?.is_premium) return TreeTypeEnum.Premium;
|
|
||||||
})()}
|
|
||||||
stats={session.customColumns.map((customColumn) => {
|
|
||||||
const rowStat = rowStats[customColumn.display];
|
|
||||||
|
|
||||||
if (!rowStat) return undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...rowStat,
|
|
||||||
delta:
|
|
||||||
customColumn.showDelta && rowStat.percentile === undefined
|
|
||||||
? rowStat.delta
|
|
||||||
: undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Breakdown.Row
|
||||||
|
color={session.color}
|
||||||
|
key={stats.tank_id}
|
||||||
|
minimized={!session.showCareer}
|
||||||
|
title={tankopedia?.name ?? `Unknown tank ${stats.tank_id}`}
|
||||||
|
type="tank"
|
||||||
|
tankType={tankopedia?.type}
|
||||||
|
treeType={(() => {
|
||||||
|
if (tankopedia?.is_collectible)
|
||||||
|
return TreeTypeEnum.Collector;
|
||||||
|
if (tankopedia?.is_premium) return TreeTypeEnum.Premium;
|
||||||
|
})()}
|
||||||
|
stats={session.customColumns.map((customColumn) => {
|
||||||
|
const rowStat = rowStats[customColumn.display];
|
||||||
|
|
||||||
|
if (!rowStat) return undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...rowStat,
|
||||||
|
delta:
|
||||||
|
customColumn.showDelta &&
|
||||||
|
rowStat.percentile === undefined
|
||||||
|
? rowStat.delta
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
/>
|
</Breakdown.Root>
|
||||||
);
|
</div>
|
||||||
})}
|
</ContextMenu.Trigger>
|
||||||
</Breakdown.Root>
|
|
||||||
|
<Menu reset={resetSession} Builder={ContextMenu} />
|
||||||
|
</ContextMenu.Root>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -41,12 +41,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
|||||||
: 'url(https://i.imgur.com/PhS06NJ.png)',
|
: 'url(https://i.imgur.com/PhS06NJ.png)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Theme
|
<Theme appearance="dark" panelBackground="translucent" radius="full">
|
||||||
appearance="dark"
|
|
||||||
panelBackground="translucent"
|
|
||||||
radius="full"
|
|
||||||
accentColor="blue"
|
|
||||||
>
|
|
||||||
{!isEmbed && <Navbar />}
|
{!isEmbed && <Navbar />}
|
||||||
|
|
||||||
<Flex direction="column">{children}</Flex>
|
<Flex direction="column">{children}</Flex>
|
||||||
|
|||||||
@@ -19,17 +19,32 @@ export default function ToolsLayout({ children }: ToolsLayoutProps) {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
height: 128,
|
height: 128,
|
||||||
backgroundImage: `url(/assets/banners/${toolId}.png)`,
|
|
||||||
backgroundSize: 'cover',
|
|
||||||
backgroundPosition: 'center',
|
|
||||||
boxShadow: `inset 0 -192px 128px -128px ${theme.colors.appBackground1}`,
|
boxShadow: `inset 0 -192px 128px -128px ${theme.colors.appBackground1}`,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
gap: 4,
|
gap: 4,
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
|
position: 'relative',
|
||||||
|
overflow: 'hidden',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
backgroundImage: `url(/assets/banners/${toolId}.webp)`,
|
||||||
|
backgroundSize: 'cover',
|
||||||
|
backgroundPosition: 'center',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
zIndex: -1,
|
||||||
|
filter: 'blur(4px)',
|
||||||
|
transform: 'scale(calc((128 + 8) / 128))',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: theme.colors.textHighContrast,
|
color: theme.colors.textHighContrast,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { keyframes, style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
|
const spinKeyframes = keyframes({
|
||||||
|
from: { transform: 'rotate(0deg)' },
|
||||||
|
to: { transform: 'rotate(360deg)' },
|
||||||
|
});
|
||||||
|
|
||||||
|
export const infiniteSpin = style({
|
||||||
|
animationName: spinKeyframes,
|
||||||
|
animationIterationCount: 'infinite',
|
||||||
|
animationTimingFunction: 'linear',
|
||||||
|
animationDuration: '1s',
|
||||||
|
});
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import {
|
||||||
|
CaretLeftIcon,
|
||||||
|
CaretRightIcon,
|
||||||
|
SymbolIcon,
|
||||||
|
} from '@radix-ui/react-icons';
|
||||||
|
import { Button, Flex, TextField } from '@radix-ui/themes';
|
||||||
|
import { range } from 'lodash';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { infiniteSpin } from './index.css';
|
||||||
|
|
||||||
|
interface PageTurnerProps {
|
||||||
|
leaderboard: Record<number, number>;
|
||||||
|
page: number;
|
||||||
|
rowsPerPage: number;
|
||||||
|
pages: number;
|
||||||
|
onPageChange: (page: number, isButtonClick: boolean) => void;
|
||||||
|
totalPlayers: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageTurner({
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
onPageChange,
|
||||||
|
pages,
|
||||||
|
leaderboard,
|
||||||
|
totalPlayers,
|
||||||
|
}: PageTurnerProps) {
|
||||||
|
const pageInput = useRef<HTMLInputElement>(null);
|
||||||
|
const rightLoading = range(
|
||||||
|
page * rowsPerPage,
|
||||||
|
Math.min(totalPlayers - 1, page * rowsPerPage + rowsPerPage + 1),
|
||||||
|
).some((index) => !(index in leaderboard));
|
||||||
|
const leftLoading = range(
|
||||||
|
Math.max(0, page * rowsPerPage - 1),
|
||||||
|
Math.max(0, page * rowsPerPage - rowsPerPage - 1) + 1,
|
||||||
|
).some((index) => !(index in leaderboard));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (pageInput.current) pageInput.current.value = `${page + 1}`;
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex justify="center" wrap="wrap" gap="2">
|
||||||
|
<Flex gap="2">
|
||||||
|
<Button
|
||||||
|
variant="soft"
|
||||||
|
onClick={() => onPageChange(Math.max(page - 1, 0), true)}
|
||||||
|
disabled={page === 0 || leftLoading}
|
||||||
|
>
|
||||||
|
{leftLoading ? (
|
||||||
|
<SymbolIcon className={infiniteSpin} />
|
||||||
|
) : (
|
||||||
|
<CaretLeftIcon />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<TextField.Root>
|
||||||
|
<TextField.Slot>Page</TextField.Slot>
|
||||||
|
<TextField.Input
|
||||||
|
type="number"
|
||||||
|
ref={pageInput}
|
||||||
|
style={{ width: 64, textAlign: 'center' }}
|
||||||
|
onBlur={(event) => {
|
||||||
|
onPageChange(
|
||||||
|
Math.max(
|
||||||
|
0,
|
||||||
|
Math.min(pages - 1, event.target.valueAsNumber - 1),
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
(event.target as HTMLInputElement).blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>out of {pages}</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
<Button
|
||||||
|
variant="soft"
|
||||||
|
onClick={() => {
|
||||||
|
onPageChange(Math.min(page + 1, pages - 1), true);
|
||||||
|
}}
|
||||||
|
disabled={page === pages - 1 || rightLoading}
|
||||||
|
>
|
||||||
|
{rightLoading ? (
|
||||||
|
<SymbolIcon className={infiniteSpin} />
|
||||||
|
) : (
|
||||||
|
<CaretRightIcon />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DropdownMenu } from '@radix-ui/themes';
|
import { ContextMenu, DropdownMenu } from '@radix-ui/themes';
|
||||||
import mutateSession, { useSession } from '../../../../stores/session';
|
import mutateSession, { useSession } from '../../../../stores/session';
|
||||||
|
|
||||||
export type CustomColumnDisplay =
|
export type CustomColumnDisplay =
|
||||||
@@ -11,20 +11,19 @@ export type CustomColumnDisplay =
|
|||||||
const NO_DELTA: CustomColumnDisplay[] = ['battles', 'wn8', 'none'];
|
const NO_DELTA: CustomColumnDisplay[] = ['battles', 'wn8', 'none'];
|
||||||
|
|
||||||
interface CustomColumn {
|
interface CustomColumn {
|
||||||
|
Builder: typeof DropdownMenu | typeof ContextMenu;
|
||||||
column: number;
|
column: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CustomColumn({ column }: CustomColumn) {
|
export function CustomColumn({ column, Builder }: CustomColumn) {
|
||||||
const customColumn = useSession((state) => state.customColumns[column]);
|
const customColumn = useSession((state) => state.customColumns[column]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu.Sub>
|
<Builder.Sub>
|
||||||
<DropdownMenu.SubTrigger>Column {column + 1}</DropdownMenu.SubTrigger>
|
<Builder.SubTrigger>Column {column + 1}</Builder.SubTrigger>
|
||||||
|
|
||||||
<DropdownMenu.SubContent>
|
<Builder.SubContent>
|
||||||
<DropdownMenu.Label>Display</DropdownMenu.Label>
|
<Builder.RadioGroup
|
||||||
|
|
||||||
<DropdownMenu.RadioGroup
|
|
||||||
value={customColumn.display}
|
value={customColumn.display}
|
||||||
onValueChange={(event) =>
|
onValueChange={(event) =>
|
||||||
mutateSession((draft) => {
|
mutateSession((draft) => {
|
||||||
@@ -33,22 +32,18 @@ export function CustomColumn({ column }: CustomColumn) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DropdownMenu.RadioItem value="battles">
|
<Builder.RadioItem value="battles">Battles</Builder.RadioItem>
|
||||||
Battles
|
<Builder.RadioItem value="winrate">Winrate</Builder.RadioItem>
|
||||||
</DropdownMenu.RadioItem>
|
<Builder.RadioItem value="wn8">WN8</Builder.RadioItem>
|
||||||
<DropdownMenu.RadioItem value="winrate">
|
<Builder.RadioItem value="damage">Damage</Builder.RadioItem>
|
||||||
Winrate
|
<Builder.RadioItem value="none">None</Builder.RadioItem>
|
||||||
</DropdownMenu.RadioItem>
|
</Builder.RadioGroup>
|
||||||
<DropdownMenu.RadioItem value="wn8">WN8</DropdownMenu.RadioItem>
|
|
||||||
<DropdownMenu.RadioItem value="damage">Damage</DropdownMenu.RadioItem>
|
|
||||||
<DropdownMenu.RadioItem value="none">None</DropdownMenu.RadioItem>
|
|
||||||
</DropdownMenu.RadioGroup>
|
|
||||||
|
|
||||||
{!NO_DELTA.includes(customColumn.display) && (
|
{!NO_DELTA.includes(customColumn.display) && (
|
||||||
<>
|
<>
|
||||||
<DropdownMenu.Separator />
|
<Builder.Separator />
|
||||||
|
|
||||||
<DropdownMenu.CheckboxItem
|
<Builder.CheckboxItem
|
||||||
checked={customColumn.showDelta}
|
checked={customColumn.showDelta}
|
||||||
onCheckedChange={(checked) =>
|
onCheckedChange={(checked) =>
|
||||||
mutateSession((draft) => {
|
mutateSession((draft) => {
|
||||||
@@ -57,10 +52,10 @@ export function CustomColumn({ column }: CustomColumn) {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
Show delta
|
Show delta
|
||||||
</DropdownMenu.CheckboxItem>
|
</Builder.CheckboxItem>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</DropdownMenu.SubContent>
|
</Builder.SubContent>
|
||||||
</DropdownMenu.Sub>
|
</Builder.Sub>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
ContextMenu,
|
||||||
|
Dialog,
|
||||||
|
DropdownMenu,
|
||||||
|
Flex,
|
||||||
|
Heading,
|
||||||
|
TextField,
|
||||||
|
} from '@radix-ui/themes';
|
||||||
|
import { createColors } from 'bepaint';
|
||||||
|
import { useRef, useState } from 'react';
|
||||||
|
import {
|
||||||
|
ACCENT_COLORS,
|
||||||
|
AccentColor,
|
||||||
|
GRAY_COLORS,
|
||||||
|
GrayColor,
|
||||||
|
PALETTES,
|
||||||
|
} from '../../../../constants/radixColors';
|
||||||
|
import { useSession } from '../../../../stores/session';
|
||||||
|
import { CustomColumn } from './CustomColumn';
|
||||||
|
|
||||||
|
interface ContextMenuProps {
|
||||||
|
Builder: typeof DropdownMenu | typeof ContextMenu;
|
||||||
|
reset: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Menu({ Builder, reset }: ContextMenuProps) {
|
||||||
|
const session = useSession();
|
||||||
|
const [showTitleEditor, setShowTitleEditor] = useState(false);
|
||||||
|
const titleInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dialog.Root open={showTitleEditor} onOpenChange={setShowTitleEditor}>
|
||||||
|
<Dialog.Content>
|
||||||
|
<Flex direction="column" gap="4">
|
||||||
|
<Heading size="4">Edit title</Heading>
|
||||||
|
|
||||||
|
<Flex gap="2" style={{ width: '100%' }}>
|
||||||
|
<TextField.Root style={{ flex: 1 }}>
|
||||||
|
<TextField.Input
|
||||||
|
ref={titleInput}
|
||||||
|
defaultValue={session.title}
|
||||||
|
placeholder="Enter title..."
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter' && titleInput.current) {
|
||||||
|
setShowTitleEditor(false);
|
||||||
|
useSession.setState({ title: titleInput.current!.value });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</TextField.Root>
|
||||||
|
|
||||||
|
<Dialog.Close>
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
useSession.setState({ title: titleInput.current!.value })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Set
|
||||||
|
</Button>
|
||||||
|
</Dialog.Close>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Root>
|
||||||
|
|
||||||
|
<Builder.Content>
|
||||||
|
<Builder.Sub>
|
||||||
|
<Builder.SubTrigger>Accent color</Builder.SubTrigger>
|
||||||
|
|
||||||
|
<Builder.SubContent>
|
||||||
|
<Builder.RadioGroup
|
||||||
|
value={session.color}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
useSession.setState({ color: value as AccentColor | GrayColor })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{[...ACCENT_COLORS, ...GRAY_COLORS].map((color) => (
|
||||||
|
<Builder.RadioItem value={color} key={color}>
|
||||||
|
<Flex gap="2" align="center">
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: createColors(PALETTES[color])
|
||||||
|
.solidBackground,
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
borderRadius: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{`${color.charAt(0).toUpperCase()}${color.slice(1)}`}
|
||||||
|
</Flex>
|
||||||
|
</Builder.RadioItem>
|
||||||
|
))}
|
||||||
|
</Builder.RadioGroup>
|
||||||
|
</Builder.SubContent>
|
||||||
|
</Builder.Sub>
|
||||||
|
|
||||||
|
<Builder.Separator />
|
||||||
|
|
||||||
|
<Builder.Item onClick={() => setShowTitleEditor(true)}>
|
||||||
|
Edit title...
|
||||||
|
</Builder.Item>
|
||||||
|
<CustomColumn Builder={Builder} column={0} />
|
||||||
|
<CustomColumn Builder={Builder} column={1} />
|
||||||
|
<CustomColumn Builder={Builder} column={2} />
|
||||||
|
<CustomColumn Builder={Builder} column={3} />
|
||||||
|
|
||||||
|
<Builder.Separator />
|
||||||
|
|
||||||
|
<Builder.CheckboxItem
|
||||||
|
checked={session.showTotal}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({ showTotal: checked })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Show total
|
||||||
|
</Builder.CheckboxItem>
|
||||||
|
<Builder.CheckboxItem
|
||||||
|
checked={session.showCareer}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({ showCareer: checked })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Show career
|
||||||
|
</Builder.CheckboxItem>
|
||||||
|
|
||||||
|
<Builder.Separator />
|
||||||
|
|
||||||
|
<Builder.Item color="red" onClick={reset}>
|
||||||
|
Reset
|
||||||
|
</Builder.Item>
|
||||||
|
</Builder.Content>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,21 +14,17 @@ import {
|
|||||||
Flex,
|
Flex,
|
||||||
Text,
|
Text,
|
||||||
TextField,
|
TextField,
|
||||||
Tooltip,
|
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { ChangeEvent, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { REGION_NAMES, Region } from '../../../constants/regions';
|
import { REGION_NAMES } from '../../../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
import searchPlayersAcrossRegions, {
|
||||||
import getWargamingResponse from '../../../core/blitz/getWargamingResponse';
|
|
||||||
import listPlayers, {
|
|
||||||
AccountListWithServer,
|
AccountListWithServer,
|
||||||
} from '../../../core/blitz/listPlayers';
|
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
||||||
import { useSession } from '../../../stores/session';
|
import { resetSession, setSession, useSession } from '../../../stores/session';
|
||||||
import { NormalizedTankStats, TanksStats } from '../../../types/tanksStats';
|
|
||||||
import SessionPage from '../../embeds/session/page';
|
import SessionPage from '../../embeds/session/page';
|
||||||
import { CustomColumn } from './components/CustomColumn';
|
import { Menu } from './components/Menu';
|
||||||
import * as styles from './page.css';
|
import * as styles from './page.css';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
@@ -40,7 +36,7 @@ export default function Page() {
|
|||||||
const handleChange = debounce(
|
const handleChange = debounce(
|
||||||
async (event: ChangeEvent<HTMLInputElement>) => {
|
async (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
if (event.target.value) {
|
if (event.target.value) {
|
||||||
setSearchResults(await listPlayers(event.target.value));
|
setSearchResults(await searchPlayersAcrossRegions(event.target.value));
|
||||||
} else {
|
} else {
|
||||||
setSearchResults(undefined);
|
setSearchResults(undefined);
|
||||||
setShowSearchResults(false);
|
setShowSearchResults(false);
|
||||||
@@ -50,40 +46,12 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
|
||||||
async function setSession(region: Region, id: number, nickname: string) {
|
useEffect(() => {
|
||||||
input.current!.value = nickname;
|
if (session.isTracking) input.current!.value = session.nickname;
|
||||||
|
}, [session]);
|
||||||
const rawTankStats = (
|
|
||||||
await getWargamingResponse<TanksStats>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
)
|
|
||||||
)[id];
|
|
||||||
const tankStats = rawTankStats.reduce<NormalizedTankStats>(
|
|
||||||
(accumulator, tank) => ({
|
|
||||||
...accumulator,
|
|
||||||
[tank.tank_id]: tank,
|
|
||||||
}),
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
useSession.setState({
|
|
||||||
isTracking: true,
|
|
||||||
id,
|
|
||||||
region,
|
|
||||||
nickname,
|
|
||||||
tankStats,
|
|
||||||
time: Date.now(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
|
||||||
const session = useSession.getState();
|
|
||||||
if (!session.isTracking) return;
|
|
||||||
setSession(session.region, session.id, session.nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper>
|
<PageWrapper color="blue">
|
||||||
<div className={styles.toolBar}>
|
<div className={styles.toolBar}>
|
||||||
<div style={{ flex: 1, boxSizing: 'border-box', position: 'relative' }}>
|
<div style={{ flex: 1, boxSizing: 'border-box', position: 'relative' }}>
|
||||||
<TextField.Root>
|
<TextField.Root>
|
||||||
@@ -156,9 +124,9 @@ export default function Page() {
|
|||||||
<Button
|
<Button
|
||||||
variant="soft"
|
variant="soft"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
if (!session.promptBeforeReset) {
|
if (!session.resetPrompt) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
reset();
|
resetSession();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className={styles.toolbarButton}
|
className={styles.toolbarButton}
|
||||||
@@ -185,7 +153,7 @@ export default function Page() {
|
|||||||
mr="1"
|
mr="1"
|
||||||
onCheckedChange={(checked) =>
|
onCheckedChange={(checked) =>
|
||||||
useSession.setState({
|
useSession.setState({
|
||||||
promptBeforeReset: !checked,
|
resetPrompt: !checked,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -201,7 +169,7 @@ export default function Page() {
|
|||||||
</AlertDialog.Cancel>
|
</AlertDialog.Cancel>
|
||||||
|
|
||||||
<AlertDialog.Action>
|
<AlertDialog.Action>
|
||||||
<Button variant="solid" color="red" onClick={reset}>
|
<Button variant="solid" color="red" onClick={resetSession}>
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
</AlertDialog.Action>
|
</AlertDialog.Action>
|
||||||
@@ -209,19 +177,63 @@ export default function Page() {
|
|||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
|
|
||||||
<Tooltip content="Copy to clipboard">
|
<AlertDialog.Root>
|
||||||
<Button
|
<AlertDialog.Trigger>
|
||||||
variant="soft"
|
<Button
|
||||||
className={styles.toolbarButton}
|
variant="soft"
|
||||||
onClick={() =>
|
className={styles.toolbarButton}
|
||||||
navigator.clipboard.writeText(
|
onClick={(event) => {
|
||||||
`${location.origin}/embeds/session`,
|
if (!session.embedPrompt) {
|
||||||
)
|
event.preventDefault();
|
||||||
}
|
resetSession();
|
||||||
>
|
}
|
||||||
<CopyIcon width="16" height="16" /> Embed
|
|
||||||
</Button>
|
navigator.clipboard.writeText(
|
||||||
</Tooltip>
|
`${location.origin}/embeds/session`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CopyIcon width="16" height="16" /> Embed
|
||||||
|
</Button>
|
||||||
|
</AlertDialog.Trigger>
|
||||||
|
|
||||||
|
<AlertDialog.Content>
|
||||||
|
<AlertDialog.Title>
|
||||||
|
Copied link to your clipboard
|
||||||
|
</AlertDialog.Title>
|
||||||
|
<AlertDialog.Description>
|
||||||
|
Instructions for streamers:
|
||||||
|
<iframe
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
aspectRatio: '16 / 9',
|
||||||
|
border: 'none',
|
||||||
|
}}
|
||||||
|
src="https://www.youtube-nocookie.com/embed/e--GwjyrJAE?si=ftEiCmpbMI2FUY5N"
|
||||||
|
title="YouTube video player"
|
||||||
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||||
|
></iframe>
|
||||||
|
</AlertDialog.Description>
|
||||||
|
|
||||||
|
<Text size="2">
|
||||||
|
<Checkbox
|
||||||
|
mr="1"
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({
|
||||||
|
embedPrompt: !checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
Don't show this again
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<Flex gap="3" mt="4">
|
||||||
|
<AlertDialog.Cancel>
|
||||||
|
<Button variant="soft">Got it!</Button>
|
||||||
|
</AlertDialog.Cancel>
|
||||||
|
</Flex>
|
||||||
|
</AlertDialog.Content>
|
||||||
|
</AlertDialog.Root>
|
||||||
|
|
||||||
<DropdownMenu.Root>
|
<DropdownMenu.Root>
|
||||||
<DropdownMenu.Trigger>
|
<DropdownMenu.Trigger>
|
||||||
@@ -231,31 +243,7 @@ export default function Page() {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
|
|
||||||
<DropdownMenu.Content>
|
<Menu Builder={DropdownMenu} reset={resetSession} />
|
||||||
<CustomColumn column={0} />
|
|
||||||
<CustomColumn column={1} />
|
|
||||||
<CustomColumn column={2} />
|
|
||||||
<CustomColumn column={3} />
|
|
||||||
|
|
||||||
<DropdownMenu.Separator />
|
|
||||||
|
|
||||||
<DropdownMenu.CheckboxItem
|
|
||||||
checked={session.showTotal}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
useSession.setState({ showTotal: checked })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Show total
|
|
||||||
</DropdownMenu.CheckboxItem>
|
|
||||||
<DropdownMenu.CheckboxItem
|
|
||||||
checked={session.showCareer}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
useSession.setState({ showCareer: checked })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Show career
|
|
||||||
</DropdownMenu.CheckboxItem>
|
|
||||||
</DropdownMenu.Content>
|
|
||||||
</DropdownMenu.Root>
|
</DropdownMenu.Root>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import { registerProcesses } from './core/blitzkrieg/processes';
|
||||||
|
import { secrets } from './core/blitzkrieg/secrets';
|
||||||
import { client } from './core/discord/client';
|
import { client } from './core/discord/client';
|
||||||
import { secrets } from './core/node/secrets';
|
|
||||||
import { registerErrorHandlers } from './events/error';
|
|
||||||
|
|
||||||
registerErrorHandlers();
|
// console.log(`🟡 Launching bot ${client.shard?.ids[0]}`);
|
||||||
|
|
||||||
|
registerProcesses();
|
||||||
client.login(secrets.DISCORD_TOKEN);
|
client.login(secrets.DISCORD_TOKEN);
|
||||||
@@ -11,6 +11,7 @@ const DOCS = {
|
|||||||
introduction: 'guide/introduction',
|
introduction: 'guide/introduction',
|
||||||
invite: 'guide/invite',
|
invite: 'guide/invite',
|
||||||
timezones: 'guide/timezones',
|
timezones: 'guide/timezones',
|
||||||
|
creators: 'guide/creators',
|
||||||
};
|
};
|
||||||
const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
|
const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
|
||||||
permissions: 'The permissions needed for the bot to function',
|
permissions: 'The permissions needed for the bot to function',
|
||||||
@@ -18,6 +19,7 @@ const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
|
|||||||
introduction: 'About the bot',
|
introduction: 'About the bot',
|
||||||
invite: 'How to invite the bot',
|
invite: 'How to invite the bot',
|
||||||
timezones: 'How Blitzkrieg infers and uses your timezone',
|
timezones: 'How Blitzkrieg infers and uses your timezone',
|
||||||
|
creators: 'Who created the bot',
|
||||||
};
|
};
|
||||||
|
|
||||||
function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
|
function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
|
||||||
@@ -51,6 +53,7 @@ export const aboutCommand: CommandRegistry = {
|
|||||||
await Promise.all(COMMANDS_RAW)
|
await Promise.all(COMMANDS_RAW)
|
||||||
)
|
)
|
||||||
.filter((registry) => registry.inPublic && registry.inProduction)
|
.filter((registry) => registry.inPublic && registry.inProduction)
|
||||||
|
.sort((a, b) => (a.command.name < b.command.name ? -1 : 1))
|
||||||
.map(
|
.map(
|
||||||
(registry) =>
|
(registry) =>
|
||||||
`- \`/${registry.command.name}\`: ${registry.command.description}`,
|
`- \`/${registry.command.name}\`: ${registry.command.description}`,
|
||||||
|
|||||||
@@ -0,0 +1,340 @@
|
|||||||
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { chunk } from 'lodash';
|
||||||
|
import * as Breakdown from '../components/Breakdown';
|
||||||
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
|
import TitleBar from '../components/TitleBar';
|
||||||
|
import Wrapper from '../components/Wrapper';
|
||||||
|
import { AllStats, getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import getTankStats from '../core/blitz/getTankStats';
|
||||||
|
import getTreeType from '../core/blitz/getTreeType';
|
||||||
|
import resolveTankName from '../core/blitz/resolveTankName';
|
||||||
|
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
|
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||||
|
import { tankopedia } from '../core/blitzstars/tankopedia';
|
||||||
|
import addFilterOptions from '../core/discord/addFilterOptions';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import buttonPrimary from '../core/discord/buttonPrimary';
|
||||||
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
|
import resolvePeriodFromCommand, {
|
||||||
|
ResolvedPeriod,
|
||||||
|
} from '../core/discord/resolvePeriodFromCommand';
|
||||||
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||||
|
import resolvePlayerFromCommand, {
|
||||||
|
ResolvedPlayer,
|
||||||
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import calculateWN8 from '../core/statistics/calculateWN8';
|
||||||
|
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
||||||
|
import getWN8Percentile from '../core/statistics/getWN8Percentile';
|
||||||
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
|
|
||||||
|
const ROWS_PER_PAGE = 8;
|
||||||
|
const MAX_PAGES = 10;
|
||||||
|
|
||||||
|
async function render(
|
||||||
|
{ region, id }: ResolvedPlayer,
|
||||||
|
{ start, end, name }: ResolvedPeriod,
|
||||||
|
filters: StatFilters,
|
||||||
|
) {
|
||||||
|
const awaitedTankopedia = await tankopedia;
|
||||||
|
const awaitedTankAverages = await tankAverages;
|
||||||
|
const statsInPeriod = await getStatsInPeriod(region, id, start, end);
|
||||||
|
const { filteredOrder } = await filterStats(statsInPeriod, filters);
|
||||||
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
|
const clanData = await getClanAccountInfo(region, id, ['clan']);
|
||||||
|
const tankStats = await getTankStats(region, id);
|
||||||
|
const filterDescriptions = await filtersToDescription(filters);
|
||||||
|
const orderedCurrentStats: AllStats[] = [];
|
||||||
|
const orderedCareerStats: AllStats[] = [];
|
||||||
|
const orderedCurrentWN8: (number | undefined)[] = [];
|
||||||
|
const orderedCareerWN8: (number | undefined)[] = [];
|
||||||
|
const orderedCareerWN8Full: (number | undefined)[] = [];
|
||||||
|
|
||||||
|
filteredOrder.forEach((id) => {
|
||||||
|
const tankAveragesEntry = awaitedTankAverages[id];
|
||||||
|
const current = statsInPeriod.diff[id];
|
||||||
|
const career = tankStats.find((tank) => tank.tank_id === id)!.all;
|
||||||
|
const currentWN8 = tankAveragesEntry
|
||||||
|
? calculateWN8(tankAveragesEntry.all, current)
|
||||||
|
: undefined;
|
||||||
|
const careerWN8 = tankAveragesEntry
|
||||||
|
? calculateWN8(tankAveragesEntry.all, career)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
orderedCurrentStats.push(current);
|
||||||
|
orderedCareerStats.push(career);
|
||||||
|
orderedCurrentWN8.push(currentWN8);
|
||||||
|
orderedCareerWN8.push(careerWN8);
|
||||||
|
});
|
||||||
|
tankStats.forEach((tank) => {
|
||||||
|
const tankAveragesEntry = awaitedTankAverages[tank.tank_id];
|
||||||
|
|
||||||
|
orderedCareerWN8Full.push(
|
||||||
|
tankAveragesEntry
|
||||||
|
? calculateWN8(tankAveragesEntry.all, tank.all)
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentBattles = orderedCurrentStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.battles,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const careerBattles = tankStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.all.battles,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const currentWinrate =
|
||||||
|
orderedCurrentStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.wins,
|
||||||
|
0,
|
||||||
|
) / currentBattles;
|
||||||
|
const careerWinrate =
|
||||||
|
tankStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.all.wins,
|
||||||
|
0,
|
||||||
|
) / careerBattles;
|
||||||
|
const currentWN8 =
|
||||||
|
orderedCurrentWN8.reduce<number>(
|
||||||
|
(accumulator, current, index) =>
|
||||||
|
accumulator + (current ?? 0) * orderedCurrentStats[index].battles,
|
||||||
|
0,
|
||||||
|
) /
|
||||||
|
orderedCurrentStats.reduce(
|
||||||
|
(accumulator, current, index) =>
|
||||||
|
accumulator +
|
||||||
|
(orderedCurrentWN8[index] === undefined ? 0 : current.battles),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const careerWN8 =
|
||||||
|
orderedCareerWN8Full.reduce<number>(
|
||||||
|
(accumulator, current) => accumulator + (current ?? 0),
|
||||||
|
0,
|
||||||
|
) /
|
||||||
|
tankStats.reduce(
|
||||||
|
(accumulator, current, index) =>
|
||||||
|
accumulator +
|
||||||
|
(orderedCareerWN8Full[index] === undefined ? 0 : current.all.battles),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const currentDamage =
|
||||||
|
orderedCurrentStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.damage_dealt,
|
||||||
|
0,
|
||||||
|
) / currentBattles;
|
||||||
|
const careerDamage =
|
||||||
|
tankStats.reduce(
|
||||||
|
(accumulator, current) => accumulator + current.all.damage_dealt,
|
||||||
|
0,
|
||||||
|
) / careerBattles;
|
||||||
|
|
||||||
|
const children: JSX.Element[] = [];
|
||||||
|
|
||||||
|
if (filteredOrder.length > 0) {
|
||||||
|
children.push(
|
||||||
|
<Breakdown.Row
|
||||||
|
key={id}
|
||||||
|
type="summary"
|
||||||
|
title="Total"
|
||||||
|
stats={[
|
||||||
|
{
|
||||||
|
title: 'Battles',
|
||||||
|
current: currentBattles,
|
||||||
|
career: careerBattles,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Winrate',
|
||||||
|
current: `${(100 * currentWinrate).toFixed(2)}%`,
|
||||||
|
career: `${(100 * careerWinrate).toFixed(2)}%`,
|
||||||
|
delta: currentWinrate - careerWinrate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'WN8',
|
||||||
|
current:
|
||||||
|
currentWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: Math.round(currentWN8).toLocaleString(),
|
||||||
|
career:
|
||||||
|
careerWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: Math.round(careerWN8).toLocaleString(),
|
||||||
|
percentile:
|
||||||
|
currentWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: getWN8Percentile(currentWN8),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Damage',
|
||||||
|
current: Math.round(currentDamage).toLocaleString(),
|
||||||
|
career: Math.round(careerDamage).toLocaleString(),
|
||||||
|
delta: currentDamage - careerDamage,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
filteredOrder.map(async (id, index) => {
|
||||||
|
const tankopediaEntry = awaitedTankopedia[id];
|
||||||
|
const current = orderedCurrentStats[index];
|
||||||
|
const career = orderedCareerStats[index];
|
||||||
|
const currentWN8 = orderedCurrentWN8[index];
|
||||||
|
const careerWN8 = orderedCareerWN8[index];
|
||||||
|
|
||||||
|
children.push(
|
||||||
|
<Breakdown.Row
|
||||||
|
key={id}
|
||||||
|
type="tank"
|
||||||
|
tankType={tankopediaEntry?.type}
|
||||||
|
treeType={tankopediaEntry ? await getTreeType(id) : undefined}
|
||||||
|
title={await resolveTankName(id)}
|
||||||
|
stats={[
|
||||||
|
{
|
||||||
|
title: 'Battles',
|
||||||
|
current: current.battles.toLocaleString(),
|
||||||
|
career: career.battles.toLocaleString(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Winrate',
|
||||||
|
current: `${(100 * (current.wins / current.battles)).toFixed(
|
||||||
|
2,
|
||||||
|
)}%`,
|
||||||
|
career: `${(100 * (career.wins / career.battles)).toFixed(2)}%`,
|
||||||
|
delta:
|
||||||
|
current.wins / current.battles - career.wins / career.battles,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'WN8',
|
||||||
|
current:
|
||||||
|
currentWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: Math.round(currentWN8).toLocaleString(),
|
||||||
|
career:
|
||||||
|
careerWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: Math.round(careerWN8).toLocaleString(),
|
||||||
|
percentile:
|
||||||
|
currentWN8 === undefined
|
||||||
|
? undefined
|
||||||
|
: getWN8Percentile(currentWN8),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Damage',
|
||||||
|
current: Math.round(
|
||||||
|
current.damage_dealt / current.battles,
|
||||||
|
).toLocaleString(),
|
||||||
|
career: Math.round(
|
||||||
|
career.damage_dealt / career.battles,
|
||||||
|
).toLocaleString(),
|
||||||
|
delta:
|
||||||
|
current.damage_dealt / current.battles -
|
||||||
|
career.damage_dealt / career.battles,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pages = chunk(
|
||||||
|
children,
|
||||||
|
Math.max(Math.ceil(children.length / MAX_PAGES), ROWS_PER_PAGE),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (filteredOrder.length > 0) {
|
||||||
|
return pages
|
||||||
|
.map((page, index) => (
|
||||||
|
<Wrapper>
|
||||||
|
{index === 0 && (
|
||||||
|
<TitleBar
|
||||||
|
name={accountInfo.nickname}
|
||||||
|
image={
|
||||||
|
clanData?.clan
|
||||||
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
description={`${name} • ${filterDescriptions}`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Breakdown.Root>{page}</Breakdown.Root>
|
||||||
|
</Wrapper>
|
||||||
|
))
|
||||||
|
.reverse();
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
<Wrapper>
|
||||||
|
<TitleBar
|
||||||
|
name={accountInfo.nickname}
|
||||||
|
image={
|
||||||
|
clanData?.clan
|
||||||
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
description={`${name} • ${filterDescriptions}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{filteredOrder.length === 0 && (
|
||||||
|
<NoData type={NoDataType.BattlesInPeriod} />
|
||||||
|
)}
|
||||||
|
</Wrapper>,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const breakdownCommand = new Promise<CommandRegistryRaw>(
|
||||||
|
async (resolve) => {
|
||||||
|
const command = await addFilterOptions(
|
||||||
|
new SlashCommandBuilder()
|
||||||
|
.setName('breakdown')
|
||||||
|
.setDescription("A period's breakdown by tanks played"),
|
||||||
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
|
);
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
command,
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
|
const path = commandToURL(interaction, {
|
||||||
|
...player,
|
||||||
|
...getCustomPeriodParams(interaction),
|
||||||
|
...filters,
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
...(await render(player, period, filters)),
|
||||||
|
buttonPrimary(path, 'Refresh'),
|
||||||
|
await getBlitzStarsLinkButton(player.region, player.id),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
autocomplete: (interaction) => {
|
||||||
|
autocompleteUsername(interaction);
|
||||||
|
autocompleteTanks(interaction);
|
||||||
|
},
|
||||||
|
|
||||||
|
async button(interaction) {
|
||||||
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
|
return await render(player, period, filters);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -1,97 +1,93 @@
|
|||||||
import { SlashCommandBuilder, escapeMarkdown } from 'discord.js';
|
// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
|
||||||
import markdownEscape from 'markdown-escape';
|
// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
|
||||||
import { PlayerHistoriesRaw } from '../core/blitzstars/getPlayerHistories';
|
// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
|
||||||
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
|
||||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
|
||||||
import embedWarning from '../core/discord/embedWarning';
|
|
||||||
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
import { AccountAchievements } from '../types/accountAchievements';
|
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { ClanInfo } from '../types/clanInfo';
|
|
||||||
|
|
||||||
export const clanEventCommand: CommandRegistry = {
|
// import { SlashCommandBuilder, escapeMarkdown } from 'discord.js';
|
||||||
inProduction: false,
|
// import markdownEscape from 'markdown-escape';
|
||||||
inPublic: true,
|
// import { getAccountAchievements } from '../core/blitz/getAccountAchievements';
|
||||||
|
// import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
// import { getClanInfo } from '../core/blitz/getClanInfo';
|
||||||
|
// import { PlayerHistoriesRaw } from '../LEGACY_core/blitzstars/getPlayerHistories';
|
||||||
|
// import getTimeDaysAgo from '../LEGACY_core/blitzstars/getTimeDaysAgo';
|
||||||
|
// import addClanChoices from '../LEGACY_core/discord/addClanChoices';
|
||||||
|
// import autocompleteClan from '../LEGACY_core/discord/autocompleteClan';
|
||||||
|
// import embedWarning from '../LEGACY_core/discord/embedWarning';
|
||||||
|
// import resolveClanFromCommand from '../LEGACY_core/discord/resolveClanFromCommand';
|
||||||
|
// import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
// export const clanEventCommand: CommandRegistry = {
|
||||||
.setName('clan-event')
|
// inProduction: false,
|
||||||
.setDescription('Lists all inactive players')
|
// inPublic: true,
|
||||||
.addStringOption(addClanChoices),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
// command: new SlashCommandBuilder()
|
||||||
const { region, id } = await resolveClanFromCommand(interaction);
|
// .setName('clan-event')
|
||||||
const clan = (
|
// .setDescription('Lists all inactive players')
|
||||||
await getWargamingResponse<ClanInfo>(
|
// .addStringOption(addClanChoices),
|
||||||
`https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`,
|
|
||||||
)
|
|
||||||
)[id];
|
|
||||||
const memberIds = clan.members_ids.join(',');
|
|
||||||
const [players, achievements, previousJointVictories] = await Promise.all([
|
|
||||||
getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`,
|
|
||||||
),
|
|
||||||
getWargamingResponse<AccountAchievements>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`,
|
|
||||||
),
|
|
||||||
Promise.all(
|
|
||||||
clan.members_ids.map((id) =>
|
|
||||||
fetch(`https://www.blitzstars.com/api/playerstats/${id}`)
|
|
||||||
.then((response) => response.json() as Promise<PlayerHistoriesRaw>)
|
|
||||||
.then((data) => ({
|
|
||||||
id,
|
|
||||||
jointVictory: data[0]?.achievements.jointVictoryCount as
|
|
||||||
| number
|
|
||||||
| undefined,
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
).then((data) =>
|
|
||||||
data.reduce<Record<number, number | undefined>>(
|
|
||||||
(accumulator, value) => ({
|
|
||||||
...accumulator,
|
|
||||||
[value.id]: value.jointVictory,
|
|
||||||
}),
|
|
||||||
{},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
const jointVictories = clan.members_ids.map((id) => ({
|
|
||||||
id,
|
|
||||||
joinVictory:
|
|
||||||
players[id].last_battle_time > getTimeDaysAgo(region, 1)
|
|
||||||
? previousJointVictories[id] === undefined
|
|
||||||
? 0
|
|
||||||
: achievements[id].max_series.jointVictory -
|
|
||||||
previousJointVictories[id]!
|
|
||||||
: 0,
|
|
||||||
}));
|
|
||||||
|
|
||||||
return [
|
// async handler(interaction) {
|
||||||
`# ${escapeMarkdown(clan.name)} [${escapeMarkdown(
|
// const { region, id } = await resolveClanFromCommand(interaction);
|
||||||
clan.tag,
|
// const clan = await getClanInfo(region, id);
|
||||||
)}]'s platoon wins today: ${(
|
// const [players, achievements, previousJointVictories] = await Promise.all([
|
||||||
jointVictories.reduce(
|
// getAccountInfo(region, clan.members_ids),
|
||||||
(accumulator, { joinVictory }) => accumulator + joinVictory,
|
// getAccountAchievements(region, clan.members_ids),
|
||||||
0,
|
// Promise.all(
|
||||||
) / 2
|
// clan.members_ids.map((id) =>
|
||||||
).toFixed(0)}\n${jointVictories
|
// fetch(`https://www.blitzstars.com/api/playerstats/${id}`)
|
||||||
.filter(({ joinVictory }) => joinVictory)
|
// .then((response) => response.json() as Promise<PlayerHistoriesRaw>)
|
||||||
.sort((a, b) => b.joinVictory - a.joinVictory)
|
// .then((data) => ({
|
||||||
.map(
|
// id,
|
||||||
({ id, joinVictory }) =>
|
// jointVictory: data[0]?.achievements.jointVictoryCount as
|
||||||
`- ${markdownEscape(players[id].nickname)}: ${joinVictory}`,
|
// | number
|
||||||
)
|
// | undefined,
|
||||||
.join('\n')}`,
|
// })),
|
||||||
|
// ),
|
||||||
|
// ).then((data) =>
|
||||||
|
// data.reduce<Record<number, number | undefined>>(
|
||||||
|
// (accumulator, value) => ({
|
||||||
|
// ...accumulator,
|
||||||
|
// [value.id]: value.jointVictory,
|
||||||
|
// }),
|
||||||
|
// {},
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ]);
|
||||||
|
// const jointVictories = clan.members_ids.map((id) => ({
|
||||||
|
// id,
|
||||||
|
// joinVictory:
|
||||||
|
// players[id].last_battle_time > getTimeDaysAgo(region, 1)
|
||||||
|
// ? previousJointVictories[id] === undefined
|
||||||
|
// ? 0
|
||||||
|
// : achievements[id].max_series.jointVictory -
|
||||||
|
// previousJointVictories[id]!
|
||||||
|
// : 0,
|
||||||
|
// }));
|
||||||
|
|
||||||
embedWarning(
|
// return [
|
||||||
'This is an approximation!',
|
// `# ${escapeMarkdown(clan.name)} [${escapeMarkdown(
|
||||||
"Wargaming provides very little information about platoons publicly. Caveats:\n- Players in two different clans platooning artificially inflates the total count\n- Game-mode battles aren't counted since Wargaming doesn't publicly share that data\n- This command is also subject to Blitzkrieg's reset times (use `/about timezones` for more info)",
|
// clan.tag,
|
||||||
),
|
// )}]'s platoon wins today: ${(
|
||||||
];
|
// jointVictories.reduce(
|
||||||
},
|
// (accumulator, { joinVictory }) => accumulator + joinVictory,
|
||||||
|
// 0,
|
||||||
|
// ) / 2
|
||||||
|
// ).toFixed(0)}\n${jointVictories
|
||||||
|
// .filter(({ joinVictory }) => joinVictory)
|
||||||
|
// .sort((a, b) => b.joinVictory - a.joinVictory)
|
||||||
|
// .map(
|
||||||
|
// ({ id, joinVictory }) =>
|
||||||
|
// `- ${markdownEscape(players[id].nickname)}: ${joinVictory}`,
|
||||||
|
// )
|
||||||
|
// .join('\n')}`,
|
||||||
|
|
||||||
autocomplete: autocompleteClan,
|
// embedWarning(
|
||||||
};
|
// 'This is an approximation!',
|
||||||
|
// "Wargaming provides very little information about platoons publicly. Caveats:\n- Players in two different clans platooning artificially inflates the total count\n- Game-mode battles aren't counted since Wargaming doesn't publicly share that data\n- This command is also subject to Blitzkrieg's reset times (use `/about timezones` for more info)",
|
||||||
|
// ),
|
||||||
|
// ];
|
||||||
|
// },
|
||||||
|
|
||||||
|
// autocomplete: autocompleteClan,
|
||||||
|
// };
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import packageJSON from '../../package.json' assert { type: 'json' };
|
import packageJSON from '../../package.json' assert { type: 'json' };
|
||||||
import { tankopedia } from '../core/blitz/tankopedia';
|
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
|
||||||
import { client } from '../core/discord/client';
|
import { client } from '../core/discord/client';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
|
||||||
import markdownTable from '../core/discord/markdownTable';
|
|
||||||
import getClientId from '../core/node/getClientId';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|
||||||
const executionStart = new Date().getTime();
|
const executionStart = new Date().getTime();
|
||||||
@@ -21,24 +16,21 @@ export const debugCommand: CommandRegistry = {
|
|||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const uptime = currentTime - executionStart;
|
const uptime = currentTime - executionStart;
|
||||||
|
const list = [
|
||||||
|
['Version', packageJSON.version],
|
||||||
|
['Shard', client.shard?.ids[0] ?? 'default'],
|
||||||
|
[
|
||||||
|
'Uptime',
|
||||||
|
`${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor(
|
||||||
|
(uptime / 1000 / 60) % 60,
|
||||||
|
)}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor(
|
||||||
|
uptime % 1000,
|
||||||
|
)}ms`,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
.map(([key, value]) => `- ${key}: ${value}`)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
return embedInfo(
|
return `# Debug\n\n${list}`;
|
||||||
`${client.user?.username} debug information`,
|
|
||||||
markdownTable([
|
|
||||||
['Version', packageJSON.version],
|
|
||||||
['Client ID', getClientId()],
|
|
||||||
['Tag', interaction.client.user.tag],
|
|
||||||
[
|
|
||||||
'Uptime',
|
|
||||||
`${Math.floor(uptime / 1000 / 60 / 60 / 24)}d ${Math.floor(
|
|
||||||
(uptime / 1000 / 60 / 60) % 24,
|
|
||||||
)}h ${Math.floor((uptime / 1000 / 60) % 60)}m ${Math.floor(
|
|
||||||
(uptime / 1000) % 60,
|
|
||||||
)}s ${Math.floor(uptime % 1000)}ms`,
|
|
||||||
],
|
|
||||||
['Tankopedia cached', `${(await tankopedia) !== undefined}`],
|
|
||||||
['Tank averages cached', `${(await tankAverages) !== undefined}`],
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import calculateWN8 from '../core/blitz/calculateWN8';
|
import getPeriodNow from '../core/blitzkrieg/getPeriodNow';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo';
|
||||||
import sumStats from '../core/blitz/sumStats';
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
import { tankopedia } from '../core/blitz/tankopedia';
|
|
||||||
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
|
||||||
import getPeriodNow from '../core/blitzstars/getPeriodNow';
|
|
||||||
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||||
|
import { tankopedia } from '../core/blitzstars/tankopedia';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import embedNegative from '../core/discord/embedNegative';
|
import embedNegative from '../core/discord/embedNegative';
|
||||||
import embedPositive from '../core/discord/embedPositive';
|
import embedPositive from '../core/discord/embedPositive';
|
||||||
import markdownTable, { TableInput } from '../core/discord/markdownTable';
|
import markdownTable, { TableInput } from '../core/discord/markdownTable';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import calculateWN8 from '../core/statistics/calculateWN8';
|
||||||
|
import sumStats from '../core/statistics/sumStats';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||||
|
|
||||||
export type SkilledClan = 'SKLLD' | 'SMRI';
|
export type SkilledClan = 'SKLLD' | 'SMRI';
|
||||||
@@ -48,20 +46,18 @@ export const eligibleCommand: CommandRegistry = {
|
|||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const clan = interaction.options.getString('clan') as SkilledClan;
|
const clan = interaction.options.getString('clan') as SkilledClan;
|
||||||
const { id, region: server } = await resolvePlayerFromCommand(interaction);
|
const { id, region: region } = await resolvePlayerFromCommand(interaction);
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const problems: TableInput = [];
|
const problems: TableInput = [];
|
||||||
const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
const title = `${accountInfo.nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
||||||
let isEligible = false;
|
let isEligible = false;
|
||||||
let body = '';
|
let body = '';
|
||||||
|
|
||||||
if (clan === 'SKLLD') {
|
if (clan === 'SKLLD') {
|
||||||
const { diffed } = await getDiffedTankStats(
|
const { diff: diffed } = await getStatsInPeriod(
|
||||||
server,
|
region,
|
||||||
id,
|
id,
|
||||||
getTimeDaysAgo(server, 30),
|
getTimeDaysAgo(region, 30),
|
||||||
getPeriodNow(),
|
getPeriodNow(),
|
||||||
);
|
);
|
||||||
const entries = Object.entries(diffed);
|
const entries = Object.entries(diffed);
|
||||||
@@ -171,7 +167,7 @@ export const eligibleCommand: CommandRegistry = {
|
|||||||
problems,
|
problems,
|
||||||
)}`;
|
)}`;
|
||||||
} else if (clan === 'SMRI') {
|
} else if (clan === 'SMRI') {
|
||||||
const stats = accountInfo[id].statistics.all;
|
const stats = accountInfo.statistics.all;
|
||||||
|
|
||||||
if (stats.battles < 1500) {
|
if (stats.battles < 1500) {
|
||||||
problems.push([
|
problems.push([
|
||||||
|
|||||||
@@ -1,31 +1,142 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import {
|
||||||
import { CYCLIC_API } from '../constants/cyclic';
|
SlashCommandBuilder,
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
SlashCommandSubcommandGroupBuilder,
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
} from 'discord.js';
|
||||||
|
import * as Graph from '../components/Graph';
|
||||||
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
|
import TitleBar from '../components/TitleBar';
|
||||||
|
import Wrapper from '../components/Wrapper';
|
||||||
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import resolveTankId from '../core/blitz/resolveTankId';
|
import resolveTankId from '../core/blitz/resolveTankId';
|
||||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
||||||
|
import getTankHistories from '../core/blitzkrieg/getTankHistories';
|
||||||
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
|
import getPlayerHistories from '../core/blitzstars/getPlayerHistories';
|
||||||
|
import addPeriodSubCommands from '../core/discord/addPeriodSubCommands';
|
||||||
|
import addTankChoices from '../core/discord/addTankChoices';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import interactionToURL from '../core/discord/interactionToURL';
|
import buttonPrimary from '../core/discord/buttonPrimary';
|
||||||
import linkButton from '../core/discord/linkButton';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import primaryButton from '../core/discord/primaryButton';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
import resolvePeriodFromCommand, {
|
||||||
|
ResolvedPeriod,
|
||||||
|
} from '../core/discord/resolvePeriodFromCommand';
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand, {
|
||||||
|
ResolvedPlayer,
|
||||||
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import evolution from '../renderers/evolution';
|
|
||||||
import { StatType } from '../renderers/stats';
|
type EvolutionStatType = 'player' | 'tank';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
|
async function render(
|
||||||
|
{ region, id }: ResolvedPlayer,
|
||||||
|
{ start, end, name }: ResolvedPeriod,
|
||||||
|
type: 'player' | 'tank',
|
||||||
|
tankId: number | null,
|
||||||
|
) {
|
||||||
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
|
const logo = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
||||||
|
const histories = await (type === 'player'
|
||||||
|
? getPlayerHistories(region, id, {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
includeLatestHistories: true,
|
||||||
|
includePreviousHistories: true,
|
||||||
|
})
|
||||||
|
: getTankHistories(region, id, {
|
||||||
|
tankId: tankId!,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
includeLatestHistories: true,
|
||||||
|
includePreviousHistories: true,
|
||||||
|
}));
|
||||||
|
const plot = histories.map(
|
||||||
|
(history) =>
|
||||||
|
[
|
||||||
|
history.all.battles,
|
||||||
|
(history.all.wins / history.all.battles) * 100,
|
||||||
|
] as Graph.PlotItem,
|
||||||
|
);
|
||||||
|
const times = histories.map((history) => history.last_battle_time);
|
||||||
|
const minTime = Math.min(...times);
|
||||||
|
const maxTime = Math.max(...times);
|
||||||
|
const ys = plot.map(([, y]) => y);
|
||||||
|
const xs = plot.map(([x]) => x);
|
||||||
|
const maxY = Math.max(...ys);
|
||||||
|
const minY = Math.min(...ys);
|
||||||
|
const maxX = Math.max(...xs);
|
||||||
|
const minX = Math.min(...xs);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Wrapper>
|
||||||
|
<TitleBar name={accountInfo.nickname} image={logo} description={name} />
|
||||||
|
|
||||||
|
{plot.length > 0 && (
|
||||||
|
<Graph.Root
|
||||||
|
verticalMargin={{
|
||||||
|
min: minY,
|
||||||
|
max: maxY,
|
||||||
|
suffix: '%',
|
||||||
|
precision: 2,
|
||||||
|
}}
|
||||||
|
horizontalMargin={{
|
||||||
|
min: minX,
|
||||||
|
max: maxX,
|
||||||
|
precision: 0,
|
||||||
|
}}
|
||||||
|
xMinLabel={new Date(minTime * 1000).toDateString()}
|
||||||
|
xMaxLabel={new Date(maxTime * 1000).toDateString()}
|
||||||
|
>
|
||||||
|
{Graph.Line({
|
||||||
|
color: Graph.LineColor.Red,
|
||||||
|
plot: plot,
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
})}
|
||||||
|
</Graph.Root>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{plot.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const evolutionCommand = new Promise<CommandRegistryRaw>(
|
export const evolutionCommand = new Promise<CommandRegistryRaw>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
const command = await addStatTypeSubCommandGroups(
|
let playerGroup: SlashCommandSubcommandGroupBuilder;
|
||||||
new SlashCommandBuilder()
|
let tankGroup: SlashCommandSubcommandGroupBuilder;
|
||||||
.setName('evolution')
|
const command = new SlashCommandBuilder()
|
||||||
.setDescription('Evolution of statistics'),
|
.setName('evolution')
|
||||||
false,
|
.setDescription('Evolution of statistics')
|
||||||
);
|
.addSubcommandGroup((option) => {
|
||||||
|
playerGroup = option
|
||||||
|
.setName('player')
|
||||||
|
.setDescription('Player statistics');
|
||||||
|
|
||||||
|
return playerGroup;
|
||||||
|
})
|
||||||
|
.addSubcommandGroup((option) => {
|
||||||
|
tankGroup = option.setName('tank').setDescription('Tank statistics');
|
||||||
|
|
||||||
|
return tankGroup;
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
addPeriodSubCommands(playerGroup!, (option) =>
|
||||||
|
option.addStringOption(addUsernameChoices),
|
||||||
|
),
|
||||||
|
addPeriodSubCommands(tankGroup!, (option) =>
|
||||||
|
option
|
||||||
|
.addStringOption(addTankChoices)
|
||||||
|
.addStringOption(addUsernameChoices),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
@@ -34,37 +145,28 @@ export const evolutionCommand = new Promise<CommandRegistryRaw>(
|
|||||||
command,
|
command,
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup = interaction.options.getSubcommandGroup(
|
const commandGroup =
|
||||||
true,
|
interaction.options.getSubcommandGroup() as EvolutionStatType;
|
||||||
) as StatType;
|
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
const tankIdRaw = interaction.options.getString('tank')!;
|
||||||
const tankId =
|
const tankId =
|
||||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
||||||
const start = interaction.options.getInteger('start');
|
const path = commandToURL(interaction, {
|
||||||
const end = interaction.options.getInteger('end');
|
|
||||||
const { nickname } = (
|
|
||||||
await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
|
||||||
)
|
|
||||||
)[player.id];
|
|
||||||
const path = interactionToURL(interaction, {
|
|
||||||
...player,
|
...player,
|
||||||
|
...getCustomPeriodParams(interaction),
|
||||||
tankId,
|
tankId,
|
||||||
start,
|
|
||||||
end,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getBlitzStarsLinkButton;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
await evolution(commandGroup, period, player, tankId),
|
await render(player, period, commandGroup, tankId),
|
||||||
primaryButton(path, 'Refresh'),
|
buttonPrimary(path, 'Refresh'),
|
||||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
await getBlitzStarsLinkButton(
|
||||||
linkButton(
|
player.region,
|
||||||
`https://www.blitzstars.com/player/${player.region}/${nickname}${
|
player.id,
|
||||||
commandGroup === 'tank' ? `/tank/${tankId!}` : ''
|
tankId ?? undefined,
|
||||||
}`,
|
|
||||||
'BlitzStars',
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@@ -75,17 +177,17 @@ export const evolutionCommand = new Promise<CommandRegistryRaw>(
|
|||||||
},
|
},
|
||||||
|
|
||||||
async button(interaction) {
|
async button(interaction) {
|
||||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
const url = new URL(`https://example.com/${interaction.customId}`);
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
const path = url.pathname.split('/');
|
||||||
const commandGroup = path[1] as StatType;
|
const commandGroup = path[2] as EvolutionStatType;
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
|
||||||
return await evolution(
|
return await render(
|
||||||
commandGroup,
|
|
||||||
period,
|
|
||||||
player,
|
player,
|
||||||
parseInt(url.searchParams.get('tankId')!),
|
period,
|
||||||
|
commandGroup,
|
||||||
|
parseInt(url.searchParams.get('tankId') ?? '0') || null,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,30 +1,76 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { TreeTypeString } from '../components/Tanks';
|
import GenericAllStats from '../components/GenericAllStats';
|
||||||
import { CYCLIC_API } from '../constants/cyclic';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import TierWeights from '../components/TierWeights';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import TitleBar from '../components/TitleBar';
|
||||||
import resolveTankId from '../core/blitz/resolveTankId';
|
import Wrapper from '../components/Wrapper';
|
||||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
||||||
|
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
|
import addFilterOptions from '../core/discord/addFilterOptions';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import interactionToURL from '../core/discord/interactionToURL';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import linkButton from '../core/discord/linkButton';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import primaryButton from '../core/discord/primaryButton';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
import resolvePeriodFromCommand, {
|
||||||
|
ResolvedPeriod,
|
||||||
|
} from '../core/discord/resolvePeriodFromCommand';
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand, {
|
||||||
|
ResolvedPlayer,
|
||||||
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
||||||
|
import { getTierWeights } from '../core/statistics/getTierWeights';
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import fullStats from '../renderers/fullStats';
|
|
||||||
import { MultiTankFilters, StatType } from '../renderers/stats';
|
async function render(
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
{ region, id }: ResolvedPlayer,
|
||||||
|
{ start, end, name }: ResolvedPeriod,
|
||||||
|
filters: StatFilters,
|
||||||
|
) {
|
||||||
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
|
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
||||||
|
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
||||||
|
const { stats, supplementary, filteredOrder } = await filterStats(
|
||||||
|
diffedTankStats,
|
||||||
|
filters,
|
||||||
|
);
|
||||||
|
const filterDescriptions = await filtersToDescription(filters);
|
||||||
|
const tierWeights = await getTierWeights(diffedTankStats.diff, filteredOrder);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Wrapper>
|
||||||
|
<TitleBar
|
||||||
|
name={nickname}
|
||||||
|
image={clanImage}
|
||||||
|
description={`${name} • ${filterDescriptions}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
|
{stats.battles > 0 && <TierWeights weights={tierWeights!} />}
|
||||||
|
{stats.battles > 0 && (
|
||||||
|
<GenericAllStats stats={stats} supplementaryStats={supplementary} />
|
||||||
|
)}
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
const command = await addStatTypeSubCommandGroups(
|
const command = await addFilterOptions(
|
||||||
new SlashCommandBuilder()
|
new SlashCommandBuilder()
|
||||||
.setName('full-stats')
|
.setName('full-stats')
|
||||||
.setDescription('Full in-game statistics'),
|
.setDescription('Full in-game statistics'),
|
||||||
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
);
|
);
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
@@ -34,60 +80,20 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
command,
|
command,
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup = interaction.options.getSubcommandGroup(
|
|
||||||
true,
|
|
||||||
) as StatType;
|
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
const resolvedPeriod = resolvePeriodFromCommand(
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
player.region,
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
interaction,
|
const path = commandToURL(interaction, {
|
||||||
);
|
|
||||||
const period = interaction.options.getString('period');
|
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
|
||||||
const tankId =
|
|
||||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
|
||||||
const start = interaction.options.getInteger('start');
|
|
||||||
const end = interaction.options.getInteger('end');
|
|
||||||
const path = interactionToURL(interaction, {
|
|
||||||
...player,
|
...player,
|
||||||
tankId,
|
...getCustomPeriodParams(interaction),
|
||||||
start,
|
...filters,
|
||||||
end,
|
|
||||||
period,
|
|
||||||
});
|
});
|
||||||
const { nickname } = (
|
|
||||||
await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
|
||||||
)
|
|
||||||
)[player.id];
|
|
||||||
|
|
||||||
const tierOption = interaction.options.getString('tier');
|
return Promise.all([
|
||||||
|
render(player, period, filters),
|
||||||
return [
|
buttonRefresh(interaction, path),
|
||||||
await fullStats(
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
commandGroup,
|
]);
|
||||||
resolvedPeriod,
|
|
||||||
player,
|
|
||||||
commandGroup === 'tank'
|
|
||||||
? tankId
|
|
||||||
: commandGroup === 'multi-tank'
|
|
||||||
? ({
|
|
||||||
'tank-type':
|
|
||||||
interaction.options.getString('tank-type') ?? undefined,
|
|
||||||
nation: interaction.options.getString('nation') ?? undefined,
|
|
||||||
tier: tierOption ? parseInt(tierOption) : undefined,
|
|
||||||
'tree-type': (interaction.options.getString('tree-type') ??
|
|
||||||
undefined) as TreeTypeString | undefined,
|
|
||||||
} satisfies Partial<MultiTankFilters>)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
primaryButton(path, 'Refresh'),
|
|
||||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
|
||||||
linkButton(
|
|
||||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
|
||||||
'BlitzStars',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
autocomplete: (interaction) => {
|
||||||
@@ -96,18 +102,11 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
},
|
},
|
||||||
|
|
||||||
async button(interaction) {
|
async button(interaction) {
|
||||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
|
||||||
const commandGroup = path[1] as StatType;
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await fullStats(
|
return await render(player, period, filters);
|
||||||
commandGroup,
|
|
||||||
period,
|
|
||||||
player,
|
|
||||||
parseInt(url.searchParams.get('tankId')!),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,14 +3,12 @@ import GenericStats from '../components/GenericStats';
|
|||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
import Wrapper from '../components/Wrapper';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import { getClanInfo } from '../core/blitz/getClanInfo';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
import autocompleteClan from '../core/discord/autocompleteClan';
|
||||||
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { ClanInfo } from '../types/clanInfo';
|
|
||||||
|
|
||||||
const DEFAULT_THRESHOLD = 7;
|
const DEFAULT_THRESHOLD = 7;
|
||||||
|
|
||||||
@@ -36,24 +34,16 @@ export const inactiveCommand: CommandRegistry = {
|
|||||||
const threshold =
|
const threshold =
|
||||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||||
const time = new Date().getTime() / 1000;
|
const time = new Date().getTime() / 1000;
|
||||||
const clanData = (
|
const clanInfo = await getClanInfo(region, id);
|
||||||
await getWargamingResponse<ClanInfo>(
|
const accountInfo = await getAccountInfo(region, clanInfo.members_ids);
|
||||||
`https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`,
|
const inactive = accountInfo
|
||||||
|
.map(
|
||||||
|
(account) =>
|
||||||
|
[
|
||||||
|
account.nickname,
|
||||||
|
(time - account.last_battle_time) / 60 / 60 / 24,
|
||||||
|
] as [string, number],
|
||||||
)
|
)
|
||||||
)[id];
|
|
||||||
const memberIds = clanData.members_ids;
|
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds.join(
|
|
||||||
',',
|
|
||||||
)}`,
|
|
||||||
);
|
|
||||||
const inactive = memberIds
|
|
||||||
.map((memberId) => {
|
|
||||||
const member = accounts[memberId];
|
|
||||||
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
|
|
||||||
|
|
||||||
return [member.nickname, inactiveDays] as [string, number];
|
|
||||||
})
|
|
||||||
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
||||||
.sort((a, b) => b[1] - a[1])
|
.sort((a, b) => b[1] - a[1])
|
||||||
.map(
|
.map(
|
||||||
@@ -64,8 +54,8 @@ export const inactiveCommand: CommandRegistry = {
|
|||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={clanData.name}
|
name={clanInfo.name}
|
||||||
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData.emblem_set_id}.png`}
|
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
|
||||||
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
|
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
import { teal } from '@radix-ui/colors';
|
||||||
|
import {
|
||||||
|
AttachmentBuilder,
|
||||||
|
GuildMemberRoleManager,
|
||||||
|
SlashCommandBuilder,
|
||||||
|
} from 'discord.js';
|
||||||
|
import markdownEscape from 'markdown-escape';
|
||||||
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
|
import { Glow } from '../components/AllStatsOverview/components/WN8Display/components/Glow';
|
||||||
|
import Wrapper from '../components/Wrapper';
|
||||||
|
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
||||||
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import embedNegative from '../core/discord/embedNegative';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
import { theme } from '../stitches.config';
|
||||||
|
|
||||||
|
const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||||
|
|
||||||
|
export const verifyCommand: CommandRegistry = {
|
||||||
|
inProduction: true,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
command: new SlashCommandBuilder()
|
||||||
|
.setName('link')
|
||||||
|
.setDescription('Links your Blitz and Discord account')
|
||||||
|
.addStringOption((option) => addUsernameChoices(option).setRequired(true)),
|
||||||
|
|
||||||
|
async handler(interaction) {
|
||||||
|
const username = interaction.options.getString('username', true);
|
||||||
|
|
||||||
|
if (serverAndIdPattern.test(username)) {
|
||||||
|
const [region, idString] = username.split('/');
|
||||||
|
const id = parseInt(idString);
|
||||||
|
const discordId = parseInt(interaction.user.id);
|
||||||
|
const accountInfo = await getAccountInfo(region as Region, id);
|
||||||
|
const clanAccountInfo = await getClanAccountInfo(region as Region, id, [
|
||||||
|
'clan',
|
||||||
|
]);
|
||||||
|
|
||||||
|
await linkBlitzAndDiscord(discordId, region as Region, id);
|
||||||
|
|
||||||
|
if (interaction.guildId === discord.sklld_guild_id) {
|
||||||
|
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
|
||||||
|
return embedNegative(
|
||||||
|
`${markdownEscape(interaction.user.username)} failed to verify`,
|
||||||
|
"I don't have the permission to change your manage roles.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await (interaction.member!.roles as GuildMemberRoleManager).remove(
|
||||||
|
discord.sklld_verify_role,
|
||||||
|
);
|
||||||
|
await (interaction.member!.roles as GuildMemberRoleManager).add(
|
||||||
|
discord.sklld_peasant_role,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Wrapper fat>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Glow color={teal.teal9} rotation={90} />
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 8,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={
|
||||||
|
interaction.user.avatarURL({ extension: 'png' }) ??
|
||||||
|
'https://i.stack.imgur.com/l60Hf.png'
|
||||||
|
}
|
||||||
|
style={{
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
borderRadius: 32,
|
||||||
|
objectFit: 'cover',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 32,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 900,
|
||||||
|
maxWidth: 240,
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{interaction.user.displayName}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
@{interaction.user.username}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 4,
|
||||||
|
color: theme.colors.textLowContrast_teal,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="https://i.imgur.com/jIcRgog.png"
|
||||||
|
style={{
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span style={{ fontSize: 16 }}>Accounts linked</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: 8,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clanAccountInfo?.clan ? (
|
||||||
|
<img
|
||||||
|
style={{
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
borderRadius: 32,
|
||||||
|
objectFit: 'cover',
|
||||||
|
}}
|
||||||
|
src={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanAccountInfo?.clan?.emblem_set_id}.png`}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 32,
|
||||||
|
color: theme.colors.textHighContrast,
|
||||||
|
fontWeight: 900,
|
||||||
|
maxWidth: 240,
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{accountInfo.nickname}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: 16,
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clanAccountInfo?.clan
|
||||||
|
? `[${clanAccountInfo?.clan?.tag}] - `
|
||||||
|
: ''}
|
||||||
|
{REGION_NAMES_SHORT[region as Region]}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Glow color={teal.teal9} rotation={-90} />
|
||||||
|
</div>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
embedNegative(
|
||||||
|
'Please select from the options',
|
||||||
|
'Follow the procedure like the video above. The search results may take a while to show up.',
|
||||||
|
),
|
||||||
|
new AttachmentBuilder('https://i.imgur.com/2p6GFgC.gif'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
autocomplete: autocompleteUsername,
|
||||||
|
};
|
||||||
@@ -3,46 +3,24 @@ import NoData, { NoDataType } from '../components/NoData';
|
|||||||
import * as Tanks from '../components/Tanks';
|
import * as Tanks from '../components/Tanks';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
import Wrapper from '../components/Wrapper';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import getTankStats from '../core/blitz/getTankStats';
|
import getTankStats from '../core/blitz/getTankStats';
|
||||||
import getTreeType from '../core/blitz/getTreeType';
|
import getTreeType from '../core/blitz/getTreeType';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
||||||
import resolveTankName from '../core/blitz/resolveTankName';
|
import resolveTankName from '../core/blitz/resolveTankName';
|
||||||
|
import { tankopediaInfo } from '../core/blitz/tankopediaInfo';
|
||||||
|
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
||||||
import {
|
import {
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
TankopediaEntry,
|
TankopediaEntry,
|
||||||
Tier,
|
Tier,
|
||||||
tankopedia,
|
tankopedia,
|
||||||
tankopediaInfo,
|
} from '../core/blitzstars/tankopedia';
|
||||||
} from '../core/blitz/tankopedia';
|
|
||||||
import addTierChoices from '../core/discord/addTierChoices';
|
import addTierChoices from '../core/discord/addTierChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
|
||||||
|
|
||||||
const COMP_TANKS = [
|
|
||||||
// light tanks
|
|
||||||
24321, // t-100 lt
|
|
||||||
20257, // sheridan
|
|
||||||
3649, // bat chat
|
|
||||||
19537, // vickers
|
|
||||||
|
|
||||||
// heavy tanks
|
|
||||||
6145, // is-4
|
|
||||||
7169, // is-7
|
|
||||||
10785, // t110e5
|
|
||||||
12161, // strvk
|
|
||||||
4481, // kranvagn
|
|
||||||
22817, // m6 yoh
|
|
||||||
6225, // fv215b
|
|
||||||
5425, // wz 113
|
|
||||||
7297, // 60tp
|
|
||||||
58641, // vk 72
|
|
||||||
6753, // type 71
|
|
||||||
];
|
|
||||||
|
|
||||||
export const ownedTanksCommand: CommandRegistry = {
|
export const ownedTanksCommand: CommandRegistry = {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
@@ -58,9 +36,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
const tier = Number(interaction.options.getString('tier'));
|
const tier = Number(interaction.options.getString('tier'));
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
const account = await resolvePlayerFromCommand(interaction);
|
||||||
const { id, region: server } = account;
|
const { id, region: server } = account;
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getAccountInfo(server, id);
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const tankStats = await getTankStats(server, id);
|
const tankStats = await getTankStats(server, id);
|
||||||
const filteredTanks = (
|
const filteredTanks = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@@ -70,9 +46,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
).filter((tank) => tank.tankopedia?.tier === tier);
|
).filter((tank) => tank.tankopedia?.tier === tier);
|
||||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
const clanAccountInfo = await getClanAccountInfo(server, id, ['clan']);
|
||||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
|
||||||
);
|
|
||||||
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
||||||
const nations: string[] = [];
|
const nations: string[] = [];
|
||||||
|
|
||||||
@@ -90,18 +64,13 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={accountInfo[id].nickname}
|
name={accountInfo.nickname}
|
||||||
nameDiscriminator={
|
|
||||||
clanData[id]?.clan ? `[${clanData[id]?.clan?.tag}]` : undefined
|
|
||||||
}
|
|
||||||
image={
|
image={
|
||||||
clanData[id]?.clan
|
clanAccountInfo?.clan
|
||||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
? emblemIdToURL(clanAccountInfo.clan.emblem_set_id)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
description={`Tier ${
|
description={`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]} tanks`}
|
||||||
TIER_ROMAN_NUMERALS[tier as Tier]
|
|
||||||
} tanks • ${new Date().toDateString()}`}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{filteredTanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
{filteredTanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
||||||
@@ -158,17 +127,3 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
autocomplete: autocompleteUsername,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: make this work in the future
|
|
||||||
// console.log('Caching tank images...');
|
|
||||||
// TANKS.then((tanks) =>
|
|
||||||
// jsxToSvg(
|
|
||||||
// <div style={{ display: 'flex' }}>
|
|
||||||
// {tanks.map(({ images, tank_id }) => {
|
|
||||||
// return (
|
|
||||||
// images.normal && <img key={tank_id} src={images.normal} width={0} />
|
|
||||||
// );
|
|
||||||
// })}
|
|
||||||
// </div>,
|
|
||||||
// ),
|
|
||||||
// ).then(() => console.log('Cached tank images'));
|
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { startCase } from 'lodash';
|
import { startCase } from 'lodash';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountAchievements } from '../core/blitz/getAccountAchievements';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
|
import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountAchievements } from '../types/accountAchievements';
|
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
|
|
||||||
type SortBy = 'name' | 'count';
|
type SortBy = 'name' | 'count';
|
||||||
|
|
||||||
@@ -35,22 +33,17 @@ export const playerAchievementsCommand: CommandRegistry = {
|
|||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
const account = await resolvePlayerFromCommand(interaction);
|
||||||
const { id, region: server } = account;
|
const { id, region: region } = account;
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
const accountsAchievements = await getAccountAchievements(region, id);
|
||||||
);
|
const accountAchievements = accountsAchievements;
|
||||||
const accountsAchievements =
|
|
||||||
await getWargamingResponse<AccountAchievements>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const accountAchievements = accountsAchievements[id];
|
|
||||||
const compound = {
|
const compound = {
|
||||||
...accountAchievements.achievements,
|
...accountAchievements.achievements,
|
||||||
...accountAchievements.max_series,
|
...accountAchievements.max_series,
|
||||||
};
|
};
|
||||||
|
|
||||||
return embedInfo(
|
return embedInfo(
|
||||||
`${markdownEscape(accounts[id].nickname)}'s information`,
|
`${markdownEscape(accountInfo.nickname)}'s information`,
|
||||||
|
|
||||||
markdownTable(
|
markdownTable(
|
||||||
Object.keys(compound)
|
Object.keys(compound)
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import markdownTable from '../core/discord/markdownTable';
|
import markdownTable from '../core/discord/markdownTable';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
|
|
||||||
export const playerInfoCommand: CommandRegistry = {
|
export const playerInfoCommand: CommandRegistry = {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
@@ -21,11 +19,8 @@ export const playerInfoCommand: CommandRegistry = {
|
|||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const account = await resolvePlayerFromCommand(interaction);
|
const account = await resolvePlayerFromCommand(interaction);
|
||||||
const { id, region: server } = account;
|
const { id, region: region } = account;
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const accountInfo = accounts[id];
|
|
||||||
|
|
||||||
return embedInfo(
|
return embedInfo(
|
||||||
`${markdownEscape(accountInfo.nickname)}'s information`,
|
`${markdownEscape(accountInfo.nickname)}'s information`,
|
||||||
|
|||||||
@@ -4,28 +4,30 @@ import {
|
|||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
SlashCommandSubcommandGroupBuilder,
|
SlashCommandSubcommandGroupBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
import { range } from 'lodash';
|
||||||
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
|
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
|
||||||
import * as Leaderboard from '../components/Leaderboard';
|
import * as Leaderboard from '../components/Leaderboard';
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
import Wrapper from '../components/Wrapper';
|
||||||
|
import { LEAGUES } from '../constants/leagues';
|
||||||
|
import { FIRST_ARCHIVED_RATINGS_SEASON } from '../constants/ratings';
|
||||||
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import getArchivedRatingsInfo from '../core/blitz/getArchivedRatingsInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import { getRatingsLeague } from '../core/blitz/getRatingsLeague';
|
||||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
import { getRatingsNeighbors } from '../core/blitz/getRatingsNeighbors';
|
||||||
import getMidnightLeaderboard, {
|
import { getArchivedLatestSeasonNumber } from '../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
||||||
DATABASE_REPO,
|
import getArchivedRatingsInfo from '../core/blitzkrieg/getArchivedRatingsInfo';
|
||||||
} from '../core/database/getMidnightLeaderboard';
|
import { getArchivedRatingsLeaderboard } from '../core/blitzkrieg/getArchivedRatingsLeaderboard';
|
||||||
|
import getArchivedRatingsMidnightLeaderboard from '../core/blitzkrieg/getArchivedRatingsMidnightLeaderboard';
|
||||||
|
import { UserError } from '../core/blitzkrieg/userError';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
|
import embedNegative from '../core/discord/embedNegative';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { octokit } from '../core/github/octokit';
|
|
||||||
import throwError from '../core/node/throwError';
|
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
|
||||||
|
|
||||||
export interface RatingsPlayer {
|
export interface RatingsPlayer {
|
||||||
spa_id: number;
|
spa_id: number;
|
||||||
@@ -114,14 +116,6 @@ export interface RatingsNeighbors {
|
|||||||
neighbors: RatingsPlayer[];
|
neighbors: RatingsPlayer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const LEAGUES = [
|
|
||||||
{ name: 'Diamond', minScore: 5000 },
|
|
||||||
{ name: 'Platinum', minScore: 4000 },
|
|
||||||
{ name: 'Gold', minScore: 3000 },
|
|
||||||
{ name: 'Silver', minScore: 2000 },
|
|
||||||
{ name: 'Bronze', minScore: 0 },
|
|
||||||
];
|
|
||||||
|
|
||||||
function addSubcommands(
|
function addSubcommands(
|
||||||
option: SlashCommandSubcommandGroupBuilder,
|
option: SlashCommandSubcommandGroupBuilder,
|
||||||
addOptions = (option: SlashCommandSubcommandBuilder) => option,
|
addOptions = (option: SlashCommandSubcommandBuilder) => option,
|
||||||
@@ -130,14 +124,14 @@ function addSubcommands(
|
|||||||
.addSubcommand((option) =>
|
.addSubcommand((option) =>
|
||||||
addOptions(
|
addOptions(
|
||||||
option
|
option
|
||||||
.setName('neighbours')
|
.setName('neighbors')
|
||||||
.setDescription('Your position and neighbours'),
|
.setDescription('Your position and neighbors'),
|
||||||
)
|
)
|
||||||
.addStringOption(addUsernameChoices)
|
.addStringOption(addUsernameChoices)
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('limit')
|
.setName('limit')
|
||||||
.setDescription('How many neighbours to display (default: 10)')
|
.setDescription('How many neighbors to display (default: 10)')
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
.setMinValue(5)
|
.setMinValue(5)
|
||||||
.setMaxValue(30),
|
.setMaxValue(30),
|
||||||
@@ -172,25 +166,24 @@ function addSubcommands(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const noOngoingSeason = embedNegative(
|
||||||
|
'No ongoing season',
|
||||||
|
"Wargaming didn't provide any data for this season.",
|
||||||
|
);
|
||||||
|
|
||||||
export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
const seasonChoices = await octokit.repos
|
const latestArchivedSeasonNumber = await getArchivedLatestSeasonNumber();
|
||||||
.getContent({
|
const seasonChoices = range(
|
||||||
...DATABASE_REPO,
|
FIRST_ARCHIVED_RATINGS_SEASON,
|
||||||
path: 'com/ratings',
|
latestArchivedSeasonNumber + 1,
|
||||||
})
|
).map(
|
||||||
.then(({ data }) => {
|
(number) =>
|
||||||
if (!Array.isArray(data)) {
|
({
|
||||||
throw throwError('Archived ratings data is malformed');
|
name: `Season ${number}`,
|
||||||
}
|
value: `${number}`,
|
||||||
return data.map(
|
}) satisfies APIApplicationCommandOptionChoice<string>,
|
||||||
(folder) =>
|
);
|
||||||
({
|
|
||||||
name: `Season ${folder.name}`,
|
|
||||||
value: folder.name,
|
|
||||||
}) satisfies APIApplicationCommandOptionChoice<string>,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const command = new SlashCommandBuilder()
|
const command = new SlashCommandBuilder()
|
||||||
.setName('ratings')
|
.setName('ratings')
|
||||||
@@ -236,7 +229,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
| 'current';
|
| 'current';
|
||||||
const subcommand = interaction.options.getSubcommand(true) as
|
const subcommand = interaction.options.getSubcommand(true) as
|
||||||
| 'league'
|
| 'league'
|
||||||
| 'neighbours';
|
| 'neighbors';
|
||||||
const limit = interaction.options.getInteger('limit') ?? 10;
|
const limit = interaction.options.getInteger('limit') ?? 10;
|
||||||
const seasonOption = interaction.options.getString('season');
|
const seasonOption = interaction.options.getString('season');
|
||||||
const season = seasonOption ? parseInt(seasonOption) : undefined;
|
const season = seasonOption ? parseInt(seasonOption) : undefined;
|
||||||
@@ -258,41 +251,27 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
const region = interaction.options.getString('region') as Region;
|
const region = interaction.options.getString('region') as Region;
|
||||||
regionRatingsInfo = await (subcommandGroup === 'current'
|
regionRatingsInfo = await (subcommandGroup === 'current'
|
||||||
? getRatingsInfo(region)
|
? getRatingsInfo(region)
|
||||||
: getArchivedRatingsInfo(season!, region));
|
: getArchivedRatingsInfo(region, season!));
|
||||||
const regionSubdomain = regionToRegionSubdomain(region);
|
|
||||||
|
if (regionRatingsInfo.detail !== undefined) return noOngoingSeason;
|
||||||
|
|
||||||
const result =
|
const result =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? regionRatingsInfo.detail === undefined
|
? await getRatingsLeague(region, leagueIndex).then(
|
||||||
? await fetch(
|
async (result) =>
|
||||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
result.slice(0, limit).map(
|
||||||
)
|
(player) =>
|
||||||
.then((response) => response.json() as Promise<LeagueTop>)
|
({
|
||||||
.then(async ({ result }) =>
|
id: player.spa_id,
|
||||||
result.slice(0, limit).map(
|
score: player.score,
|
||||||
(player) =>
|
position: player.number,
|
||||||
({
|
clan: player.clan_tag,
|
||||||
id: player.spa_id,
|
nickname: player.nickname,
|
||||||
score: player.score,
|
}) satisfies SimplifiedPlayer,
|
||||||
position: player.number,
|
),
|
||||||
clan: player.clan_tag,
|
)
|
||||||
nickname: player.nickname,
|
: await getArchivedRatingsLeaderboard(region, season!).then(
|
||||||
}) satisfies SimplifiedPlayer,
|
async (players) => {
|
||||||
),
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
: await octokit.repos
|
|
||||||
.getContent({
|
|
||||||
...DATABASE_REPO,
|
|
||||||
path: `${region}/ratings/${season}/latest.json`,
|
|
||||||
})
|
|
||||||
.then(async ({ data }) => {
|
|
||||||
if (Array.isArray(data) || data.type !== 'file') {
|
|
||||||
throw throwError('Archived ratings data is malformed');
|
|
||||||
}
|
|
||||||
|
|
||||||
const players = (await fetch(data.download_url!).then(
|
|
||||||
(response) => response.json(),
|
|
||||||
)) as BlitzkriegRatingsLeaderboard;
|
|
||||||
const firstPlayerIndex =
|
const firstPlayerIndex =
|
||||||
leagueIndex === 0
|
leagueIndex === 0
|
||||||
? 0
|
? 0
|
||||||
@@ -305,9 +284,10 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
firstPlayerIndex,
|
firstPlayerIndex,
|
||||||
lastPlayerIndex + 1,
|
lastPlayerIndex + 1,
|
||||||
);
|
);
|
||||||
const ids = trimmed.map((player) => player.id).join(',');
|
const clanData = await getClanAccountInfo(
|
||||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
region,
|
||||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
trimmed.map(({ id }) => id),
|
||||||
|
['clan'],
|
||||||
);
|
);
|
||||||
|
|
||||||
return trimmed.map(
|
return trimmed.map(
|
||||||
@@ -322,114 +302,70 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
`Unknown Player ${player.id}`,
|
`Unknown Player ${player.id}`,
|
||||||
}) satisfies SimplifiedPlayer,
|
}) satisfies SimplifiedPlayer,
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
const leagueInfo =
|
);
|
||||||
regionRatingsInfo.detail === undefined
|
const leagueInfo = regionRatingsInfo.leagues[leagueIndex];
|
||||||
? regionRatingsInfo.leagues[leagueIndex]
|
|
||||||
: undefined;
|
|
||||||
midnightLeaderboard =
|
midnightLeaderboard =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? regionRatingsInfo.detail === undefined
|
? await getArchivedRatingsMidnightLeaderboard(
|
||||||
? await getMidnightLeaderboard(
|
region,
|
||||||
region,
|
regionRatingsInfo.current_season,
|
||||||
regionRatingsInfo.current_season,
|
)
|
||||||
)
|
: await getArchivedRatingsMidnightLeaderboard(region, season!);
|
||||||
: undefined
|
|
||||||
: await getMidnightLeaderboard(region, season!);
|
|
||||||
|
|
||||||
players = result;
|
players = result;
|
||||||
playersBefore = result ? result[0].position - 1 : 0;
|
playersBefore = result ? result[0].position - 1 : 0;
|
||||||
playersAfter =
|
playersAfter =
|
||||||
regionRatingsInfo.detail === undefined && result !== undefined
|
regionRatingsInfo.count - result[result.length - 1].position;
|
||||||
? regionRatingsInfo.count - result[result.length - 1].position
|
|
||||||
: 0;
|
|
||||||
titleName = `${
|
titleName = `${
|
||||||
leagueInfo ? leagueInfo.title : 'No Ongoing Season'
|
leagueInfo ? leagueInfo.title : 'No Ongoing Season'
|
||||||
} - ${REGION_NAMES_SHORT[region]}`;
|
} - ${REGION_NAMES_SHORT[region]}`;
|
||||||
titleImage = leagueInfo
|
titleImage = leagueInfo.big_icon.startsWith('http')
|
||||||
? leagueInfo.big_icon.startsWith('http')
|
? leagueInfo.big_icon
|
||||||
? leagueInfo.big_icon
|
: `https:${leagueInfo.big_icon}`;
|
||||||
: `https:${leagueInfo.big_icon}`
|
|
||||||
: undefined;
|
|
||||||
titleDescription = `Top ${limit} players`;
|
titleDescription = `Top ${limit} players`;
|
||||||
} else {
|
} else {
|
||||||
const { region, id } = await resolvePlayerFromCommand(interaction);
|
const { region, id } = await resolvePlayerFromCommand(interaction);
|
||||||
regionRatingsInfo =
|
regionRatingsInfo =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? await getRatingsInfo(region)
|
? await getRatingsInfo(region)
|
||||||
: await octokit.repos
|
: await getArchivedRatingsInfo(region, season!);
|
||||||
.getContent({
|
|
||||||
...DATABASE_REPO,
|
|
||||||
path: `${region}/ratings/${season}/info.json`,
|
|
||||||
})
|
|
||||||
.then(async ({ data }) => {
|
|
||||||
if (Array.isArray(data) || data.type !== 'file') {
|
|
||||||
throw throwError('Archived ratings info is malformed');
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = fetch(data.download_url!);
|
if (regionRatingsInfo.detail !== undefined) return noOngoingSeason;
|
||||||
return (await response.then((response) =>
|
|
||||||
response.json(),
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
)) as RatingsInfo;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
});
|
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const clan = (
|
|
||||||
await getWargamingResponse<PlayerClanData>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
|
||||||
)
|
|
||||||
)[id]?.clan;
|
|
||||||
const regionSubdomain = regionToRegionSubdomain(region);
|
|
||||||
const neighbors =
|
const neighbors =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? regionRatingsInfo.detail === undefined
|
? await getRatingsNeighbors(
|
||||||
? await fetch(
|
region,
|
||||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${Math.round(
|
id,
|
||||||
limit / 2,
|
Math.round(limit / 2),
|
||||||
)}`,
|
).then((players) =>
|
||||||
)
|
players.neighbors.map(
|
||||||
.then(
|
(player) =>
|
||||||
(response) =>
|
({
|
||||||
response.json() as Promise<RatingsNeighbors>,
|
id: player.spa_id,
|
||||||
)
|
position: player.number,
|
||||||
.then((players) =>
|
score: player.score,
|
||||||
players.neighbors.map(
|
clan: player.clan_tag,
|
||||||
(player) =>
|
nickname: player.nickname,
|
||||||
({
|
}) satisfies SimplifiedPlayer,
|
||||||
id: player.spa_id,
|
),
|
||||||
position: player.number,
|
)
|
||||||
score: player.score,
|
: await getArchivedRatingsLeaderboard(region, season!).then(
|
||||||
clan: player.clan_tag,
|
async (players) => {
|
||||||
nickname: player.nickname,
|
|
||||||
}) satisfies SimplifiedPlayer,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
: await octokit.repos
|
|
||||||
.getContent({
|
|
||||||
...DATABASE_REPO,
|
|
||||||
path: `${region}/ratings/${season}/latest.json`,
|
|
||||||
})
|
|
||||||
.then(async ({ data }) => {
|
|
||||||
if (Array.isArray(data) || data.type !== 'file') {
|
|
||||||
throw throwError(
|
|
||||||
'Archived ratings latest data is malformed',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = fetch(data.download_url!);
|
|
||||||
const players = (await response.then((response) =>
|
|
||||||
response.json(),
|
|
||||||
)) as BlitzkriegRatingsLeaderboard;
|
|
||||||
const playerIndex = players.findIndex(
|
const playerIndex = players.findIndex(
|
||||||
(player) => player.id === id,
|
(player) => player.id === id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (playerIndex === -1) {
|
if (playerIndex === -1) {
|
||||||
throw throwError(
|
throw new UserError(
|
||||||
`${accountInfo[id].nickname} didn't player ratings in season ${season}`,
|
`${accountInfo.nickname} didn't player ratings in season ${season}`,
|
||||||
'This player did not participate in this season or did not get past calibration.',
|
{
|
||||||
|
cause:
|
||||||
|
'This player did not participate in this season or did not get past calibration.',
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,9 +374,10 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
playerIndex - halfRange,
|
playerIndex - halfRange,
|
||||||
playerIndex + halfRange + 1,
|
playerIndex + halfRange + 1,
|
||||||
);
|
);
|
||||||
const ids = trimmed.map((player) => player.id).join(',');
|
const clanData = await getClanAccountInfo(
|
||||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
region,
|
||||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
trimmed.map((player) => player.id),
|
||||||
|
['clan'],
|
||||||
);
|
);
|
||||||
|
|
||||||
return trimmed.map((player, index) => ({
|
return trimmed.map((player, index) => ({
|
||||||
@@ -450,49 +387,42 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
clan: clanData[player.id]!.clan?.tag,
|
clan: clanData[player.id]!.clan?.tag,
|
||||||
nickname: clanData[player.id]!.account_name,
|
nickname: clanData[player.id]!.account_name,
|
||||||
}));
|
}));
|
||||||
});
|
},
|
||||||
|
);
|
||||||
midnightLeaderboard =
|
midnightLeaderboard =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? regionRatingsInfo.detail === undefined
|
? await getArchivedRatingsMidnightLeaderboard(
|
||||||
? await getMidnightLeaderboard(
|
region,
|
||||||
region,
|
regionRatingsInfo.current_season,
|
||||||
regionRatingsInfo.current_season,
|
)
|
||||||
)
|
: await getArchivedRatingsMidnightLeaderboard(region, season!);
|
||||||
: undefined
|
|
||||||
: await getMidnightLeaderboard(region, season!);
|
|
||||||
|
|
||||||
if (clan && neighbors) titleNameDiscriminator = `[${clan.tag}]`;
|
if (clan && neighbors) titleNameDiscriminator = `[${clan.tag}]`;
|
||||||
|
|
||||||
players = neighbors;
|
players = neighbors;
|
||||||
titleImage = neighbors
|
titleImage = clan
|
||||||
? clan
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
|
||||||
: undefined
|
|
||||||
: undefined;
|
: undefined;
|
||||||
titleName = neighbors
|
titleName = neighbors
|
||||||
? accountInfo[id].nickname
|
? accountInfo.nickname
|
||||||
: `No Ongoing Season - ${REGION_NAMES_SHORT[region]}`;
|
: `No Ongoing Season - ${REGION_NAMES_SHORT[region]}`;
|
||||||
titleDescription = 'Ratings neighbours';
|
titleDescription = 'Ratings neighbors';
|
||||||
playersBefore = neighbors ? neighbors[0].position - 1 : 0;
|
playersBefore = neighbors ? neighbors[0].position - 1 : 0;
|
||||||
playersAfter =
|
playersAfter =
|
||||||
regionRatingsInfo.detail === undefined
|
regionRatingsInfo.count - neighbors[neighbors.length - 1].position;
|
||||||
? neighbors
|
|
||||||
? regionRatingsInfo.count -
|
|
||||||
neighbors[neighbors.length - 1].position
|
|
||||||
: 0
|
|
||||||
: 0;
|
|
||||||
playerId = id;
|
playerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = players?.map((player) => {
|
const resolvedRegionRatingsInfo: typeof regionRatingsInfo & {
|
||||||
const reward =
|
detail: undefined;
|
||||||
regionRatingsInfo.detail === undefined
|
} = regionRatingsInfo;
|
||||||
? regionRatingsInfo.rewards.find(
|
|
||||||
(reward) =>
|
const items = players.map((player) => {
|
||||||
player.position >= reward.from_position &&
|
const reward = resolvedRegionRatingsInfo.rewards.find(
|
||||||
player.position <= reward.to_position,
|
(reward) =>
|
||||||
)
|
player.position >= reward.from_position &&
|
||||||
: undefined;
|
player.position <= reward.to_position,
|
||||||
|
);
|
||||||
const midnightIndex = midnightLeaderboard?.findIndex(
|
const midnightIndex = midnightLeaderboard?.findIndex(
|
||||||
(item) => item.id === player.id,
|
(item) => item.id === player.id,
|
||||||
);
|
);
|
||||||
@@ -523,17 +453,22 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
<TitleBar
|
<TitleBar
|
||||||
name={titleName}
|
name={titleName}
|
||||||
image={titleImage}
|
image={titleImage}
|
||||||
nameDiscriminator={titleNameDiscriminator}
|
description={titleDescription}
|
||||||
description={`${titleDescription} • ${new Date().toDateString()}`}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{items && (
|
{items && (
|
||||||
<Leaderboard.Root>
|
<Leaderboard.Root>
|
||||||
{playersBefore > 0 && (
|
{playersBefore > 0 && (
|
||||||
<Leaderboard.Gap number={playersBefore} />
|
<Leaderboard.Gap
|
||||||
|
message={`+ ${playersBefore.toLocaleString()} more`}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{items}
|
{items}
|
||||||
{playersAfter > 0 && <Leaderboard.Gap number={playersAfter} />}
|
{playersAfter > 0 && (
|
||||||
|
<Leaderboard.Gap
|
||||||
|
message={`+ ${playersAfter.toLocaleString()} more`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Leaderboard.Root>
|
</Leaderboard.Root>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { REGION_NAMES, Region } from '../constants/regions';
|
import { REGION_NAMES, Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import addClanChoices from '../core/discord/addClanChoices';
|
import addClanChoices from '../core/discord/addClanChoices';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
@@ -30,7 +30,7 @@ export const searchClansCommand: CommandRegistry = {
|
|||||||
const server = interaction.options.getString('region') as Region;
|
const server = interaction.options.getString('region') as Region;
|
||||||
const clan = interaction.options.getString('clan')!;
|
const clan = interaction.options.getString('clan')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const clanList = await getWargamingResponse<ClanList>(
|
const clanList = await fetchBlitz<ClanList>(
|
||||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import { SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { REGION_NAMES, Region } from '../constants/regions';
|
import { REGION_NAMES, Region } from '../constants/regions';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import fetchBlitz from '../core/blitz/fetchBlitz';
|
||||||
import { AccountList, usernamePattern } from '../core/blitz/listPlayers';
|
import {
|
||||||
|
AccountList,
|
||||||
|
usernamePattern,
|
||||||
|
} from '../core/blitz/searchPlayersAcrossRegions';
|
||||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
@@ -34,7 +37,7 @@ export const searchPlayersCommand: CommandRegistry = {
|
|||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const trimmedSearch = name.trim();
|
const trimmedSearch = name.trim();
|
||||||
const players = usernamePattern.test(trimmedSearch)
|
const players = usernamePattern.test(trimmedSearch)
|
||||||
? await getWargamingResponse<AccountList>(
|
? await fetchBlitz<AccountList>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
||||||
trimmedSearch,
|
trimmedSearch,
|
||||||
)}&limit=${limit}`,
|
)}&limit=${limit}`,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { TANK_NAMES_DIACRITICS } from '../core/blitz/tankopedia';
|
import { TANK_NAMES_DIACRITICS } from '../core/blitzstars/tankopedia';
|
||||||
import addTankChoices from '../core/discord/addTankChoices';
|
import addTankChoices from '../core/discord/addTankChoices';
|
||||||
import embedInfo from '../core/discord/embedInfo';
|
import embedInfo from '../core/discord/embedInfo';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
|
|||||||
@@ -1,28 +1,68 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { TreeTypeString } from '../components/Tanks';
|
import AllStatsOverview from '../components/AllStatsOverview';
|
||||||
import { CYCLIC_API } from '../constants/cyclic';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
import TitleBar from '../components/TitleBar';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import Wrapper from '../components/Wrapper';
|
||||||
import resolveTankId from '../core/blitz/resolveTankId';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
|
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
|
||||||
|
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
|
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
|
||||||
|
import addFilterOptions from '../core/discord/addFilterOptions';
|
||||||
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import interactionToURL from '../core/discord/interactionToURL';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import linkButton from '../core/discord/linkButton';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import primaryButton from '../core/discord/primaryButton';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
import resolvePeriodFromCommand, {
|
||||||
|
ResolvedPeriod,
|
||||||
|
} from '../core/discord/resolvePeriodFromCommand';
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand, {
|
||||||
|
ResolvedPlayer,
|
||||||
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
|
import { StatFilters, filterStats } from '../core/statistics/filterStats';
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import stats, { MultiTankFilters, StatType } from '../renderers/stats';
|
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
async function render(
|
||||||
|
{ region, id }: ResolvedPlayer,
|
||||||
|
{ start, end, name }: ResolvedPeriod,
|
||||||
|
filters: StatFilters,
|
||||||
|
) {
|
||||||
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
|
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
||||||
|
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
||||||
|
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||||
|
const filterDescriptions = await filtersToDescription(filters);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Wrapper>
|
||||||
|
<TitleBar
|
||||||
|
name={nickname}
|
||||||
|
image={clanImage}
|
||||||
|
description={`${name} • ${filterDescriptions}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!stats.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
|
{stats.battles > 0 && (
|
||||||
|
<AllStatsOverview stats={stats} supplementaryStats={supplementary} />
|
||||||
|
)}
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
||||||
const command = await addStatTypeSubCommandGroups(
|
const command = await addFilterOptions(
|
||||||
new SlashCommandBuilder()
|
new SlashCommandBuilder()
|
||||||
.setName('stats')
|
.setName('stats')
|
||||||
.setDescription('Regular battles statistics'),
|
.setDescription('Regular battles statistics'),
|
||||||
|
(option) => option.addStringOption(addUsernameChoices),
|
||||||
);
|
);
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
@@ -32,60 +72,20 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
command,
|
command,
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup = interaction.options.getSubcommandGroup(
|
|
||||||
true,
|
|
||||||
) as StatType;
|
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
const player = await resolvePlayerFromCommand(interaction);
|
||||||
const resolvedPeriod = resolvePeriodFromCommand(
|
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||||
player.region,
|
const filters = await getFiltersFromCommand(interaction);
|
||||||
interaction,
|
const path = commandToURL(interaction, {
|
||||||
);
|
|
||||||
const period = interaction.options.getString('period');
|
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
|
||||||
const tankId =
|
|
||||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
|
||||||
const start = interaction.options.getInteger('start');
|
|
||||||
const end = interaction.options.getInteger('end');
|
|
||||||
const path = interactionToURL(interaction, {
|
|
||||||
...player,
|
...player,
|
||||||
tankId,
|
...getCustomPeriodParams(interaction),
|
||||||
start,
|
...filters,
|
||||||
end,
|
|
||||||
period,
|
|
||||||
});
|
});
|
||||||
const { nickname } = (
|
|
||||||
await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
|
||||||
)
|
|
||||||
)[player.id];
|
|
||||||
|
|
||||||
const tierOption = interaction.options.getString('tier');
|
return Promise.all([
|
||||||
|
render(player, period, filters),
|
||||||
return [
|
buttonRefresh(interaction, path),
|
||||||
await stats(
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
commandGroup,
|
]);
|
||||||
resolvedPeriod,
|
|
||||||
player,
|
|
||||||
commandGroup === 'tank'
|
|
||||||
? tankId
|
|
||||||
: commandGroup === 'multi-tank'
|
|
||||||
? ({
|
|
||||||
'tank-type':
|
|
||||||
interaction.options.getString('tank-type') ?? undefined,
|
|
||||||
nation: interaction.options.getString('nation') ?? undefined,
|
|
||||||
tier: tierOption ? parseInt(tierOption) : undefined,
|
|
||||||
'tree-type': (interaction.options.getString('tree-type') ??
|
|
||||||
undefined) as TreeTypeString | undefined,
|
|
||||||
} satisfies Partial<MultiTankFilters>)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
primaryButton(path, 'Refresh'),
|
|
||||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
|
||||||
linkButton(
|
|
||||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
|
||||||
'BlitzStars',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
autocomplete: (interaction) => {
|
||||||
@@ -94,27 +94,11 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async button(interaction) {
|
async button(interaction) {
|
||||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
|
||||||
const commandGroup = path[1] as StatType;
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await stats(
|
return await render(player, period, filters);
|
||||||
commandGroup,
|
|
||||||
period,
|
|
||||||
player,
|
|
||||||
commandGroup === 'tank'
|
|
||||||
? parseInt(url.searchParams.get('tankId')!)
|
|
||||||
: commandGroup === 'multi-tank'
|
|
||||||
? ({
|
|
||||||
'tank-type': url.searchParams.get('tank-type')!,
|
|
||||||
nation: url.searchParams.get('nation')!,
|
|
||||||
tier: parseInt(url.searchParams.get('tier')!),
|
|
||||||
'tree-type': url.searchParams.get('tree-type') as TreeTypeString,
|
|
||||||
} satisfies MultiTankFilters)
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
||||||
import interactionToURL from '../core/discord/interactionToURL';
|
|
||||||
import linkButton from '../core/discord/linkButton';
|
|
||||||
import primaryButton from '../core/discord/primaryButton';
|
|
||||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
import today from '../renderers/today';
|
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
|
|
||||||
export const todayCommand: CommandRegistry = {
|
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
|
||||||
.setName('today')
|
|
||||||
.setDescription('A general daily breakdown of your performance')
|
|
||||||
.addStringOption(addUsernameChoices)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('cutoff')
|
|
||||||
.setDescription(
|
|
||||||
'The maximum number of tanks to display (default: Infinity)',
|
|
||||||
)
|
|
||||||
.setRequired(false)
|
|
||||||
.setMinValue(1),
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('maximized')
|
|
||||||
.setDescription(
|
|
||||||
'The number of rows with full stats after which all are collapsed (default: 4)',
|
|
||||||
)
|
|
||||||
.setMinValue(0)
|
|
||||||
.setRequired(false),
|
|
||||||
)
|
|
||||||
.addBooleanOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('show-total')
|
|
||||||
.setDescription('Show the total stats at the top (default: true)')
|
|
||||||
.setRequired(false),
|
|
||||||
),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
|
||||||
const player = await resolvePlayerFromCommand(interaction);
|
|
||||||
const cutoff = interaction.options.getInteger('cutoff') ?? undefined;
|
|
||||||
const maximized = interaction.options.getInteger('maximized') ?? undefined;
|
|
||||||
const showTotal = interaction.options.getBoolean('show-total') ?? undefined;
|
|
||||||
const { nickname } = (
|
|
||||||
await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
|
||||||
)
|
|
||||||
)[player.id];
|
|
||||||
const path = interactionToURL(interaction, {
|
|
||||||
...player,
|
|
||||||
cutoff,
|
|
||||||
maximized,
|
|
||||||
'show-total': showTotal,
|
|
||||||
});
|
|
||||||
|
|
||||||
return [
|
|
||||||
await today(player, cutoff, maximized, showTotal, false),
|
|
||||||
primaryButton(path, 'Refresh'),
|
|
||||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
|
||||||
linkButton(
|
|
||||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
|
||||||
'BlitzStars',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
|
||||||
|
|
||||||
async button(interaction) {
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
|
||||||
|
|
||||||
return await today(player);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
|
||||||
import markdownEscape from 'markdown-escape';
|
|
||||||
import discord from '../../discord.json' assert { type: 'json' };
|
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
||||||
import embedNegative from '../core/discord/embedNegative';
|
|
||||||
import embedPositive from '../core/discord/embedPositive';
|
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
|
||||||
|
|
||||||
export const verifyCommand: CommandRegistry = {
|
|
||||||
inProduction: true,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
|
||||||
.setName('verify')
|
|
||||||
.setDescription("Set's the user's username to their in-game name")
|
|
||||||
.addStringOption((option) => addUsernameChoices(option).setRequired(true)),
|
|
||||||
|
|
||||||
async handler(interaction) {
|
|
||||||
const blitzAccount = await resolvePlayerFromCommand(interaction);
|
|
||||||
const { id, region: server } = blitzAccount;
|
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
|
||||||
);
|
|
||||||
const clan = clanData[id]?.clan;
|
|
||||||
const clanTag = clan ? ` [${clan!.tag}]` : '';
|
|
||||||
const member =
|
|
||||||
interaction.member &&
|
|
||||||
interaction.guild?.members.cache.get(interaction.member?.user.id);
|
|
||||||
|
|
||||||
if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) {
|
|
||||||
return embedNegative(
|
|
||||||
`${markdownEscape(interaction.user.username)} failed to verify`,
|
|
||||||
"I don't have the permission to change your nickname.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!interaction.member || !member) {
|
|
||||||
return embedNegative(
|
|
||||||
`${interaction.user.username} is not in this server`,
|
|
||||||
"I couldn't find this person in this server. Did they leave?",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await member.setNickname(`${accountInfo[id].nickname}${clanTag}`);
|
|
||||||
|
|
||||||
if (interaction.guildId === discord.sklld_guild_id) {
|
|
||||||
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
|
|
||||||
return embedNegative(
|
|
||||||
`${markdownEscape(interaction.user.username)} failed to verify`,
|
|
||||||
"I don't have the permission to change your manage roles.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await member.roles.remove(discord.sklld_verify_role);
|
|
||||||
await member.roles.add(discord.sklld_peasant_role);
|
|
||||||
}
|
|
||||||
|
|
||||||
return embedPositive(
|
|
||||||
`${interaction.user.username} is verified`,
|
|
||||||
`The user is now verified as ${markdownEscape(
|
|
||||||
accountInfo[id].nickname,
|
|
||||||
)}${markdownEscape(clanTag)}`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
return embedNegative(
|
|
||||||
`${interaction.user.username} failed to verify`,
|
|
||||||
"I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: autocompleteUsername,
|
|
||||||
};
|
|
||||||
@@ -1,31 +1,28 @@
|
|||||||
import { Percentile } from '../../../../../constants/percentiles';
|
|
||||||
import { PERCENTILE_COLORS } from '../../../../PercentileIndicator';
|
|
||||||
|
|
||||||
export enum GlowSide {
|
|
||||||
Top,
|
|
||||||
Bottom,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GlowProps {
|
export interface GlowProps {
|
||||||
percentile: Percentile;
|
color: string;
|
||||||
side: GlowSide;
|
direction?: 'default' | 'reverse';
|
||||||
|
rotation?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Glow({ percentile, side }: GlowProps) {
|
export function Glow({
|
||||||
const color = PERCENTILE_COLORS[percentile];
|
color,
|
||||||
|
direction = 'default',
|
||||||
|
rotation = 0,
|
||||||
|
}: GlowProps) {
|
||||||
const color1 = color;
|
const color1 = color;
|
||||||
const color2 = `${color}00`;
|
const color2 = `${color}00`;
|
||||||
|
|
||||||
const background = `linear-gradient(${
|
const background = `linear-gradient(${
|
||||||
side === GlowSide.Top ? 0 : 180
|
direction === 'default' ? 0 : 180
|
||||||
}deg, ${color1} 0%, ${color2} 100%)`;
|
}deg, ${color1} 0%, ${color2} 100%)`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: side === GlowSide.Top ? 'flex-end' : 'flex-start',
|
alignItems: direction === 'default' ? 'flex-end' : 'flex-start',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
transform: `rotate(${rotation}deg)`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ height: 54, width: 16, background }} />
|
<div style={{ height: 54, width: 16, background }} />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Percentile } from '../../../../constants/percentiles';
|
import { Percentile } from '../../../../constants/percentiles';
|
||||||
import getWN8Percentile from '../../../../core/blitz/getWN8Percentile';
|
import getWN8Percentile from '../../../../core/statistics/getWN8Percentile';
|
||||||
import { theme } from '../../../../stitches.config';
|
import { theme } from '../../../../stitches.config';
|
||||||
import { PERCENTILE_COLORS } from '../../../PercentileIndicator';
|
import { PERCENTILE_COLORS } from '../../../PercentileIndicator';
|
||||||
import { Glow, GlowSide } from './components/Glow';
|
import { Glow } from './components/Glow';
|
||||||
|
|
||||||
export interface WN8DisplayProps {
|
export interface WN8DisplayProps {
|
||||||
WN8?: number;
|
WN8?: number;
|
||||||
@@ -37,7 +37,7 @@ export function WN8Display({ WN8 }: WN8DisplayProps) {
|
|||||||
gap: -16,
|
gap: -16,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Glow percentile={percentile} side={GlowSide.Top} />
|
<Glow color={PERCENTILE_COLORS[percentile]} />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -71,7 +71,7 @@ export function WN8Display({ WN8 }: WN8DisplayProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Glow percentile={percentile} side={GlowSide.Bottom} />
|
<Glow color={PERCENTILE_COLORS[percentile]} direction="reverse" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AllStats, SupplementaryStats } from '../../types/accountInfo';
|
import { AllStats, SupplementaryStats } from '../../core/blitz/getAccountInfo';
|
||||||
import { WN8Display } from './components/WN8Display';
|
import { WN8Display } from './components/WN8Display';
|
||||||
import {
|
import {
|
||||||
WN8SurroundingStat,
|
WN8SurroundingStat,
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ export interface RootProps {
|
|||||||
|
|
||||||
export function Root({ children }: RootProps) {
|
export function Root({ children }: RootProps) {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
<div
|
||||||
|
className="session-tracker-root"
|
||||||
|
style={{ display: 'flex', flexDirection: 'column', gap: 8 }}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
import { createColors } from 'bepaint';
|
||||||
import { Percentile } from '../../../constants/percentiles';
|
import { Percentile } from '../../../constants/percentiles';
|
||||||
import { TankType } from '../../../core/blitz/tankopedia';
|
import {
|
||||||
import { theme } from '../../../stitches.config';
|
AccentColor,
|
||||||
|
GrayColor,
|
||||||
|
PALETTES,
|
||||||
|
} from '../../../constants/radixColors';
|
||||||
import { TREE_TYPE_ICONS, TreeTypeEnum } from '../../Tanks';
|
import { TREE_TYPE_ICONS, TreeTypeEnum } from '../../Tanks';
|
||||||
import { RowStat } from './RowStat';
|
import { RowStat } from './RowStat';
|
||||||
|
|
||||||
@@ -17,19 +21,30 @@ interface RowProps {
|
|||||||
title: string;
|
title: string;
|
||||||
minimized?: boolean;
|
minimized?: boolean;
|
||||||
treeType?: TreeTypeEnum;
|
treeType?: TreeTypeEnum;
|
||||||
tankType?: TankType;
|
tankType?: string;
|
||||||
|
color?: AccentColor | GrayColor;
|
||||||
stats: (RowStatItem | undefined)[];
|
stats: (RowStatItem | undefined)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Row(props: RowProps) {
|
export function Row({
|
||||||
|
color = 'slate',
|
||||||
|
stats,
|
||||||
|
title,
|
||||||
|
minimized,
|
||||||
|
tankType,
|
||||||
|
treeType,
|
||||||
|
type,
|
||||||
|
}: RowProps) {
|
||||||
|
const theme = createColors(PALETTES[`${color}Dark`]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
className="session-tracker-row"
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
backgroundColor: theme.colors.appBackground2,
|
backgroundColor: theme.appBackground2,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -40,16 +55,12 @@ export function Row(props: RowProps) {
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
padding: 8,
|
padding: 8,
|
||||||
gap: 4,
|
gap: 4,
|
||||||
backgroundColor: theme.colors.componentInteractive,
|
backgroundColor: theme.componentInteractive,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.type === 'tank' && props.tankType !== undefined && (
|
{type === 'tank' && tankType !== undefined && (
|
||||||
<img
|
<img
|
||||||
src={
|
src={TREE_TYPE_ICONS[treeType ?? TreeTypeEnum.TechTree][tankType]}
|
||||||
TREE_TYPE_ICONS[props.treeType ?? TreeTypeEnum.TechTree][
|
|
||||||
props.tankType
|
|
||||||
]
|
|
||||||
}
|
|
||||||
style={{ width: 16, height: 16 }}
|
style={{ width: 16, height: 16 }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -57,18 +68,18 @@ export function Row(props: RowProps) {
|
|||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color:
|
color:
|
||||||
props.type === 'tank'
|
type === 'tank'
|
||||||
? props.treeType === TreeTypeEnum.Collector
|
? treeType === TreeTypeEnum.Collector
|
||||||
? theme.colors.textLowContrast_blue
|
? theme.textLowContrast_blue
|
||||||
: props.treeType === TreeTypeEnum.Premium
|
: treeType === TreeTypeEnum.Premium
|
||||||
? theme.colors.textLowContrast_amber
|
? theme.textLowContrast_amber
|
||||||
: theme.colors.textHighContrast
|
: theme.textHighContrast
|
||||||
: theme.colors.textLowContrast,
|
: theme.textLowContrast,
|
||||||
fontWeight: 900,
|
fontWeight: 900,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.title}
|
{title}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -79,11 +90,11 @@ export function Row(props: RowProps) {
|
|||||||
paddingBottom: 8,
|
paddingBottom: 8,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.stats.map(
|
{stats.map(
|
||||||
(row, index) =>
|
(row, index) =>
|
||||||
row && (
|
row && (
|
||||||
<RowStat
|
<RowStat
|
||||||
minimized={props.minimized}
|
minimized={minimized}
|
||||||
key={index}
|
key={index}
|
||||||
name={`${row.title} • ${row.career ?? '--'}`}
|
name={`${row.title} • ${row.career ?? '--'}`}
|
||||||
value={row.current ?? '--'}
|
value={row.current ?? '--'}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
import { createColors } from 'bepaint';
|
||||||
import { Percentile } from '../../../constants/percentiles';
|
import { Percentile } from '../../../constants/percentiles';
|
||||||
import { theme } from '../../../stitches.config';
|
import {
|
||||||
|
AccentColor,
|
||||||
|
GrayColor,
|
||||||
|
PALETTES,
|
||||||
|
} from '../../../constants/radixColors';
|
||||||
import PercentileIndicator from '../../PercentileIndicator';
|
import PercentileIndicator from '../../PercentileIndicator';
|
||||||
|
|
||||||
export interface RowStatProps {
|
export interface RowStatProps {
|
||||||
@@ -8,6 +13,7 @@ export interface RowStatProps {
|
|||||||
delta?: number;
|
delta?: number;
|
||||||
percentile?: Percentile;
|
percentile?: Percentile;
|
||||||
minimized?: boolean;
|
minimized?: boolean;
|
||||||
|
color?: AccentColor | GrayColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RowStat({
|
export function RowStat({
|
||||||
@@ -15,10 +21,14 @@ export function RowStat({
|
|||||||
value,
|
value,
|
||||||
delta,
|
delta,
|
||||||
percentile,
|
percentile,
|
||||||
minimized,
|
minimized = false,
|
||||||
|
color = 'slate',
|
||||||
}: RowStatProps) {
|
}: RowStatProps) {
|
||||||
|
const theme = createColors(PALETTES[`${color}Dark`]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
className="session-tracker-row-stat"
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
@@ -52,7 +62,7 @@ export function RowStat({
|
|||||||
|
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: theme.colors.textHighContrast,
|
color: theme.textHighContrast,
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
@@ -65,7 +75,7 @@ export function RowStat({
|
|||||||
{!minimized && (
|
{!minimized && (
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: theme.colors.textLowContrast,
|
color: theme.textLowContrast,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export function Card({ items, title }: CardProps) {
|
|||||||
>
|
>
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<div
|
<div
|
||||||
|
key={item.label}
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: 8,
|
gap: 8,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import getWN8Percentile from '../../core/blitz/getWN8Percentile';
|
import { AllStats, SupplementaryStats } from '../../core/blitz/getAccountInfo';
|
||||||
import isNumber from '../../core/node/isNumber';
|
import isNumber from '../../core/math/isNumber';
|
||||||
import { AllStats, SupplementaryStats } from '../../types/accountInfo';
|
import getWN8Percentile from '../../core/statistics/getWN8Percentile';
|
||||||
import { Card } from './components/Card';
|
import { Card } from './components/Card';
|
||||||
import { Root } from './components/Root';
|
import { Root } from './components/Root';
|
||||||
import { Row } from './components/Row';
|
import { Row } from './components/Row';
|
||||||
|
|
||||||
// TODO: remove the .js endings
|
|
||||||
|
|
||||||
export interface GenericAllStatsProps {
|
export interface GenericAllStatsProps {
|
||||||
stats: AllStats;
|
stats: AllStats;
|
||||||
supplementaryStats?: SupplementaryStats;
|
supplementaryStats?: SupplementaryStats;
|
||||||
|
|||||||
@@ -15,9 +15,18 @@ export default function GenericStatsRow({ stat }: GenericStatsRowProps) {
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 16 }}>
|
<span
|
||||||
|
style={{
|
||||||
|
color: theme.colors.textLowContrast,
|
||||||
|
fontSize: 16,
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
maxWidth: 128,
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
{stat[0]}
|
{stat[0]}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: theme.colors.textHighContrast,
|
color: theme.colors.textHighContrast,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { theme } from '../../../stitches.config';
|
import { theme } from '../../../stitches.config';
|
||||||
|
|
||||||
export interface GapProps {
|
export interface GapProps {
|
||||||
number: number;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Gap({ number }: GapProps) {
|
export function Gap({ message: number }: GapProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -22,7 +22,7 @@ export function Gap({ number }: GapProps) {
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
+ {number.toLocaleString()} more
|
{number.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
import { ComponentProps } from 'react';
|
||||||
import { RatingsReward } from '../../../commands/ratings';
|
import { RatingsReward } from '../../../commands/ratings';
|
||||||
import { theme } from '../../../stitches.config';
|
import { theme } from '../../../stitches.config';
|
||||||
|
|
||||||
export interface ItemProps {
|
export interface ItemProps extends ComponentProps<'div'> {
|
||||||
position: number;
|
position: number;
|
||||||
deltaPosition?: number;
|
deltaPosition?: number;
|
||||||
score: number;
|
score?: number;
|
||||||
deltaScore?: number;
|
deltaScore?: number;
|
||||||
reward?: RatingsReward;
|
reward?: RatingsReward;
|
||||||
nickname: string;
|
nickname: string;
|
||||||
@@ -25,10 +26,13 @@ export function Item({
|
|||||||
nickname,
|
nickname,
|
||||||
clan,
|
clan,
|
||||||
highlight,
|
highlight,
|
||||||
|
...props
|
||||||
}: ItemProps) {
|
}: ItemProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
{...props}
|
||||||
style={{
|
style={{
|
||||||
|
cursor: 'pointer',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
padding: 8,
|
padding: 8,
|
||||||
backgroundColor: highlight
|
backgroundColor: highlight
|
||||||
@@ -185,16 +189,18 @@ export function Item({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<span
|
{score !== undefined && (
|
||||||
style={{
|
<span
|
||||||
color: highlight
|
style={{
|
||||||
? theme.colors.textHighContrast_blue
|
color: highlight
|
||||||
: theme.colors.textHighContrast,
|
? theme.colors.textHighContrast_blue
|
||||||
fontSize: 16,
|
: theme.colors.textHighContrast,
|
||||||
}}
|
fontSize: 16,
|
||||||
>
|
}}
|
||||||
{score.toLocaleString()}
|
>
|
||||||
</span>
|
{score.toLocaleString()}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,24 +1,31 @@
|
|||||||
|
import { Flex, Theme } from '@radix-ui/themes';
|
||||||
import { ComponentProps } from 'react';
|
import { ComponentProps } from 'react';
|
||||||
|
|
||||||
|
interface PageWrapperProps extends ComponentProps<typeof Flex> {
|
||||||
|
color?: ComponentProps<typeof Theme>['accentColor'];
|
||||||
|
}
|
||||||
|
|
||||||
export default function PageWrapper({
|
export default function PageWrapper({
|
||||||
style,
|
style,
|
||||||
|
color,
|
||||||
...props
|
...props
|
||||||
}: ComponentProps<'div'>) {
|
}: PageWrapperProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<Theme accentColor={color}>
|
||||||
style={{
|
<Flex
|
||||||
width: '100%',
|
{...props}
|
||||||
maxWidth: 800,
|
direction="column"
|
||||||
margin: 'auto',
|
gap="4"
|
||||||
display: 'flex',
|
style={{
|
||||||
padding: 16,
|
width: '100%',
|
||||||
flexDirection: 'column',
|
maxWidth: 800,
|
||||||
gap: 16,
|
margin: 'auto',
|
||||||
boxSizing: 'border-box',
|
padding: 16,
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
|
||||||
...style,
|
...style,
|
||||||
}}
|
}}
|
||||||
{...props}
|
/>
|
||||||
/>
|
</Theme>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { slateDarkA } from '@radix-ui/colors';
|
||||||
|
import { keyframes, style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
|
const animation = keyframes({
|
||||||
|
'0%': { backgroundColor: slateDarkA.slateA2 },
|
||||||
|
'50%': { backgroundColor: slateDarkA.slateA3 },
|
||||||
|
'100%': { backgroundColor: slateDarkA.slateA2 },
|
||||||
|
});
|
||||||
|
|
||||||
|
export const skeleton = style({
|
||||||
|
borderRadius: 8,
|
||||||
|
animation: `${animation} 2s ease-in-out infinite`,
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { ComponentProps } from 'react';
|
||||||
|
import { skeleton } from './index.css';
|
||||||
|
|
||||||
|
export function Skeleton({ className, ...props }: ComponentProps<'div'>) {
|
||||||
|
return <div {...props} className={`${className} ${skeleton}`} />;
|
||||||
|
}
|
||||||
@@ -2,8 +2,7 @@ import {
|
|||||||
TANK_ICONS,
|
TANK_ICONS,
|
||||||
TANK_ICONS_COLLECTOR,
|
TANK_ICONS_COLLECTOR,
|
||||||
TANK_ICONS_PREMIUM,
|
TANK_ICONS_PREMIUM,
|
||||||
TankType,
|
} from '../../../core/blitzstars/tankopedia';
|
||||||
} from '../../../core/blitz/tankopedia';
|
|
||||||
import { theme } from '../../../stitches.config';
|
import { theme } from '../../../stitches.config';
|
||||||
|
|
||||||
export enum TreeTypeEnum {
|
export enum TreeTypeEnum {
|
||||||
@@ -12,11 +11,17 @@ export enum TreeTypeEnum {
|
|||||||
Collector,
|
Collector,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TreeTypeString = 'techtree' | 'premium' | 'collector';
|
export type TreeTypeString = 'tech-tree' | 'premium' | 'collector';
|
||||||
|
|
||||||
|
export const TREE_TYPE_NAMES: Record<TreeTypeString, string> = {
|
||||||
|
'tech-tree': 'Tech tree',
|
||||||
|
premium: 'Premium',
|
||||||
|
collector: 'Collector',
|
||||||
|
};
|
||||||
|
|
||||||
export interface ItemProps {
|
export interface ItemProps {
|
||||||
image?: string;
|
image?: string;
|
||||||
tankType?: TankType;
|
tankType?: string;
|
||||||
name: string;
|
name: string;
|
||||||
treeType: TreeTypeEnum;
|
treeType: TreeTypeEnum;
|
||||||
}
|
}
|
||||||
@@ -75,7 +80,15 @@ export function Item({ image, tankType, name, treeType }: ItemProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{image && <img src={image} style={{ flex: 1 }} />}
|
{/* {image && (
|
||||||
|
// TODO: remove hardcoded dimensions when satori fixes non-width unloadable images
|
||||||
|
<img
|
||||||
|
src={image}
|
||||||
|
width={106}
|
||||||
|
height={32}
|
||||||
|
style={{ objectFit: 'cover' }}
|
||||||
|
/>
|
||||||
|
)} */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||