mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c2861f956 | ||
|
|
894b841769 | ||
|
|
62627c96a3 | ||
|
|
c173ece882 | ||
|
|
eca7cbbbeb | ||
|
|
c72bfa9f71 | ||
|
|
b4ae39a509 | ||
|
|
631c051895 | ||
|
|
9a2e11a2a4 | ||
|
|
aa6011b18d | ||
|
|
9419aec116 | ||
|
|
638402589f | ||
|
|
6d6a6bf738 | ||
|
|
31f6123a55 | ||
|
|
18a3e3092c | ||
|
|
5ded0f8744 | ||
|
|
4e0f0536fa | ||
|
|
3f081a5577 | ||
|
|
2447d663fa | ||
|
|
8a0afee97a | ||
|
|
3cca68a8f0 | ||
|
|
622cd92a13 | ||
|
|
6d9e6973d5 | ||
|
|
098e6c09b9 | ||
|
|
186d45e3d9 | ||
|
|
0fdc87a88c | ||
|
|
1d4ac2f133 | ||
|
|
21158e9081 | ||
|
|
fedad8df3e | ||
|
|
6c8f5ca478 | ||
|
|
463af106be | ||
|
|
feeb850ca9 | ||
|
|
80ffff322c | ||
|
|
0833375562 | ||
|
|
297f2f6580 | ||
|
|
438feefa83 | ||
|
|
8f6388b42b | ||
|
|
405f544774 | ||
|
|
dd0644e09f | ||
|
|
d8ac0b2ef6 | ||
|
|
87955214e3 | ||
|
|
f985cbf70b | ||
|
|
f64e72c312 | ||
|
|
ce6715cf2c | ||
|
|
18e5405c54 | ||
|
|
a0f15fc1c4 | ||
|
|
cf20ae38d4 | ||
|
|
2bf5eb78be | ||
|
|
57271e3c23 | ||
|
|
2258b0f936 | ||
|
|
aa8115d260 | ||
|
|
f8dfa386a0 | ||
|
|
00771e130f | ||
|
|
bd612bf777 | ||
|
|
ca208e44a1 | ||
|
|
72c4cd664b | ||
|
|
f907c79d68 | ||
|
|
ae3d0a08cd | ||
|
|
fb66027de0 | ||
|
|
423ad4e433 | ||
|
|
cf291c89a2 | ||
|
|
604e356736 | ||
|
|
00b721f34f | ||
|
|
95b105cb65 | ||
|
|
433ffba1e3 | ||
|
|
423a8b8088 | ||
|
|
d2d575bd72 | ||
|
|
2958124499 | ||
|
|
5addc55dd0 | ||
|
|
c78e58106a | ||
|
|
798f063712 | ||
|
|
ff99487b13 | ||
|
|
0c58515fd0 | ||
|
|
c39a59d321 | ||
|
|
3167e311c2 | ||
|
|
7b17d3f96e | ||
|
|
ac87a9d919 | ||
|
|
25ea608d81 | ||
|
|
ebe1fb891b | ||
|
|
931257d18d | ||
|
|
ae66fc92ef | ||
|
|
fc4390d22f | ||
|
|
4c2b0253de | ||
|
|
e34a6c6e4b | ||
|
|
90d4b76b31 | ||
|
|
3fd90588a3 | ||
|
|
e81c0cbc1e | ||
|
|
4c9715988d | ||
|
|
c2d2d076f0 | ||
|
|
d1d8aad6c7 | ||
|
|
dd39563d6d | ||
|
|
64fd15c0a5 | ||
|
|
5fb36352d2 | ||
|
|
8bf8030157 | ||
|
|
da950ad42f | ||
|
|
f8f95af215 | ||
|
|
a0ba60a3fb | ||
|
|
ab5061ba99 | ||
|
|
01ed20941d | ||
|
|
169588a211 | ||
|
|
c7821d03d2 | ||
|
|
9dc48c9125 | ||
|
|
a67d1700fc | ||
|
|
c221c06511 | ||
|
|
abcb75f06e | ||
|
|
7dd3913ae8 | ||
|
|
f2ae698438 | ||
|
|
0f46f333b5 | ||
|
|
79343438f0 | ||
|
|
8dd0ca9d10 | ||
|
|
aa0069a0a3 | ||
|
|
8882c28267 | ||
|
|
24cf2c2cd9 | ||
|
|
8570559588 | ||
|
|
d8f53bff9f | ||
|
|
58f5b894f9 | ||
|
|
ae2d12a629 | ||
|
|
05a25c7454 | ||
|
|
b84f2e7adc | ||
|
|
e7fafa6902 | ||
|
|
8b9f665d47 | ||
|
|
f134efa1e8 | ||
|
|
d8a78bc25e | ||
|
|
752f9b339b | ||
|
|
bcbc1e259f | ||
|
|
91da65196d | ||
|
|
e49bd6aa68 | ||
|
|
6f21789c46 | ||
|
|
3e8e198c88 | ||
|
|
70145abe86 | ||
|
|
35f0f614af | ||
|
|
d9690460d5 | ||
|
|
0cf0e63fda | ||
|
|
e0c1db2a0b | ||
|
|
78424c1535 | ||
|
|
78d429808a | ||
|
|
1c4cb67a6a | ||
|
|
6f90d4fb75 | ||
|
|
21c094a76b | ||
|
|
5e98bc988c | ||
|
|
f6480ad66f | ||
|
|
4d9dc067af | ||
|
|
fbcd9e82e3 | ||
|
|
568ffa06e3 | ||
|
|
e3b1df0a46 | ||
|
|
68ee95c327 | ||
|
|
858efbcdfe |
No files matched your search
@@ -0,0 +1,34 @@
|
||||
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
|
||||
@@ -0,0 +1,34 @@
|
||||
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
|
||||
@@ -0,0 +1,60 @@
|
||||
name: CD Docs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
||||
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: Build docs
|
||||
run: yarn build:docs
|
||||
|
||||
- name: Configure pages
|
||||
uses: actions/configure-pages@v2
|
||||
|
||||
- name: Upload pages artifact
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
with:
|
||||
path: docs/.vitepress/dist
|
||||
|
||||
- name: Deploy
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v1
|
||||
|
||||
- name: Archive build
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: docs/.vitepress/dist
|
||||
@@ -0,0 +1,34 @@
|
||||
name: CD Europe 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=eu --latest
|
||||
@@ -0,0 +1,34 @@
|
||||
name: CD Europe Ratings Leaderboards
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 23 * * *"
|
||||
|
||||
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=eu
|
||||
@@ -0,0 +1,32 @@
|
||||
name: CD Host
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 */5 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
host:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Use node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Download release assets
|
||||
run: |
|
||||
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/tresabhi/blitzkrieg/releases/latest \
|
||||
| grep "browser_download_url.*dist.zip" \
|
||||
| cut -d : -f 2,3 \
|
||||
| tr -d \")
|
||||
curl -L -o dist.zip $DOWNLOAD_URL
|
||||
unzip dist.zip
|
||||
|
||||
- name: Run bot
|
||||
run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} node --enable-source-maps --trace-warnings bot.cjs
|
||||
@@ -0,0 +1,34 @@
|
||||
name: CD North America 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=na --latest
|
||||
@@ -0,0 +1,34 @@
|
||||
name: CD North America Ratings Leaderboards
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 5 * * *'
|
||||
|
||||
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=na
|
||||
@@ -11,18 +11,14 @@ jobs:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
|
||||
steps:
|
||||
- name: Get code
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Use node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
node-version: 18
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Yarn
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
name: Host
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '50 */5 * * *'
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
host:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Use node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Get latest release
|
||||
uses: actions/github-script@v4
|
||||
with:
|
||||
script: |
|
||||
const response = await github.repos.getLatestRelease({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo
|
||||
});
|
||||
console.log(response.data.assets[0].browser_download_url);
|
||||
core.setOutput("download_url", response.data.assets[0].browser_download_url);
|
||||
|
||||
- name: Download release assets
|
||||
run: |
|
||||
curl -L -o dist.zip ${{ steps.get-latest-release.outputs.download_url }}
|
||||
unzip dist.zip
|
||||
|
||||
- name: Run index.cjs
|
||||
run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} node --enable-source-maps dist/index.cjs
|
||||
+6
-1
@@ -5,5 +5,10 @@ package-lock.json
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
||||
dist/
|
||||
dist.*
|
||||
yarn-error.log
|
||||
dist.zip
|
||||
commands.txt
|
||||
/test.*
|
||||
/docs/.vitepress/dist
|
||||
/docs/.vitepress/cache
|
||||
servers.csv
|
||||
Vendored
+20
@@ -3,22 +3,42 @@
|
||||
"Abhi",
|
||||
"accountinfo",
|
||||
"bepaint",
|
||||
"blitzstars",
|
||||
"cleandist",
|
||||
"customperiod",
|
||||
"Everytime",
|
||||
"fullstats",
|
||||
"fuzzysort",
|
||||
"kranvagn",
|
||||
"Leaderboard",
|
||||
"leaderboards",
|
||||
"outfile",
|
||||
"ownedtanks",
|
||||
"playerachievements",
|
||||
"playerinfo",
|
||||
"ratingsleaderboard",
|
||||
"Resvg",
|
||||
"roboto",
|
||||
"searchclans",
|
||||
"searchplayers",
|
||||
"searchtanks",
|
||||
"SKLLD",
|
||||
"Smri",
|
||||
"startcase",
|
||||
"statsfull",
|
||||
"Stringifying",
|
||||
"strvk",
|
||||
"subnation",
|
||||
"tankaverages",
|
||||
"tankopedia",
|
||||
"tankstats",
|
||||
"tresabhi",
|
||||
"Unicum",
|
||||
"Unregistering",
|
||||
"vickers",
|
||||
"vitepress",
|
||||
"wargaming",
|
||||
"webp",
|
||||
"winrate"
|
||||
],
|
||||
"deno.enable": false,
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
the [Official Discord Server](https://discord.gg/nDt7AjGJQH).
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 TrèsAbhi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,25 @@
|
||||
import { DefaultTheme, defineConfig } from 'vitepress';
|
||||
import { getSidebar } from 'vitepress-plugin-auto-sidebar';
|
||||
|
||||
export default defineConfig({
|
||||
title: 'blitzkrieg',
|
||||
description: '🎉 All-in-one Discord bot for everything World of Tanks Blitz',
|
||||
base: '/blitzkrieg/',
|
||||
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Home', link: '/' },
|
||||
{ text: 'Examples', link: '/markdown-examples' },
|
||||
],
|
||||
|
||||
sidebar: getSidebar({
|
||||
collapsed: false,
|
||||
contentDirs: ['guide', 'legal', 'changelogs'],
|
||||
contentRoot: '/docs/',
|
||||
}) as DefaultTheme.Sidebar,
|
||||
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
// https://vitepress.dev/guide/custom-theme
|
||||
import { h } from 'vue';
|
||||
import Theme from 'vitepress/theme';
|
||||
import './style.css';
|
||||
|
||||
export default {
|
||||
extends: Theme,
|
||||
Layout: () => {
|
||||
return h(Theme.Layout, null, {
|
||||
// https://vitepress.dev/guide/extending-default-theme#layout-slots
|
||||
});
|
||||
},
|
||||
enhanceApp({ app, router, siteData }) {
|
||||
// ...
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Customize default theme styling by overriding CSS variables:
|
||||
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
||||
*/
|
||||
|
||||
/**
|
||||
* Colors
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-c-brand: #646cff;
|
||||
--vp-c-brand-light: #747bff;
|
||||
--vp-c-brand-lighter: #9499ff;
|
||||
--vp-c-brand-lightest: #bcc0ff;
|
||||
--vp-c-brand-dark: #535bf2;
|
||||
--vp-c-brand-darker: #454ce1;
|
||||
--vp-c-brand-dimm: rgba(100, 108, 255, 0.08);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Button
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-button-brand-border: var(--vp-c-brand-light);
|
||||
--vp-button-brand-text: var(--vp-c-white);
|
||||
--vp-button-brand-bg: var(--vp-c-brand);
|
||||
--vp-button-brand-hover-border: var(--vp-c-brand-light);
|
||||
--vp-button-brand-hover-text: var(--vp-c-white);
|
||||
--vp-button-brand-hover-bg: var(--vp-c-brand-light);
|
||||
--vp-button-brand-active-border: var(--vp-c-brand-light);
|
||||
--vp-button-brand-active-text: var(--vp-c-white);
|
||||
--vp-button-brand-active-bg: var(--vp-button-brand-bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Home
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-home-hero-name-color: transparent;
|
||||
--vp-home-hero-name-background: -webkit-linear-gradient(
|
||||
120deg,
|
||||
#bd34fe 30%,
|
||||
#41d1ff
|
||||
);
|
||||
|
||||
--vp-home-hero-image-background-image: linear-gradient(
|
||||
-45deg,
|
||||
#bd34fe 50%,
|
||||
#47caff 50%
|
||||
);
|
||||
--vp-home-hero-image-filter: blur(40px);
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(56px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(72px);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Custom Block
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
:root {
|
||||
--vp-custom-block-tip-border: var(--vp-c-brand);
|
||||
--vp-custom-block-tip-text: var(--vp-c-brand-darker);
|
||||
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-custom-block-tip-border: var(--vp-c-brand);
|
||||
--vp-custom-block-tip-text: var(--vp-c-brand-lightest);
|
||||
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component: Algolia
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
.DocSearch {
|
||||
--docsearch-primary-color: var(--vp-c-brand) !important;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# Blitzkrieg 1.10.0
|
||||
|
||||
This update addresses many readability issues that users have reported over time.
|
||||
|
||||
## Changes
|
||||
|
||||
- `/ownedtanks`
|
||||
- Tanks are now displayed in two columns
|
||||
- Collector and premium tanks now have their own colors
|
||||
- Tank types are also displayed
|
||||
- A stylistic image of the tank is also displayed for each tank to the right
|
||||
- `/fullstats`
|
||||
- Was previously called `/statsfull`; this was changed to avoid the clutter that would show up when searching for `/stats`
|
||||
- Added four catagories in which all the stats are sorted into
|
||||
- Catagories now have backgrounds to compartmentalize them
|
||||
- `/evolution`
|
||||
- Gave the axis markings a high contrast color
|
||||
- Added a label for the x axis affirming that it is plotted over the number of battles
|
||||
- `/today`
|
||||
- Added a border to all the rows to compartmentalize them
|
||||
- This command can now generate embeds too
|
||||
- Removed survivability
|
||||
- Added a limit option to cut off after a certain number of tanks played (this is mainly intended to be used by streamers to limit the content of the embeds)
|
||||
- Tanks are now displayed in order of the most recent battle
|
||||
- `/help`
|
||||
- A significant amount of subcommands were added
|
||||
- These new subcommands now return normal Discord messages instead of embeds in favor of readability
|
||||
- The contents of the replies are directly fetched from the Blitzkrieg documentation
|
||||
- Time zones
|
||||
- What is considered a "day's worth of battles" has been adjusted as the "reset time" was the same for all Blitz servers
|
||||
- The reset time is now dependent on the server of the player
|
||||
- Use `/help timezones` to learn more
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- All themes have been merged to leverage Bepaint's suffixes
|
||||
- Switched to Node module resolution
|
||||
@@ -0,0 +1,7 @@
|
||||
# Blitzkrieg 1.10.1
|
||||
|
||||
This is a bit of an experiment.
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Every midnight in the Central North American Time, a permanent record of the entire ratings leaderboard will be stored for North America
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blitzkrieg 1.10.2
|
||||
|
||||
The experiment in Blitzkrieg `1.10.1` was a bit of a failure so here are a few changes.
|
||||
|
||||
## Fixes
|
||||
|
||||
- North American leaderboards are now saved in the `na` directory instead of `asia`
|
||||
- Dependencies are now installed before the script is ran
|
||||
- Added leaderboards for all regions
|
||||
- All regions now have their own separate cron timings
|
||||
@@ -0,0 +1,22 @@
|
||||
# Blitzkrieg 1.11.0
|
||||
|
||||
I am going on vacation so I thought I'd publish this a bit prematurely without all the planned features.
|
||||
|
||||
## Changes
|
||||
|
||||
- Added `/ratings`
|
||||
- This command currently only has the `leagues` subcommand group
|
||||
- Displays the top players in a league
|
||||
- Also shows the changes in their positions and scores since last region midnight
|
||||
- Use `/help timezones` to know when Blitzkrieg records the leaderboard
|
||||
- Blitzkrieg now internally generates and keeps a permanent record of all leaderboards updated every `UTC+0` midnight
|
||||
- This approach will allow us to capture the absolute latest state of the leaderboard before it is wiped for the next season
|
||||
|
||||
## Fixed
|
||||
|
||||
- Removed region "Europe" in `/verify` example
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Add scripts were upgraded to TypeScript
|
||||
- Secrets now only throw errors if they're used when not provided
|
||||
@@ -0,0 +1,9 @@
|
||||
# Blitzkrieg 1.3.0
|
||||
|
||||
This release of Blitzkrieg focuses mainly on **performance**. Blitzkrieg now uses **Satori** and **resvg** under the hood to render images resulting in a solid **2x to 8x performance boost** depending on the situation.
|
||||
|
||||
This only applies to `/today` and /stats` as they're the only commands that render an image currently.
|
||||
|
||||
We're working further on **performance optimizations**. Our goal is to deliver a message within **3 seconds or less**. We're close and we'll get there!
|
||||
|
||||
**Thank you to ba·ka**, the creator of aftermath, for telling me about Satori!
|
||||
@@ -0,0 +1,8 @@
|
||||
# Blitzkrieg 1.3.1
|
||||
|
||||
In this **minor update**, Blitzkrieg received several little **safety features** and **bug fixes**!
|
||||
|
||||
- The bot is now more verbose
|
||||
- Every time you use a command, the bot will now store data on what parameters you provided and if any errors were caused
|
||||
- This update also eliminates the redundant usage of truthy type checking after API calls
|
||||
- _Hopefully_ the bot let you know why it won't respond to you
|
||||
@@ -0,0 +1,5 @@
|
||||
# Blitzkrieg 1.3.2
|
||||
|
||||
From now on, I **won't be pinging** the Blitzkrieg role for minor updates. Anyway, this **minor update** includes an optimization for `/today`. The tank icons on the left were fetched every time someone used the command. The bot now caches those images allowing for an instantaneous load.
|
||||
|
||||
I noticed rendering times up to `3000ms` for rendering stats of about 10 tanks. Cached images should now be indifferent to this.
|
||||
@@ -0,0 +1,8 @@
|
||||
# Blitzkrieg 1.3.3
|
||||
|
||||
This **minor update** fixes a few things :partying_face:
|
||||
|
||||
- Rating battles now no longer count in `/today`
|
||||
- This resolves the issue where some tanks had `NaN` stats
|
||||
- Stats with the value of `-Infinity` are now ommited
|
||||
- Images are not longer cached in `dev` `env`
|
||||
@@ -0,0 +1,28 @@
|
||||
# Blitzkrieg 1.4.0
|
||||
|
||||
A **few features** :star: and a **few much needed fixes** :wrench:!
|
||||
|
||||
## Changes
|
||||
|
||||
- Added an "today" row to `/today` which displays your overall statistics
|
||||
- Gave `/tankstats` the new blitzkrieg look
|
||||
- Also added "today", "60 days", and "career" stats
|
||||
- Added a beta warning to generated images
|
||||
- Updated the logo for match the new slate theme
|
||||
- Canary versions now use the canary logo variant
|
||||
- Added subtle polka dots to the background
|
||||
|
||||
## Fixes
|
||||
|
||||
- Rewrote `/stats` to precisely calculate stats on a per-tank basis
|
||||
- This should stop the bot from hallucinating about stats
|
||||
- This should also stop the bot from giving stats from like a week ago
|
||||
- Also added "60 day" stats
|
||||
- Tank autocomplete is now more human-tolerant just like username autocomplete
|
||||
- Titlebar discriminators are now truncated on overflow
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- The bot now uses `bepaint`, a library that I made that standardizes the color palette
|
||||
- Also updated the logo to follow this
|
||||
- Optimized how fonts are imported by fetching them all asynchronously
|
||||
@@ -0,0 +1,3 @@
|
||||
# Blitzkrieg 1.4.1
|
||||
|
||||
A quick fix for the `/help` command not accepting the new theme colors.
|
||||
@@ -0,0 +1,23 @@
|
||||
# Blitzkrieg 1.5.0
|
||||
|
||||
So so many **quality-of-life** changes and nasty **bug squashes**!
|
||||
|
||||
## Changes
|
||||
|
||||
- Added WN8 to `/today`, `/stats`, and `/tankstats`
|
||||
- Added average tier to `/stats` and `/tankstats`
|
||||
- Average tier in `/tankstats` is simply the tier of the tank that you are looking up
|
||||
- Added an indicator of WN8 ranging from "very bad" (gray) to "super unicum" (purple)
|
||||
- Replaced ellipses with simple clipping
|
||||
- Added a "large image" warning to `/today` if displaying `6` or more tanks
|
||||
|
||||
## Fixes
|
||||
|
||||
- Removed random 0 that'd show up in `/today` where there was no difference between career and today's stats
|
||||
- Added stricter checks for username autocomplete via a new REGEX pattern
|
||||
- Fixed wonky ellipses that'd cut off usernames, tank names, and clan names unnecessarily
|
||||
- Fixed the delta indicator showing up in battle counts
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Optimized and cleaned up tankopedia cache
|
||||
@@ -0,0 +1,3 @@
|
||||
# Blitzkrieg 1.5.1
|
||||
|
||||
An emergency patch that fixes failed image caching.
|
||||
@@ -0,0 +1,14 @@
|
||||
# Blitzkrieg 1.5.2
|
||||
|
||||
Quite a few **bug fixes** with a **bunch more** on their way next update!
|
||||
|
||||
## Fixes
|
||||
|
||||
- Disabled image encoding as it seems to have broken in `1.5.0` and simply spams the console now
|
||||
- `/stats` now ignores tanks that don't have any averages
|
||||
- Tanks may not have averages registered in Blitz Stars because they are new or are in testing
|
||||
- Take a look at \_34's testing tanks in the image below
|
||||
- Fixed the "large image" prompt by simply removing the whole prompt
|
||||
- _Kaboom? Yes Rico, kaboom._
|
||||
- `/today` now displays `--` when there is no WN8 to display
|
||||
- This is unlike `/stats` which just shows 0 (this will be fixed soon)
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blitzkrieg 1.5.3
|
||||
|
||||
Just a few more fixes that weren't that important so were deffered to this update.
|
||||
|
||||
## Fixes
|
||||
|
||||
- `/stats` now uses `--` just like `/today` when WN8 is not available
|
||||
- Removed an unnecessary try/catch during the execution of a command
|
||||
- Added error handling for an edge case where accounts with 0 battles were looked up
|
||||
- This only applies to when `api/tanks/stats` is fetched; most other commands still need this fix
|
||||
@@ -0,0 +1,8 @@
|
||||
# Blitzkrieg 1.5.4
|
||||
|
||||
A last batch of fixes before the next update!
|
||||
|
||||
## Fixes
|
||||
|
||||
- Career WN8 in the `/today` command now accumulates the WN8 for all tanks instead of just the ones shown
|
||||
- WN8 and average tiers are now displayed in `/stats` in the `career` period
|
||||
@@ -0,0 +1,25 @@
|
||||
# Blitzkrieg 1.6.0
|
||||
|
||||
Spread the beauty! Spread the ease!
|
||||
|
||||
## Features
|
||||
|
||||
- Commands no longer require you to provide an username
|
||||
- They are automatically inferred from your Discord nickname
|
||||
- Re-implemented the `/eligible` command
|
||||
- This command checks a player's eligibility for any of the Skilled clans
|
||||
- This command is only available in the [Skilled](https://discord.gg/ZPvcEG7DS8) and [TresAbhi Discord](https://discord.gg/nDt7AjGJQH) servers
|
||||
- Gave `/ownedtanks` and `/inactive` the new Blitzkrieg look
|
||||
- Added "Powered by Wargaming" to commands where Blitz Stars is not utilized
|
||||
|
||||
## Fixes
|
||||
|
||||
- Removed image encoding all together
|
||||
- As it turns out, encoding them in `base64` made rendering slower!
|
||||
- Tank images in `/today` now don't make parent rows incorrectly taller
|
||||
- Added a "No tanks found" when a player does not own tanks in a tier
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Added a mature error handling system
|
||||
- Commands can now just `throw errorWithCause(...)` without caring about the error reporting to the user
|
||||
@@ -0,0 +1,20 @@
|
||||
# Blitzkrieg 1.7.0
|
||||
|
||||
This is mostly a technical update to make migrating to cyclic.sh easier.
|
||||
|
||||
## Changes
|
||||
|
||||
- The bot's new deferred caching approach allows the bot to start up almost `4x` as fast
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Made numerous caches non-blocking
|
||||
- Removed an unnecessary root-blocking await where fonts are imported
|
||||
- Further improved performance by deferring font imports until after the declaration
|
||||
- Tank averages and tankopedia are now declared fully empty only to be populated after a deferred fetch
|
||||
- Reordered error handler, client login, and client event listener registration orders
|
||||
- Removed `vite` all together
|
||||
- This reduces bundle sizes
|
||||
- To do this, a more primitive way of importing commands is used
|
||||
- Removed the redundant usage of `args` to get the Discord token and Wargaming Application ID on each use
|
||||
- Added a build script using `esbuild`
|
||||
@@ -0,0 +1,3 @@
|
||||
# Blitzkrieg 1.7.1
|
||||
|
||||
A hot fix to bring the bot back online with `vite-node`.
|
||||
@@ -0,0 +1,7 @@
|
||||
# Blitzkrieg 1.7.2
|
||||
|
||||
A quick, tiny, cute bug fix
|
||||
|
||||
## Fixes
|
||||
|
||||
- Tanks now once again show up in `/tankstats`
|
||||
@@ -0,0 +1,3 @@
|
||||
# Blitzkrieg 1.7.3 & 1.7.4
|
||||
|
||||
These minor updates fix compatibility issues with cyclic.
|
||||
@@ -0,0 +1,11 @@
|
||||
# Blitzkrieg 1.7.5
|
||||
|
||||
This minor release aids the migration to build-based hosting.
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Removed `env` logging
|
||||
- Fixed constant IDs and token naming conventions
|
||||
- Moved `esbuild` to a `js` script
|
||||
- Updated the workflow to use the latest binaries
|
||||
- Added a `zip` command for `dist`
|
||||
@@ -0,0 +1,14 @@
|
||||
# Blitzkrieg 1.7.6
|
||||
|
||||
Public service announcements and a few developer quality-of-life changes.
|
||||
|
||||
## Changes
|
||||
|
||||
- Added a PSA system
|
||||
- Lets me create announcements without having to release a new update every single time
|
||||
- Added fixed choices for tank stats instead of typing in numbers like before
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Command executions now return a payload and the executor now fully handles the interaction replies
|
||||
- The build script now skips certain steps to speed up building time when building in dev mode
|
||||
@@ -0,0 +1,7 @@
|
||||
# Blitzkrieg 1.7.7
|
||||
|
||||
A tiny fix related to hosting.
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- `index.cjs` is now run at root instead of `dist`
|
||||
@@ -0,0 +1,26 @@
|
||||
# Blitzkrieg 1.8.0
|
||||
|
||||
A slick new command and new potentials unlocked.
|
||||
|
||||
## Changes
|
||||
|
||||
- Added `/ping`
|
||||
- Allows you to see if the bot and Blitz are alive
|
||||
- Added custom periods for `/stats`
|
||||
- To do this, `/stats` received two sub command groups: `/stats player` and `/stats tank` (hence merging the two)
|
||||
- All periods, including cusotm ones, now live as subcommands
|
||||
- Added tier weights to `/stats`
|
||||
- Added `/evolution`
|
||||
- Shows your winrate and battles over a period
|
||||
|
||||
## Fixes
|
||||
|
||||
- `Infinity` and `NaN` values now show up as `--` in `/stats`
|
||||
- WN8 shortcomings in `/eligible` now rounds to nearest integer
|
||||
- Average tiers now, once again, show up in `/stats`
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Dev command names are implemented centrally in `interactionCreated`
|
||||
- Abstracted the renderers of `/stats`, `/evolution`, and `/today`
|
||||
- The bot now logs the number of server it's in on start up
|
||||
@@ -0,0 +1,7 @@
|
||||
# Blitzkrieg 1.8.1
|
||||
|
||||
A tiny oversight fixed.
|
||||
|
||||
# Fixes
|
||||
|
||||
- The min and max dates now show up in `/evolution`
|
||||
@@ -0,0 +1,32 @@
|
||||
# Blitzkrieg 1.9.0
|
||||
|
||||
The biggest, the baddest update yet!
|
||||
|
||||
## Changes
|
||||
|
||||
- Spiced up `/stats` with a graphics update
|
||||
- This command now only shows a few of the stats as most of them were pretty pointless
|
||||
- Renamed the old `/stats` to `/statsfull`
|
||||
- Added embeds for `/stats`
|
||||
- This is a URL that can be visited to load a "naked" variant of the command that auto-refreshes with the latest data every `60` seconds meant to be used the streamers
|
||||
- Added refresh buttons to a few commands
|
||||
- This lets you reuse a command on the click of a button
|
||||
- Fixed many readibility issues with `/evolution` thanks to @heldenklage
|
||||
|
||||
## Fixes
|
||||
|
||||
- Fixed several type issues for compatibility with `express`
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Added a seperate `server.ts` from `bot.ts`
|
||||
- Split builds appropriately
|
||||
- Added the ability for routes to respond with svg counterparts of commands
|
||||
- Cached `tankopedia.json` and `tankaverages.json` at build time
|
||||
- This may be reverted in a minor release i favor of `Promise<Tankopedia>`
|
||||
- Organized files as it was important to seperate the server and the bot code
|
||||
- Split `resolvePeriod` and `resolvePlayer` for command, button, and express counterparts
|
||||
- Switched a few instances of `Number(...)` to `parseInt(...)` and `parseLong(...)`
|
||||
- Disabled canary commands for the public
|
||||
- Merged `poweredBy` footers
|
||||
- `dist` now ships with a `package.json` for Cyclic
|
||||
@@ -0,0 +1,3 @@
|
||||
# Blitzkrieg 1.9.1
|
||||
|
||||
Created a website for Blitzkrieg! Check it out: https://tresabhi.github.io/blitzkrieg/
|
||||
@@ -0,0 +1,5 @@
|
||||
# Blitzkrieg 1.9.2
|
||||
|
||||
## Fixes
|
||||
|
||||
- Implemented `/blitzkrieg/` as the base path
|
||||
@@ -0,0 +1,14 @@
|
||||
# Blitzkrieg 1.9.3
|
||||
|
||||
A few fixes before we tackle the next major release.
|
||||
|
||||
## Fixes
|
||||
|
||||
- `/stats`, `/evolution`, and `/statsfull` now properly handle unowned or unplayed tanks
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Added a `Command` suffix after all command exports
|
||||
- Added a `Route` suffix after all route exports
|
||||
- Moved `tankopedia` and `tankaverages` into a runtime cache
|
||||
- But, this time, it's a promise so we get the best of both worlds
|
||||
@@ -0,0 +1,12 @@
|
||||
# Blitzkrieg 1.9.4
|
||||
|
||||
Haha, I lied. More fixes.
|
||||
|
||||
## Fixes
|
||||
|
||||
- Tank names once again show when searching for tank stats
|
||||
- Tier weights now ignore tanks without entries in the `tankopedia`
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- All `tankopedia` derivatives are now promises
|
||||
@@ -0,0 +1,9 @@
|
||||
# Blitzkrieg 1.9.5
|
||||
|
||||
Hopefully this is the last round of fixes for Blitzkrieg `1.9`.
|
||||
|
||||
## Fixes
|
||||
|
||||
- All commands have been tweaked to work even with a lack of a tankopedia entry
|
||||
- This should fix test tanks not showing up
|
||||
- `/today` now properly preserves all WN8 entries
|
||||
@@ -0,0 +1,10 @@
|
||||
# About
|
||||
|
||||
Blitzkrieg is a multipurpose bot for anything and everything World of Tanks Blitz.
|
||||
|
||||
- Track statistics
|
||||
- Find inactive players in a clan
|
||||
- Lookup owned tanks
|
||||
- Create embeds for streams
|
||||
- Track a player/tanks statistical evolution
|
||||
- ...and a variety of other similar things
|
||||
@@ -0,0 +1,23 @@
|
||||
# Embeds
|
||||
|
||||
Embeds are generated by a few commands as a URL that can be loaded in a browser/streaming software.
|
||||
|
||||
## Creating Embeds
|
||||
|
||||
1. Use a command of your liking (for example, `/stats`).
|
||||
2. Customize the command however you like and the URL generated for the embed will match your needs.
|
||||
3. Send the command and when the bot is "done thinking," an "Embed" button will appear below the bot's reply.
|
||||
|
||||
## Using Embeds in Streaming Softwares
|
||||
|
||||
1. Click on the "Embed" button.
|
||||
2. Copy the URL from your browser.
|
||||
3. Paste the URL into a Browser Source.
|
||||
4. Set the refresh rate/FPS to something very low like `0.0167` (that's 1 frame every 60 seconds).
|
||||
|
||||
## How Embeds Behave
|
||||
|
||||
- They load like any normal website albeit with a significant delay.
|
||||
- They auto refresh every `60s`.
|
||||
- All embeds and images generated by Blitzkrieg have a width of `640px` but the height varies and must be found manually through trial and error.
|
||||
- It's okay to have a Browser Source that has a height larger than needed as Blitzkrieg embeds are transparent.
|
||||
@@ -0,0 +1,17 @@
|
||||
# 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!
|
||||
@@ -0,0 +1,10 @@
|
||||
# Inviting the Bot
|
||||
|
||||
It's quite simple really. Just follow the steps below:
|
||||
|
||||
1. Join a Discord server that already has Blitzkrieg installed or [the official Discord Server](https://discord.gg/nDt7AjGJQH).
|
||||
2. Click on the bot's profile.
|
||||
3. Click the "Add to Server" button under the bot's name and ID.
|
||||
4. Select what server you want it in and see what permissions you seem fit for the bot.
|
||||
|
||||
Voila! You're ready to go.
|
||||
@@ -0,0 +1,6 @@
|
||||
# Permissions
|
||||
|
||||
The following Discord permissions are required by the bot to ensure full functionality:
|
||||
|
||||
- Attach files
|
||||
- View channels
|
||||
@@ -0,0 +1,9 @@
|
||||
# Timezones
|
||||
|
||||
What is considered a "day's worth of games" is determined by the reset time. The reset time is generally at midnight everyday after which newer games are counted towards the next day. Reset times vary from region to region:
|
||||
|
||||
- North America: `UTC-5:00` (Central North American Time midnight)
|
||||
- Europe: `UTC+1:00` (Central European Time midnight)
|
||||
- Asia: `UTC+7:00` (Central Asia Standard Time midnight)
|
||||
|
||||
**Reset times are different from Blitz Stars** (Blitz Stars resets at 5:00 am locally relative to the user opening their website). Inconsistencies with Blitz Stars only occur with sleep-deprived players and players who play in the wrong region.
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# https://vitepress.dev/reference/default-theme-home-page
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: 'blitzkrieg'
|
||||
text: Everything Blitz, right in Discord
|
||||
tagline: All-in-one Discord bot for everything World of Tanks Blitz
|
||||
image:
|
||||
src: '/assets/images/hero.png'
|
||||
alt: 'blitzkrieg'
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Add to Discord Server
|
||||
link: guide/install
|
||||
- theme: alt
|
||||
text: Guide
|
||||
link: /guide
|
||||
|
||||
features:
|
||||
- title: Clean and Efficient UI
|
||||
icon: 🚀
|
||||
details: Blitzkrieg is where concise meets efficient. Get the information you need in the way you want.
|
||||
- title: Endless Possibilities
|
||||
icon: 🛠
|
||||
details: With endless ways to customize the output, it's guaranteed that you'll always get the information you need.
|
||||
- title: Easy to Use
|
||||
icon: 💻
|
||||
details: Leveraging Discord's, Blitz Stars', and Wargaming's powerful APIS, Blitzkrieg does all the hard work for you.
|
||||
---
|
||||
@@ -0,0 +1,23 @@
|
||||
# Blitzkrieg Privacy Policy
|
||||
|
||||
Blitzkrieg collects little to no data. Regardless, here is an exhaustive list of Blitzkrieg's data collection practices.
|
||||
|
||||
## Logs
|
||||
|
||||
All Blitzkrieg logs are available to the public as an effort for open source transparency. A history of all logs [can be found on GitHub](https://github.com/tresabhi/blitzkrieg/actions/workflows/host.yml). All logs expire automatically and are permanently deleted after 30 days. However, anyone may chose to save a local copy of the logs which is not tracked by GitHub.
|
||||
|
||||
## Commands
|
||||
|
||||
Everytime a command a command is used, the command name and parameters provided is logged. Any identifying information like manually provided in-game usernames are also recorded.
|
||||
|
||||
## Errors
|
||||
|
||||
Everytime an error occurs, a detailed stack trace, scope of the error, and the error message is logged both in the GitHub logs and in the public channel [#🔲︱blitzkrieg-logs](https://discord.com/channels/734786591205359697/880650462540476416) in [the official Discord server](https://discord.gg/nDt7AjGJQH).
|
||||
|
||||
## Databases
|
||||
|
||||
No databases are used by Blitzkrieg meaning that no data is collected outside of what has already been mentioned above. This is no permanent state.
|
||||
|
||||
## 3rd Party
|
||||
|
||||
The privacy policies of Discord, Wargaming, and Blitz Stars apply too since they are utilized by the bot.
|
||||
@@ -0,0 +1,13 @@
|
||||
# Blitzkrieg Terms of Service
|
||||
|
||||
## About
|
||||
|
||||
Blitzkrieg is a multi-function Discord bot that serves users with needs specific to the game World of Tanks Blitz.
|
||||
|
||||
## License
|
||||
|
||||
Blitzkrieg is licensed under the MIT License.
|
||||
|
||||
## 3rd Party
|
||||
|
||||
The terms of services of Discord, Wargaming, and Blitz Stars apply too since they are utilized by the bot.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"main": "server.js",
|
||||
"main": "server.cjs",
|
||||
"scripts": {
|
||||
"start": "node --enable-source-maps server.cjs"
|
||||
"start": "node --enable-source-maps --trace-warnings server.cjs"
|
||||
}
|
||||
}
|
||||
+29
-11
@@ -1,37 +1,55 @@
|
||||
{
|
||||
"name": "blitzkrieg",
|
||||
"version": "1.7.4",
|
||||
"version": "1.10.2",
|
||||
"description": "",
|
||||
"main": "src/index.ts",
|
||||
"main": "src/server.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "yarn build && yarn start",
|
||||
"start": "node --enable-source-maps dist/index.cjs",
|
||||
"build:bot": "vite-node --script scripts/build --build=bot",
|
||||
"build:server": "vite-node --script scripts/build --build=server",
|
||||
"build:docs": "vitepress build docs",
|
||||
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
||||
"build": "vite-node --script scripts/build --build=all",
|
||||
"dev:bot": "yarn build:bot --dev && yarn start:bot",
|
||||
"dev:server": "yarn build:server --dev && yarn start:server",
|
||||
"dev:docs": "vitepress dev docs",
|
||||
"start:bot": "node --enable-source-maps --trace-warnings dist/bot.cjs",
|
||||
"start:server": "node --enable-source-maps --trace-warnings dist/server.cjs",
|
||||
"host:docs": "vitepress preview docs",
|
||||
"publish:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard --publish",
|
||||
"zip": "zip -r dist.zip dist",
|
||||
"build": "node scripts/build",
|
||||
"lint": "tsc"
|
||||
"lint": "npx tsc",
|
||||
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\""
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.1",
|
||||
"@radix-ui/colors": "^0.1.8",
|
||||
"@resvg/resvg-js": "^2.4.1",
|
||||
"bepaint": "^0.1.0-beta.3",
|
||||
"discord.js": "^14.9.0",
|
||||
"esbuild": "^0.18.10",
|
||||
"escape-html": "^1.0.3",
|
||||
"express": "^4.18.2",
|
||||
"false": "^0.0.4",
|
||||
"fuzzysort": "^2.0.4",
|
||||
"lodash.startcase": "^4.4.0",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-escape": "^2.0.0",
|
||||
"react": "^18.2.0",
|
||||
"satori": "^0.9.1"
|
||||
"satori": "^0.9.1",
|
||||
"vite-node": "^0.33.0",
|
||||
"vitepress-plugin-auto-sidebar": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@total-typescript/ts-reset": "^0.4.2",
|
||||
"@types/escape-html": "^1.0.2",
|
||||
"@types/lodash.startcase": "^4.4.7",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/markdown-escape": "^1.1.0",
|
||||
"@types/node": "^20.2.1",
|
||||
"@types/react": "^18.2.7",
|
||||
"esbuild": "^0.17.19",
|
||||
"typescript": "^5.0.4"
|
||||
"prettier": "^3.0.0",
|
||||
"typescript": "^5.0.4",
|
||||
"vitepress": "^1.0.0-beta.3"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { build } from 'esbuild';
|
||||
import { rmSync } from 'fs';
|
||||
|
||||
console.log('Removing dist...');
|
||||
rmSync('dist', { recursive: true, force: true });
|
||||
|
||||
console.log('Creating context...');
|
||||
build({
|
||||
entryPoints: ['src/index.ts'],
|
||||
outfile: 'dist/index.cjs',
|
||||
|
||||
platform: 'node',
|
||||
loader: {
|
||||
'.node': 'copy',
|
||||
'.ttf': 'file',
|
||||
},
|
||||
|
||||
bundle: true,
|
||||
sourcemap: true,
|
||||
minifyIdentifiers: false, // causes errors
|
||||
minifySyntax: true,
|
||||
minifyWhitespace: true,
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { BuildOptions, build } from 'esbuild';
|
||||
import { copyFile, mkdir, rm } from 'fs/promises';
|
||||
import { argv } from 'process';
|
||||
|
||||
const isProd = !argv.includes('--dev');
|
||||
const buildAll = argv.includes('--build=all');
|
||||
const buildBot = argv.includes('--build=bot') || buildAll;
|
||||
const buildServer = argv.includes('--build=server') || buildAll;
|
||||
|
||||
if (isProd) {
|
||||
// only remove in production to ensure no time is wasted in dev
|
||||
console.log('Removing dist...');
|
||||
await rm('dist', { recursive: true, force: true });
|
||||
console.log('Dist removed');
|
||||
|
||||
console.log('Creating dist...');
|
||||
await mkdir('dist');
|
||||
console.log('Dist created');
|
||||
|
||||
console.log('Copying package.json...');
|
||||
copyFile('package.dist.json', 'dist/package.json').then(() =>
|
||||
console.log('package.json copied'),
|
||||
);
|
||||
}
|
||||
|
||||
const commonOptions: BuildOptions = {
|
||||
platform: 'node',
|
||||
loader: {
|
||||
'.node': 'copy',
|
||||
'.ttf': 'file',
|
||||
},
|
||||
|
||||
bundle: true,
|
||||
sourcemap: true,
|
||||
minifyIdentifiers: false, // causes errors
|
||||
minifySyntax: isProd,
|
||||
minifyWhitespace: isProd,
|
||||
|
||||
logLevel: isProd ? 'info' : 'silent',
|
||||
};
|
||||
|
||||
if (buildBot) {
|
||||
console.log('Building bot...');
|
||||
build({
|
||||
...commonOptions,
|
||||
|
||||
entryPoints: ['src/bot.ts'],
|
||||
outfile: 'dist/bot.cjs',
|
||||
}).then(() => console.log('Bot built'));
|
||||
}
|
||||
|
||||
if (buildServer) {
|
||||
console.log('Building server...');
|
||||
build({
|
||||
...commonOptions,
|
||||
|
||||
entryPoints: ['src/server.ts'],
|
||||
outfile: 'dist/server.cjs',
|
||||
}).then(() => {
|
||||
console.log('Server built');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { rm, writeFile } from 'fs/promises';
|
||||
import { argv, env } from 'process';
|
||||
import {
|
||||
RatingsInfo,
|
||||
RatingsNeighbors,
|
||||
RatingsPlayer,
|
||||
} from '../src/commands/ratings';
|
||||
import commitMultipleFiles from './commitMultipleFiles.js';
|
||||
|
||||
/*
|
||||
* Central North American Time (UTC-5): use 0 5 * * *.
|
||||
* Central European Time (UTC+1): use 0 23 * * *.
|
||||
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
||||
*
|
||||
* na/ratings/49/info.json: season info like rewards, start & end time, etc.
|
||||
* na/ratings/49/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
||||
* na/ratings/49/midnight.json: last midnight's leaderboard relative to the region
|
||||
*/
|
||||
|
||||
export type BlitzkriegRatingsLeaderboard = { id: number; score: number }[];
|
||||
|
||||
const publish = argv.includes('--publish');
|
||||
const latest = argv.includes('--latest');
|
||||
const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1];
|
||||
|
||||
if (!server) throw new Error('Region parameter not specified');
|
||||
|
||||
const NEIGHBORS = 1000;
|
||||
const PLAYERS = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
)
|
||||
.then((response) => response.json() as Promise<RatingsInfo>)
|
||||
.then((data) => data.count);
|
||||
|
||||
const players: Record<number, RatingsPlayer> = {};
|
||||
const leaderboard: BlitzkriegRatingsLeaderboard = [];
|
||||
let registered = 0;
|
||||
|
||||
async function branchFromPlayer(id: number) {
|
||||
const { neighbors } = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
||||
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
||||
|
||||
const firstPlayer = neighbors[0];
|
||||
const lastPlayer = neighbors[neighbors.length - 1];
|
||||
|
||||
const branches: Promise<void>[] = [];
|
||||
if (!players[firstPlayer.number])
|
||||
branches.push(branchFromPlayer(firstPlayer.spa_id));
|
||||
if (!players[lastPlayer.number])
|
||||
branches.push(branchFromPlayer(lastPlayer.spa_id));
|
||||
|
||||
neighbors.forEach((neighbor) => {
|
||||
if (players[neighbor.number]) return;
|
||||
|
||||
players[neighbor.number] = neighbor;
|
||||
registered++;
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Registered ${registered} / ${PLAYERS} (${(
|
||||
(registered / PLAYERS) *
|
||||
100
|
||||
).toFixed(2)}%)`,
|
||||
);
|
||||
|
||||
await Promise.all(branches);
|
||||
}
|
||||
|
||||
async function branchFromLeague(id: number) {
|
||||
const { result } = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
||||
).then((response) => response.json() as Promise<{ result: RatingsPlayer[] }>);
|
||||
|
||||
const firstPlayer = result[0];
|
||||
const lastPlayer = result[result.length - 1];
|
||||
|
||||
await Promise.all([
|
||||
branchFromPlayer(firstPlayer.spa_id),
|
||||
branchFromPlayer(lastPlayer.spa_id),
|
||||
]);
|
||||
}
|
||||
|
||||
console.log('Branching from leagues...');
|
||||
await Promise.all([
|
||||
branchFromLeague(0),
|
||||
branchFromLeague(1),
|
||||
branchFromLeague(2),
|
||||
branchFromLeague(3),
|
||||
branchFromLeague(4),
|
||||
]);
|
||||
|
||||
console.log('Converting to an array...');
|
||||
for (let index = 0; index < PLAYERS; index++) {
|
||||
const listing = players[index + 1];
|
||||
if (!listing) console.warn(`Position ${index + 1} had no player`);
|
||||
|
||||
leaderboard[index] = {
|
||||
id: listing.spa_id,
|
||||
score: listing.score,
|
||||
};
|
||||
}
|
||||
|
||||
const leaderboardJSON = JSON.stringify(leaderboard);
|
||||
|
||||
if (publish) {
|
||||
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
||||
|
||||
const info = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
).then((response) => response.json() as Promise<RatingsInfo>);
|
||||
const normalizedServer = server === 'na' ? 'com' : server;
|
||||
|
||||
const infoPath = `${normalizedServer}/ratings/${info.current_season}/info.json`;
|
||||
const leaderboardPath = `${normalizedServer}/ratings/${info.current_season}/${
|
||||
latest ? 'latest' : 'midnight'
|
||||
}.json`;
|
||||
const infoJSON = JSON.stringify(info);
|
||||
|
||||
console.log(`Publishing to season ${info.current_season}...`);
|
||||
commitMultipleFiles(
|
||||
octokit,
|
||||
'tresabhi',
|
||||
'blitzkrieg-db',
|
||||
'main',
|
||||
new Date().toString(),
|
||||
[
|
||||
{ path: infoPath, content: infoJSON },
|
||||
{ path: leaderboardPath, content: leaderboardJSON },
|
||||
],
|
||||
);
|
||||
} else {
|
||||
console.log('Writing to disk...');
|
||||
await rm('dist.json', { force: true });
|
||||
await writeFile('dist.json', leaderboardJSON);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
|
||||
export default async function commitMultipleFiles(
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string,
|
||||
branch: string,
|
||||
message: string,
|
||||
changes: { path: string; content: string }[],
|
||||
) {
|
||||
// Get the latest commit SHA on the specified branch
|
||||
const { data: refData } = await octokit.git.getRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `heads/${branch}`,
|
||||
});
|
||||
const latestCommitSha = refData.object.sha;
|
||||
|
||||
// Get the tree SHA for the latest commit
|
||||
const { data: commitData } = await octokit.git.getCommit({
|
||||
owner,
|
||||
repo,
|
||||
commit_sha: latestCommitSha,
|
||||
});
|
||||
const treeSha = commitData.tree.sha;
|
||||
|
||||
// Create blobs for each file
|
||||
const blobs = await Promise.all(
|
||||
changes.map(async (change) => {
|
||||
const { data: blobData } = await octokit.git.createBlob({
|
||||
owner,
|
||||
repo,
|
||||
content: change.content,
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
return {
|
||||
sha: blobData.sha,
|
||||
path: change.path,
|
||||
mode: '100644',
|
||||
type: 'blob',
|
||||
} as const;
|
||||
}),
|
||||
);
|
||||
|
||||
// Create a new tree with the new blobs
|
||||
const { data: treeData } = await octokit.git.createTree({
|
||||
owner,
|
||||
repo,
|
||||
base_tree: treeSha,
|
||||
tree: blobs,
|
||||
});
|
||||
|
||||
// Create a new commit with the new tree
|
||||
const { data: newCommitData } = await octokit.git.createCommit({
|
||||
owner,
|
||||
repo,
|
||||
message,
|
||||
tree: treeData.sha,
|
||||
parents: [latestCommitSha],
|
||||
});
|
||||
|
||||
// Update the branch reference to point to the new commit
|
||||
await octokit.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `heads/${branch}`,
|
||||
sha: newCommitData.sha,
|
||||
});
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { secrets } from './core/node/secrets';
|
||||
import { registerErrorHandlers } from './events/error';
|
||||
import guildMemberAdd from './events/guildMemberAdd';
|
||||
import interactionCreate from './events/interactionCreate';
|
||||
import ready from './events/ready';
|
||||
|
||||
export const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
|
||||
})
|
||||
.on('ready', ready)
|
||||
.on('guildMemberAdd', guildMemberAdd)
|
||||
.on('interactionCreate', interactionCreate);
|
||||
|
||||
export const octokit = new Octokit({ auth: secrets.GH_TOKEN });
|
||||
|
||||
registerErrorHandlers();
|
||||
client.login(secrets.DISCORD_TOKEN);
|
||||
+29
-34
@@ -1,50 +1,45 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import packageJSON from '../../package.json' assert { type: 'json' };
|
||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||
import cleanTable from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import getClientId from '../core/process/getClientId.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { client } from '../index.js';
|
||||
import { client } from '../bot';
|
||||
import { tankopedia } from '../core/blitz/tankopedia';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import markdownTable from '../core/discord/markdownTable';
|
||||
import getClientId from '../core/node/getClientId';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
const executionStart = new Date().getTime();
|
||||
|
||||
export default {
|
||||
export const debugCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('debug'))
|
||||
.setName('debug')
|
||||
.setDescription('Debug information about the bot'),
|
||||
|
||||
async execute(interaction) {
|
||||
async handler(interaction) {
|
||||
const currentTime = new Date().getTime();
|
||||
const uptime = currentTime - executionStart;
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`${client.user?.username} debug information`,
|
||||
cleanTable([
|
||||
['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', `${tankopedia !== undefined}`],
|
||||
['Tank averages cached', `${tankAverages !== undefined}`],
|
||||
]),
|
||||
),
|
||||
],
|
||||
});
|
||||
return embedInfo(
|
||||
`${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}`],
|
||||
]),
|
||||
);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
};
|
||||
+92
-64
@@ -1,21 +1,21 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import sumStats from '../core/blitz/sumStats.js';
|
||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
|
||||
import getPeriodicStart from '../core/blitzstars/getPeriodStart.js';
|
||||
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||
import cleanTable, { TableInput } from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import calculateWN8 from '../core/blitz/calculateWN8';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import sumStats from '../core/blitz/sumStats';
|
||||
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 addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import embedNegative from '../core/discord/embedNegative';
|
||||
import embedPositive from '../core/discord/embedPositive';
|
||||
import markdownTable, { TableInput } from '../core/discord/markdownTable';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export type SkilledClan = 'SKLLD' | 'SMRI';
|
||||
|
||||
@@ -24,13 +24,13 @@ export const SKILLED_CLANS: Record<SkilledClan, string> = {
|
||||
SMRI: 'Samurai',
|
||||
};
|
||||
|
||||
export default {
|
||||
export const eligibleCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: false,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('eligible'))
|
||||
.setName('eligible')
|
||||
.setDescription('Checks eligibility for any Skilled clan')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
@@ -45,13 +45,13 @@ export default {
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addUsernameOption),
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
async execute(interaction) {
|
||||
async handler(interaction) {
|
||||
const clan = interaction.options.getString('clan') as SkilledClan;
|
||||
const { id, server } = await getBlitzAccount(interaction);
|
||||
const { id, region: server } = await resolvePlayerFromCommand(interaction);
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const problems: TableInput = [];
|
||||
const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
||||
@@ -59,51 +59,80 @@ export default {
|
||||
let body = '';
|
||||
|
||||
if (clan === 'SKLLD') {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
const { diffed } = await getDiffedTankStats(
|
||||
server,
|
||||
id,
|
||||
getPeriodicStart('30'),
|
||||
getTimeDaysAgo(server, 30),
|
||||
getPeriodNow(),
|
||||
);
|
||||
const entries = Object.entries(tankStatsOverTime);
|
||||
const entries = Object.entries(diffed);
|
||||
const stats = sumStats(entries.map(([, stats]) => stats));
|
||||
const averageTier =
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankTier = tankopedia[tankId].tier;
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return accumulator + tankTier * stats.battles;
|
||||
}, 0) / stats.battles;
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tankTier = tankopediaEntry.tier;
|
||||
|
||||
return (await accumulator) + tankTier * stats.battles;
|
||||
},
|
||||
0,
|
||||
)) /
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
return stats.battles;
|
||||
},
|
||||
0,
|
||||
));
|
||||
const WN8 =
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
// edge case where new tanks don't have averages
|
||||
if (tankAverages[tankId]) {
|
||||
const tankWN8 = getWN8(tankAverages[tankId].all, stats);
|
||||
// edge case where new tanks don't have averages
|
||||
if ((await tankAverages)[tankId]) {
|
||||
const tankWN8 = calculateWN8(
|
||||
(await tankAverages)[tankId].all,
|
||||
stats,
|
||||
);
|
||||
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
return accumulator + tankWN8 * stats.battles;
|
||||
} else return accumulator;
|
||||
}, 0) / stats.battles;
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
return (await accumulator) + tankWN8 * stats.battles;
|
||||
} else return accumulator;
|
||||
},
|
||||
0,
|
||||
)) / stats.battles;
|
||||
const tier10Damage =
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
if (tankopedia[tankId]?.tier === 10) {
|
||||
const tankStats = tankStatsOverTime[tankId];
|
||||
return accumulator + tankStats.damage_dealt;
|
||||
} else return accumulator;
|
||||
}, 0) /
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
if ((await tankopedia)[tankId]?.tier === 10) {
|
||||
const tankStats = diffed[tankId];
|
||||
return (await accumulator) + tankStats.damage_dealt;
|
||||
} else return accumulator;
|
||||
},
|
||||
0,
|
||||
)) /
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
if (tankopedia[tankId]?.tier === 10) {
|
||||
const tankStats = tankStatsOverTime[tankId];
|
||||
return accumulator + tankStats.battles;
|
||||
} else return accumulator;
|
||||
}, 0);
|
||||
if ((await tankopedia)[tankId]?.tier === 10) {
|
||||
const tankStats = diffed[tankId];
|
||||
return (await accumulator) + tankStats.battles;
|
||||
} else return accumulator;
|
||||
},
|
||||
0,
|
||||
));
|
||||
|
||||
if (stats.battles < 126) {
|
||||
problems.push(['Battles', `${stats.battles} (${stats.battles - 126})`]);
|
||||
@@ -124,7 +153,10 @@ export default {
|
||||
]);
|
||||
}
|
||||
if (WN8 < 2450) {
|
||||
problems.push(['WN8', `${WN8.toFixed(0)} (${WN8 - 2450})`]);
|
||||
problems.push([
|
||||
'WN8',
|
||||
`${WN8.toFixed(0)} (${(WN8 - 2450).toFixed(0)})`,
|
||||
]);
|
||||
}
|
||||
if (tier10Damage < 1250) {
|
||||
problems.push([
|
||||
@@ -136,7 +168,7 @@ export default {
|
||||
isEligible = problems.length === 0;
|
||||
body = isEligible
|
||||
? 'Player is fully eligible.'
|
||||
: `Player is not eligible. Shortcomings in 30-day statistics:\n\n${cleanTable(
|
||||
: `Player is not eligible. Shortcomings in 30-day statistics:\n\n${markdownTable(
|
||||
problems,
|
||||
)}`;
|
||||
} else if (clan === 'SMRI') {
|
||||
@@ -161,15 +193,11 @@ export default {
|
||||
isEligible = problems.length === 0;
|
||||
body = isEligible
|
||||
? 'Player is fully eligible.'
|
||||
: `Player is not eligible. Shortcomings in career statistics:\n\n${cleanTable(
|
||||
: `Player is not eligible. Shortcomings in career statistics:\n\n${markdownTable(
|
||||
problems,
|
||||
)}`;
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: isEligible
|
||||
? [positiveEmbed(title, body)]
|
||||
: [negativeEmbed(title, body)],
|
||||
});
|
||||
return (isEligible ? embedPositive : embedNegative)(title, body);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||
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 resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import evolution from '../renderers/evolution';
|
||||
import { StatType } from '../renderers/fullStats';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const evolutionCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('evolution')
|
||||
.setDescription('Evolution of statistics'),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const commandGroup = interaction.options.getSubcommandGroup(
|
||||
true,
|
||||
) as StatType;
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||
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 { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
tankId,
|
||||
start,
|
||||
end,
|
||||
});
|
||||
|
||||
return [
|
||||
await evolution(commandGroup, period, player, tankId),
|
||||
primaryButton(path, 'Refresh'),
|
||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}${
|
||||
commandGroup === 'tank' ? `/tank/${tankId!}` : ''
|
||||
}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
autocompleteUsername(interaction);
|
||||
autocompleteTanks(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 period = resolvePeriodFromButton(player.region, interaction);
|
||||
|
||||
return await evolution(
|
||||
commandGroup,
|
||||
period,
|
||||
player,
|
||||
parseInt(url.searchParams.get('tankId')!),
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||
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 resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import fullStats, { StatType } from '../renderers/fullStats';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const fullStatsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('fullstats')
|
||||
.setDescription('Full in-game statistics'),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const commandGroup = interaction.options.getSubcommandGroup(
|
||||
true,
|
||||
) as StatType;
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||
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,
|
||||
tankId,
|
||||
start,
|
||||
end,
|
||||
});
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
|
||||
return [
|
||||
await fullStats(commandGroup, period, player, tankId),
|
||||
primaryButton(path, 'Refresh'),
|
||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
autocompleteUsername(interaction);
|
||||
autocompleteTanks(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 period = resolvePeriodFromButton(player.region, interaction);
|
||||
|
||||
return await fullStats(
|
||||
commandGroup,
|
||||
period,
|
||||
player,
|
||||
parseInt(url.searchParams.get('tankId')!),
|
||||
);
|
||||
},
|
||||
};
|
||||
+59
-36
@@ -1,43 +1,66 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import { ACCENT_COLOR } from '../constants/colors.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import {
|
||||
CommandRegistry,
|
||||
guildCommands,
|
||||
publicCommands,
|
||||
} from '../events/interactionCreate.js';
|
||||
import { client } from '../index.js';
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export default {
|
||||
const RAW_PATH = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/`;
|
||||
const DOCS = {
|
||||
permissions: 'guide/permissions',
|
||||
embeds: 'guide/embeds',
|
||||
about: 'guide/about',
|
||||
invite: 'guide/invite',
|
||||
timezones: 'guide/timezones',
|
||||
};
|
||||
const DOC_DESCRIPTIONS: Record<keyof typeof DOCS, string> = {
|
||||
permissions: 'The permissions needed for the bot to function',
|
||||
embeds: 'How embeds work',
|
||||
about: 'About the bot',
|
||||
invite: 'How to invite the bot',
|
||||
timezones: 'How Blitzkrieg infers and uses your timezone',
|
||||
};
|
||||
|
||||
function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
|
||||
Object.entries(DOC_DESCRIPTIONS).forEach(([key, value]) => {
|
||||
option.addSubcommand((sub) => sub.setName(key).setDescription(value));
|
||||
});
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
export const helpCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('help'))
|
||||
.setDescription('All the help you need about the bot'),
|
||||
command: addDocsSubcommands(
|
||||
new SlashCommandBuilder()
|
||||
.setName('help')
|
||||
.setDescription('All the help you need about the bot')
|
||||
.addSubcommand((option) =>
|
||||
option
|
||||
.setName('commands')
|
||||
.setDescription('List of all commands and their descriptions'),
|
||||
),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle(`${client.user?.username} help`)
|
||||
.setColor(ACCENT_COLOR)
|
||||
.setDescription(
|
||||
`**About**\n${
|
||||
client.user?.username
|
||||
} automates many mundane tasks and provide statistics in numerous flexible ways.\n\nMade by TresAbhi from the Skilled [SKLLD] clan.\nGitHub: https://github.com/tresabhi/blitzkrieg\nDiscord server: https://discord.gg/nDt7AjGJQH\nSkilled server: https://discord.gg/ZPvcEG7DS8\n\n**Commands**\n${(interaction.guildId ===
|
||||
discord.sklld_guild_id
|
||||
? [...guildCommands, ...publicCommands]
|
||||
: publicCommands
|
||||
)
|
||||
.map((command) => `**/${command.name}**: ${command.description}`)
|
||||
.join(
|
||||
'\n',
|
||||
)}\n\n*I am a new bot; I may make mistakes and go offline unexpectedly from time to time.*`,
|
||||
),
|
||||
],
|
||||
});
|
||||
handler(interaction) {
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
if (subcommand === 'commands') {
|
||||
return `# Commands\n\nBlitzkrieg offers the following commands:\n\n${COMMANDS_RAW.filter(
|
||||
(registry) => registry.inPublic && registry.inProduction,
|
||||
)
|
||||
.map(
|
||||
(registry) =>
|
||||
`- \`/${registry.command.name}\`: ${registry.command.description}`,
|
||||
)
|
||||
.join('\n')}`;
|
||||
}
|
||||
|
||||
const url = `${RAW_PATH}${DOCS[subcommand as keyof typeof DOCS]}.md`;
|
||||
const content = fetch(url).then((response) => response.text());
|
||||
|
||||
return content;
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
};
|
||||
+28
-32
@@ -1,30 +1,28 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import GenericStats from '../components/GenericStats/index.js';
|
||||
import NoData, { NoDataType } from '../components/NoData.js';
|
||||
import PoweredByWargaming from '../components/PoweredByWargaming.js';
|
||||
import TitleBar from '../components/TitleBar.js';
|
||||
import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import clanAutocomplete from '../core/autocomplete/clan.js';
|
||||
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addClanChoices from '../core/options/addClanChoices.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { ClanInfo } from '../types/clanInfo.js';
|
||||
import GenericStats from '../components/GenericStats';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import PoweredBy, { PoweredByType } from '../components/PoweredBy';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { REGION_NAMES } from '../constants/regions';
|
||||
import getBlitzClan from '../core/blitz/getBlitzClan';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import addClanChoices from '../core/discord/addClanChoices';
|
||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { ClanInfo } from '../types/clanInfo';
|
||||
|
||||
const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
export default {
|
||||
export const inactiveCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('inactive'))
|
||||
.setName('inactive')
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption(addClanChoices)
|
||||
.addNumberOption((option) =>
|
||||
@@ -36,22 +34,22 @@ export default {
|
||||
.setMinValue(0),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
async handler(interaction) {
|
||||
const clanName = interaction.options.getString('clan')!;
|
||||
const { server, id } = await getBlitzClan(interaction, clanName);
|
||||
const { server, id } = await getBlitzClan(clanName);
|
||||
const threshold =
|
||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||
const time = new Date().getTime() / 1000;
|
||||
const clanData = (
|
||||
await getWargamingResponse<ClanInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`,
|
||||
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&clan_id=${id}`,
|
||||
)
|
||||
)[id];
|
||||
const memberIds = clanData.members_ids;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds.join(
|
||||
',',
|
||||
)}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${
|
||||
secrets.WARGAMING_APPLICATION_ID
|
||||
}&account_id=${memberIds.join(',')}`,
|
||||
);
|
||||
const inactive = memberIds
|
||||
.map((memberId) => {
|
||||
@@ -67,26 +65,24 @@ export default {
|
||||
);
|
||||
const hasInactiveMembers = inactive.length > 0;
|
||||
|
||||
const image = await render(
|
||||
return (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={clanData.name}
|
||||
nameDiscriminator="(Inactivity)"
|
||||
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData.emblem_set_id}.png`}
|
||||
description={`${threshold}+ Days • ${new Date().toDateString()} • ${
|
||||
BLITZ_SERVERS[server]
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
/>
|
||||
|
||||
{!hasInactiveMembers && <NoData type={NoDataType.PlayersInPeriod} />}
|
||||
{hasInactiveMembers && <GenericStats stats={inactive} />}
|
||||
|
||||
<PoweredByWargaming />
|
||||
</Wrapper>,
|
||||
<PoweredBy type={PoweredByType.Wargaming} />
|
||||
</Wrapper>
|
||||
);
|
||||
|
||||
await interaction.editReply({ files: [image] });
|
||||
},
|
||||
|
||||
autocomplete: clanAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
autocomplete: autocompleteClan,
|
||||
};
|
||||
@@ -0,0 +1,151 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import PoweredBy, { PoweredByType } from '../components/PoweredBy';
|
||||
import * as Tanks from '../components/Tanks';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { REGION_NAMES } from '../constants/regions';
|
||||
import getTankStats from '../core/blitz/getTankStats';
|
||||
import getTreeType from '../core/blitz/getTreeType';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankName from '../core/blitz/resolveTankName';
|
||||
import {
|
||||
TIER_ROMAN_NUMERALS,
|
||||
Tier,
|
||||
tankopedia,
|
||||
} from '../core/blitz/tankopedia';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
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 = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('ownedtanks')
|
||||
.setDescription("Shows a player's owned tanks")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('tier')
|
||||
.setDescription('The tier you want to see')
|
||||
.setChoices(
|
||||
{ name: 'Tier I', value: '1' },
|
||||
{ name: 'Tier II', value: '2' },
|
||||
{ name: 'Tier III', value: '3' },
|
||||
{ name: 'Tier IV', value: '4' },
|
||||
{ name: 'Tier V', value: '5' },
|
||||
{ name: 'Tier VI', value: '6' },
|
||||
{ name: 'Tier VII', value: '7' },
|
||||
{ name: 'Tier VIII', value: '8' },
|
||||
{ name: 'Tier IX', value: '9' },
|
||||
{ name: 'Tier X', value: '10' },
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
async handler(interaction) {
|
||||
const tier = Number(interaction.options.getString('tier'));
|
||||
const account = await resolvePlayerFromCommand(interaction);
|
||||
const { id, region: server } = account;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getTankStats(server, id);
|
||||
const tanks = (
|
||||
await Promise.all(
|
||||
tankStats.map(async (tankData) => ({
|
||||
...(await tankopedia)[tankData.tank_id],
|
||||
tank_id: tankData.tank_id,
|
||||
})),
|
||||
)
|
||||
).filter((tank) => tank?.tier === tier);
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const leftColumnSize = Math.ceil(tanks.length / 2);
|
||||
const leftColumn = tanks.slice(0, leftColumnSize);
|
||||
const rightColumn = tanks.slice(leftColumnSize);
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier as Tier]})`}
|
||||
image={
|
||||
clanData[id]?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||
: undefined
|
||||
}
|
||||
description={`Owned tanks • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
/>
|
||||
|
||||
{tanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
||||
|
||||
{tanks.length > 0 && (
|
||||
<Tanks.Root>
|
||||
<Tanks.Column>
|
||||
{await Promise.all(
|
||||
leftColumn.map(async (tank) => (
|
||||
<Tanks.Item
|
||||
key={tank.tank_id}
|
||||
name={await resolveTankName(tank.tank_id)}
|
||||
tankType={tank.type}
|
||||
image={tank.images?.normal}
|
||||
treeType={await getTreeType(tank.tank_id)}
|
||||
/>
|
||||
)),
|
||||
)}
|
||||
</Tanks.Column>
|
||||
<Tanks.Column>
|
||||
{await Promise.all(
|
||||
rightColumn.map(async (tank) => (
|
||||
<Tanks.Item
|
||||
key={tank.tank_id}
|
||||
name={await resolveTankName(tank.tank_id)}
|
||||
tankType={tank.type}
|
||||
image={tank.images?.normal}
|
||||
treeType={await getTreeType(tank.tank_id)}
|
||||
/>
|
||||
)),
|
||||
)}
|
||||
</Tanks.Column>
|
||||
</Tanks.Root>
|
||||
)}
|
||||
|
||||
<PoweredBy type={PoweredByType.Wargaming} />
|
||||
</Wrapper>
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: autocompleteUsername,
|
||||
};
|
||||
@@ -1,114 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import NoData, { NoDataType } from '../components/NoData.js';
|
||||
import PoweredByWargaming from '../components/PoweredByWargaming.js';
|
||||
import * as Tanks from '../components/Tanks/index.js';
|
||||
import TitleBar from '../components/TitleBar.js';
|
||||
import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
|
||||
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 default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('ownedtanks'))
|
||||
.setDescription("Shows a player's owned tanks")
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('tier')
|
||||
.setDescription('The tier you want to see')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(10)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const tier = interaction.options.getInteger('tier')!;
|
||||
const account = await getBlitzAccount(interaction);
|
||||
const { id, server } = account;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getTankStats(interaction, server, id);
|
||||
const tanks = tankStats
|
||||
.map((tankData) => tankopedia[tankData.tank_id])
|
||||
.filter((tank) => tank?.tier === tier);
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
|
||||
const image = await render(
|
||||
<Wrapper>
|
||||
{/* TODO: integrate some of these into title bar */}
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier]})`}
|
||||
image={
|
||||
clanData[id]?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||
: undefined
|
||||
}
|
||||
description={`Owned tanks • ${new Date().toDateString()} • ${
|
||||
BLITZ_SERVERS[server]
|
||||
}`}
|
||||
/>
|
||||
|
||||
{tanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
||||
|
||||
{tanks.length > 0 && (
|
||||
<Tanks.Root>
|
||||
{tanks.map((tank) => (
|
||||
<Tanks.Item
|
||||
key={tank.tank_id}
|
||||
name={tank.name}
|
||||
type={tank.type}
|
||||
icon={tank.images.normal}
|
||||
/>
|
||||
))}
|
||||
</Tanks.Root>
|
||||
)}
|
||||
|
||||
<PoweredByWargaming />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
await interaction.editReply({ files: [image] });
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export const pingCommand: CommandRegistry<true> = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
handlesInteraction: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Check if the bot is alive')
|
||||
.addSubcommand((option) =>
|
||||
option.setName('blitzkrieg').setDescription('Ping Blitzkrieg'),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
option.setName('blitz').setDescription('Ping Blitz'),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
const executionStart = Date.now();
|
||||
|
||||
if (subcommand === 'blitzkrieg') {
|
||||
await interaction.editReply('Pong 🏓');
|
||||
} else {
|
||||
await fetch('https://api.wotblitz.com/');
|
||||
}
|
||||
|
||||
const executionTime = Date.now() - executionStart;
|
||||
interaction.editReply(`Pong 🏓 - ${executionTime}ms`);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { startCase } from 'lodash';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountAchievements } from '../types/accountAchievements';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
type SortBy = 'name' | 'count';
|
||||
|
||||
export const playerAchievementsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerachievements')
|
||||
.setDescription("All the player's achievements")
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('sort')
|
||||
.setDescription('What to sort by (default: name)')
|
||||
.addChoices(
|
||||
{ name: 'By name', value: 'name' satisfies SortBy },
|
||||
{ name: 'By count', value: 'count' satisfies SortBy },
|
||||
),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
||||
const account = await resolvePlayerFromCommand(interaction);
|
||||
const { id, region: server } = account;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const accountsAchievements =
|
||||
await getWargamingResponse<AccountAchievements>(
|
||||
`https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const accountAchievements = accountsAchievements[id];
|
||||
const compound = {
|
||||
...accountAchievements.achievements,
|
||||
...accountAchievements.max_series,
|
||||
};
|
||||
|
||||
return embedInfo(
|
||||
`${markdownEscape(accounts[id].nickname)}'s information`,
|
||||
|
||||
markdownTable(
|
||||
Object.keys(compound)
|
||||
.filter((achievement) => compound[achievement] > 0)
|
||||
.sort(
|
||||
sortBy === 'count'
|
||||
? (a, b) => compound[b] - compound[a]
|
||||
: undefined,
|
||||
)
|
||||
.map(
|
||||
(achievement) =>
|
||||
[
|
||||
startCase(achievement),
|
||||
compound[achievement],
|
||||
] as TableInputEntry,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: autocompleteUsername,
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import markdownTable from '../core/discord/markdownTable';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const playerInfoCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerinfo')
|
||||
.setDescription('Basic information about a player')
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
async handler(interaction) {
|
||||
const account = await resolvePlayerFromCommand(interaction);
|
||||
const { id, region: server } = account;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const accountInfo = accounts[id];
|
||||
|
||||
return embedInfo(
|
||||
`${markdownEscape(accountInfo.nickname)}'s information`,
|
||||
|
||||
markdownTable([
|
||||
['Nickname', `${accountInfo.nickname}`],
|
||||
['Battles', `${accountInfo.statistics.all.battles}`],
|
||||
[
|
||||
'Winrate',
|
||||
`${(
|
||||
100 *
|
||||
(accountInfo.statistics.all.wins /
|
||||
accountInfo.statistics.all.battles)
|
||||
).toFixed(2)}%`,
|
||||
],
|
||||
[],
|
||||
['Account ID', `${accountInfo.account_id}`],
|
||||
[
|
||||
'Created',
|
||||
`${new Date(accountInfo.created_at * 1000).toDateString()}`,
|
||||
],
|
||||
[
|
||||
'Last battle',
|
||||
`${new Date(accountInfo.last_battle_time * 1000).toDateString()}`,
|
||||
],
|
||||
]),
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: autocompleteUsername,
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import startCase from 'lodash.startcase';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountAchievements } from '../types/accountAchievements.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
|
||||
type SortBy = 'name' | 'count';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('playerachievements'))
|
||||
.setDescription("All the player's achievements")
|
||||
.addStringOption(addUsernameOption)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('sort')
|
||||
.setDescription('What to sort by (default: name)')
|
||||
.addChoices(
|
||||
{ name: 'By name', value: 'name' satisfies SortBy },
|
||||
{ name: 'By count', value: 'count' satisfies SortBy },
|
||||
),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
||||
const account = await getBlitzAccount(interaction);
|
||||
const { id, server } = account;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
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 = {
|
||||
...accountAchievements.achievements,
|
||||
...accountAchievements.max_series,
|
||||
};
|
||||
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`${markdownEscape(accounts[id].nickname)}'s information`,
|
||||
|
||||
cleanTable(
|
||||
Object.keys(compound)
|
||||
.filter((achievement) => compound[achievement] > 0)
|
||||
.sort(
|
||||
sortBy === 'count'
|
||||
? (a, b) => compound[b] - compound[a]
|
||||
: undefined,
|
||||
)
|
||||
.map(
|
||||
(achievement) =>
|
||||
[
|
||||
startCase(achievement),
|
||||
compound[achievement],
|
||||
] as TableInputEntry,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
@@ -1,65 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cleanTable from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('playerinfo'))
|
||||
.setDescription('Basic information about a player')
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const account = await getBlitzAccount(interaction);
|
||||
const { id, server } = account;
|
||||
const accounts = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const accountInfo = accounts[id];
|
||||
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`${markdownEscape(accountInfo.nickname)}'s information`,
|
||||
|
||||
cleanTable([
|
||||
['Nickname', `${accountInfo.nickname}`],
|
||||
['Battles', `${accountInfo.statistics.all.battles}`],
|
||||
[
|
||||
'Winrate',
|
||||
`${(
|
||||
100 *
|
||||
(accountInfo.statistics.all.wins /
|
||||
accountInfo.statistics.all.battles)
|
||||
).toFixed(2)}%`,
|
||||
],
|
||||
[],
|
||||
['Account ID', `${accountInfo.account_id}`],
|
||||
[
|
||||
'Created',
|
||||
`${new Date(accountInfo.created_at * 1000).toDateString()}`,
|
||||
],
|
||||
[
|
||||
'Last battle',
|
||||
`${new Date(accountInfo.last_battle_time * 1000).toDateString()}`,
|
||||
],
|
||||
]),
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
@@ -0,0 +1,262 @@
|
||||
import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from 'discord.js';
|
||||
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
|
||||
import { octokit } from '../bot';
|
||||
import * as Leaderboard from '../components/Leaderboard';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { REGION_NAMES, Region } from '../constants/regions';
|
||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export interface RatingsPlayer {
|
||||
spa_id: number;
|
||||
mmr: number;
|
||||
season_number: number;
|
||||
calibrationBattlesLeft: number;
|
||||
number: number;
|
||||
percentile: number;
|
||||
skip: boolean;
|
||||
updated_at: string;
|
||||
score: number;
|
||||
nickname: string;
|
||||
clan_tag: string;
|
||||
}
|
||||
|
||||
export interface LeagueTop {
|
||||
result: RatingsPlayer[];
|
||||
}
|
||||
|
||||
export type RatingsReward = {
|
||||
from_position: number;
|
||||
to_position: number;
|
||||
count: number;
|
||||
} & (
|
||||
| {
|
||||
type: 'vehicle';
|
||||
|
||||
vehicle: {
|
||||
id: number;
|
||||
name: string;
|
||||
nation: string;
|
||||
subnation: string;
|
||||
use_subnation_flag: boolean;
|
||||
type_slug: string;
|
||||
level: number;
|
||||
roman_level: string;
|
||||
user_string: string;
|
||||
image_url: string;
|
||||
preview_url: string;
|
||||
is_premium: boolean;
|
||||
is_collectible: boolean;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: 'stuff';
|
||||
|
||||
stuff: {
|
||||
name: string;
|
||||
count: number;
|
||||
title: string;
|
||||
image_url: string;
|
||||
type: string;
|
||||
|
||||
sizes: {};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
export interface RatingsLeague {
|
||||
title: string;
|
||||
small_icon: string;
|
||||
big_icon: string;
|
||||
background: string;
|
||||
index: number;
|
||||
percentile: number;
|
||||
}
|
||||
|
||||
export interface RatingsInfo {
|
||||
title: string;
|
||||
icon: string | null;
|
||||
start_at: string;
|
||||
finish_at: string;
|
||||
current_season: number;
|
||||
updated_at: string;
|
||||
count: number;
|
||||
|
||||
rewards: RatingsReward[];
|
||||
leagues: RatingsLeague[];
|
||||
}
|
||||
|
||||
export interface RatingsNeighbors {
|
||||
neighbors: RatingsPlayer[];
|
||||
}
|
||||
|
||||
console.log('Caching ratings info...');
|
||||
const ratingsInfo = fetch(
|
||||
'https://na.wotblitz.com/en/api/rating-leaderboards/season/',
|
||||
)
|
||||
.then((response) => response.json() as Promise<RatingsInfo>)
|
||||
.then((info) => {
|
||||
console.log('Cached ratings info');
|
||||
return info;
|
||||
});
|
||||
|
||||
function optionalParameters(option: SlashCommandSubcommandBuilder) {
|
||||
return option
|
||||
.addStringOption(addRegionChoices)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('How many rows to display (default: 10)')
|
||||
.setRequired(false)
|
||||
.setMinValue(5)
|
||||
.setMaxValue(30),
|
||||
);
|
||||
}
|
||||
|
||||
const LEAGUE_INDEXES = ['diamond', 'platinum', 'gold', 'silver', 'bronze'];
|
||||
|
||||
export const DATABASE_REPO = { owner: 'tresabhi', repo: 'blitzkrieg-db' };
|
||||
|
||||
export const ratingsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
inPreview: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('ratings')
|
||||
.setDescription('Ratings battles statistics')
|
||||
.addSubcommandGroup((option) =>
|
||||
option
|
||||
.setName('league')
|
||||
.setDescription('Top league players')
|
||||
.addSubcommand((option) =>
|
||||
optionalParameters(
|
||||
option
|
||||
.setName('diamond')
|
||||
.setDescription('Top Diamond League players'),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
optionalParameters(
|
||||
option
|
||||
.setName('platinum')
|
||||
.setDescription('Top Platinum League players'),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
optionalParameters(
|
||||
option.setName('gold').setDescription('Top Gold League players'),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
optionalParameters(
|
||||
option
|
||||
.setName('silver')
|
||||
.setDescription('Top Silver League players'),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
optionalParameters(
|
||||
option
|
||||
.setName('bronze')
|
||||
.setDescription('Top Bronze League players'),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const subcommandGroup = interaction.options.getSubcommandGroup(true);
|
||||
|
||||
if (subcommandGroup === 'league') {
|
||||
const limit = interaction.options.getInteger('limit') ?? 10;
|
||||
const subcommand = interaction.options.getSubcommand(true);
|
||||
const leagueIndex = LEAGUE_INDEXES.indexOf(subcommand);
|
||||
const region = interaction.options.getString('region') as Region;
|
||||
const regionSubdomain = regionToRegionSubdomain(region);
|
||||
const result = await fetch(
|
||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
||||
)
|
||||
.then((response) => response.json() as Promise<LeagueTop>)
|
||||
.then(({ result }) => result.slice(0, limit));
|
||||
const awaitedInfo = await ratingsInfo;
|
||||
const leagueInfo = awaitedInfo.leagues[leagueIndex];
|
||||
const midnightLeaderboard = await octokit.repos
|
||||
.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${awaitedInfo.current_season}/midnight.json`,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
if (!Array.isArray(data) && data.type === 'file') {
|
||||
const content = Buffer.from(data.content, 'base64').toString();
|
||||
const jsonContent = JSON.parse(
|
||||
content,
|
||||
) as BlitzkriegRatingsLeaderboard;
|
||||
|
||||
return jsonContent;
|
||||
}
|
||||
})
|
||||
.catch(() => console.warn('No midnight leaderboard found'));
|
||||
const items = await Promise.all(
|
||||
result.map(async (player) => {
|
||||
const reward = awaitedInfo.rewards.find(
|
||||
(reward) =>
|
||||
player.number >= reward.from_position &&
|
||||
player.number <= reward.to_position,
|
||||
);
|
||||
const midnightIndex = midnightLeaderboard?.findIndex(
|
||||
(item) => item.id === player.spa_id,
|
||||
);
|
||||
const midnightScore =
|
||||
midnightIndex === undefined
|
||||
? player.score
|
||||
: midnightLeaderboard![midnightIndex].score;
|
||||
const midnightPosition =
|
||||
midnightIndex === undefined ? player.number : midnightIndex + 1;
|
||||
|
||||
return (
|
||||
<Leaderboard.Item
|
||||
nickname={player.nickname}
|
||||
score={player.score}
|
||||
position={player.number}
|
||||
clan={player.clan_tag}
|
||||
reward={reward}
|
||||
deltaScore={player.score - midnightScore}
|
||||
deltaPosition={midnightPosition - player.number}
|
||||
key={player.spa_id}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const playersBefore = result[0].number - 1;
|
||||
const playersAfter = awaitedInfo.count - result[result.length - 1].number;
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={leagueInfo.title}
|
||||
image={
|
||||
leagueInfo.big_icon.startsWith('http')
|
||||
? leagueInfo.big_icon
|
||||
: `https:${leagueInfo.big_icon}`
|
||||
}
|
||||
description={`Top ${limit} players • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[region]
|
||||
}`}
|
||||
/>
|
||||
|
||||
<Leaderboard.Root>
|
||||
{playersBefore > 0 && <Leaderboard.Gap number={playersBefore} />}
|
||||
{items}
|
||||
{playersAfter > 0 && <Leaderboard.Gap number={playersAfter} />}
|
||||
</Leaderboard.Root>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { REGION_NAMES, Region } from '../constants/regions';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import addClanChoices from '../core/discord/addClanChoices';
|
||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { ClanList } from '../types/clanList';
|
||||
|
||||
export const searchClansCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchclans')
|
||||
.setDescription('Search clans')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) => addClanChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const server = interaction.options.getString('region') as Region;
|
||||
const clan = interaction.options.getString('clan')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const clanList = await getWargamingResponse<ClanList>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
||||
);
|
||||
|
||||
return embedInfo(
|
||||
`Clan search for "${markdownEscape(clan)}" in ${REGION_NAMES[server]}`,
|
||||
clanList.length === 0
|
||||
? 'No clans found.'
|
||||
: `\`\`\`\n${clanList
|
||||
.map((clan) => `${clan.name} [${clan.tag}]`)
|
||||
.join('\n')}\n\`\`\``,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { REGION_NAMES, Region } from '../constants/regions';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import { usernamePattern } from '../core/blitz/listPlayers';
|
||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountList } from '../types/accountList';
|
||||
|
||||
export const searchPlayersCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchplayers')
|
||||
.setDescription('Search players in a Blitz server')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) =>
|
||||
addUsernameChoices(option).setAutocomplete(false).setRequired(true),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const server = interaction.options.getString('region') as Region;
|
||||
const name = interaction.options.getString('username')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const trimmedSearch = name.trim();
|
||||
const players = usernamePattern.test(trimmedSearch)
|
||||
? await getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${
|
||||
secrets.WARGAMING_APPLICATION_ID
|
||||
}&search=${encodeURIComponent(trimmedSearch)}&limit=${limit}`,
|
||||
)
|
||||
: [];
|
||||
|
||||
return embedInfo(
|
||||
`Player search for "${markdownEscape(name)}" in ${REGION_NAMES[server]}`,
|
||||
`\`\`\`${
|
||||
players.length === 0
|
||||
? 'No players found.'
|
||||
: players.map((player) => player.nickname).join('\n')
|
||||
}\`\`\``,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { TANK_NAMES } from '../core/blitz/tankopedia';
|
||||
import addTankChoices from '../core/discord/addTankChoices';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export const searchTanksCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchtanks')
|
||||
.setDescription('Search tanks')
|
||||
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const tank = interaction.options.getString('tank')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const results = go(tank, await TANK_NAMES, { limit }).map(
|
||||
(result) => result.target,
|
||||
);
|
||||
|
||||
return embedInfo(
|
||||
`Tank search for "${markdownEscape(tank)}"`,
|
||||
results.length === 0
|
||||
? 'No tanks found.'
|
||||
: `\`\`\`\n${results.join('\n')}\n\`\`\``,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,54 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import addClanChoices from '../core/options/addClanChoices.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { ClanList } from '../types/clanList.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('searchclans'))
|
||||
.setDescription('Search clans')
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption((option) => addClanChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const clan = interaction.options.getString('clan')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const clanList = await getWargamingResponse<ClanList>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`Clan search for "${markdownEscape(clan)}" in ${
|
||||
BLITZ_SERVERS[server]
|
||||
}`,
|
||||
clanList.length === 0
|
||||
? 'No clans found.'
|
||||
: `\`\`\`\n${clanList
|
||||
.map((clan) => `${clan.name} [${clan.tag}]`)
|
||||
.join('\n')}\n\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -1,62 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import { usernamePattern } from '../core/blitz/listAccountsPanServer.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountList } from '../types/accountList.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('searchplayers'))
|
||||
.setDescription('Search players in a Blitz server')
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption((option) =>
|
||||
addUsernameOption(option).setAutocomplete(false).setRequired(true),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const name = interaction.options.getString('username')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const trimmedSearch = name.trim();
|
||||
const players = usernamePattern.test(trimmedSearch)
|
||||
? await getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent(
|
||||
trimmedSearch,
|
||||
)}&limit=${limit}`,
|
||||
)
|
||||
: [];
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`Player search for "${markdownEscape(name)}" in ${
|
||||
BLITZ_SERVERS[server]
|
||||
}`,
|
||||
`\`\`\`${
|
||||
players.length === 0
|
||||
? 'No players found.'
|
||||
: players.map((player) => player.nickname).join('\n')
|
||||
}\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -1,45 +0,0 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { TANK_NAMES } from '../core/blitz/tankopedia.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||
import addTankChoices from '../core/options/addTankChoices.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('searchtanks'))
|
||||
.setDescription('Search tanks')
|
||||
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const tank = interaction.options.getString('tank')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
const results = go(tank, TANK_NAMES, { limit }).map(
|
||||
(result) => result.target,
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
infoEmbed(
|
||||
`Tank search for "${markdownEscape(tank)}"`,
|
||||
results.length === 0
|
||||
? 'No tanks found.'
|
||||
: `\`\`\`\n${results.join('\n')}\n\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
+76
-169
@@ -1,178 +1,85 @@
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
SlashCommandBuilder,
|
||||
} from 'discord.js';
|
||||
import GenericAllStats from '../components/GenericAllStats.js';
|
||||
import NoData, { NoDataType } from '../components/NoData.js';
|
||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||
import TitleBar from '../components/TitleBar.js';
|
||||
import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import sumStats from '../core/blitz/sumStats.js';
|
||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
|
||||
import getPeriodicStart from '../core/blitzstars/getPeriodStart.js';
|
||||
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js';
|
||||
import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js';
|
||||
import addStatPeriodChoices, {
|
||||
StatPeriod,
|
||||
statPeriodNames,
|
||||
} from '../core/options/addStatPeriodChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import {
|
||||
AccountInfo,
|
||||
AllStats,
|
||||
SupplementaryStats,
|
||||
} from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||
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 resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
||||
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { StatType } from '../renderers/fullStats';
|
||||
import stats from '../renderers/stats';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export default {
|
||||
export const statsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('stats'))
|
||||
.setDescription("Gets the user's in-game statistics")
|
||||
.addStringOption(addStatPeriodChoices)
|
||||
.addStringOption(addUsernameOption),
|
||||
command: addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('stats')
|
||||
.setDescription('Regular battles statistics'),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const period = interaction.options.getString('period') as StatPeriod;
|
||||
const { id, server } = await getBlitzAccount(interaction);
|
||||
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 tankStats = await getTankStats(interaction, server, id);
|
||||
let stats: AllStats;
|
||||
let supplementaryStats: SupplementaryStats | undefined;
|
||||
let hasWN8AccumulatedAtAll = false;
|
||||
|
||||
if (period === 'career') {
|
||||
stats = accountInfo[id].statistics.all;
|
||||
const totalBattles = tankStats.reduce(
|
||||
(accumulator, { all }) => accumulator + all.battles,
|
||||
0,
|
||||
);
|
||||
|
||||
supplementaryStats = {
|
||||
tier:
|
||||
tankStats.reduce(
|
||||
(accumulator, { tank_id, all }) =>
|
||||
accumulator + tankopedia[tank_id].tier * all.battles,
|
||||
0,
|
||||
) / totalBattles,
|
||||
WN8:
|
||||
tankStats.reduce((accumulator, { tank_id, all }) => {
|
||||
if (tankAverages[tank_id]) {
|
||||
const tankWN8 = getWN8(tankAverages[tank_id].all, all);
|
||||
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
|
||||
hasWN8AccumulatedAtAll = true;
|
||||
|
||||
return accumulator + tankWN8 * all.battles;
|
||||
} else return accumulator;
|
||||
}, 0) / totalBattles,
|
||||
};
|
||||
} else {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
getPeriodicStart(period),
|
||||
getPeriodNow(),
|
||||
);
|
||||
const entries = Object.entries(tankStatsOverTime);
|
||||
const totalBattles = entries.reduce(
|
||||
(accumulator, [, stats]) => accumulator + stats.battles,
|
||||
0,
|
||||
);
|
||||
|
||||
supplementaryStats = {
|
||||
tier:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankTier = tankopedia[tankId].tier;
|
||||
|
||||
return accumulator + tankTier * stats.battles;
|
||||
}, 0) / totalBattles,
|
||||
WN8:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
// edge case where new tanks don't have averages
|
||||
if (tankAverages[tankId]) {
|
||||
const tankWN8 = getWN8(tankAverages[tankId].all, stats);
|
||||
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
|
||||
hasWN8AccumulatedAtAll = true;
|
||||
|
||||
return accumulator + tankWN8 * stats.battles;
|
||||
} else return accumulator;
|
||||
}, 0) / totalBattles,
|
||||
};
|
||||
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
}
|
||||
|
||||
if (!hasWN8AccumulatedAtAll) supplementaryStats.WN8 = undefined;
|
||||
|
||||
const image = await render(
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={
|
||||
clanData[id]?.clan ? `[${clanData[id]?.clan?.tag}]` : undefined
|
||||
}
|
||||
image={
|
||||
clanData[id]?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||
: undefined
|
||||
}
|
||||
description={`${
|
||||
statPeriodNames[period]
|
||||
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
||||
/>
|
||||
|
||||
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
{stats.battles > 0 && (
|
||||
<GenericAllStats
|
||||
stats={stats}
|
||||
supplementaryStats={supplementaryStats}
|
||||
/>
|
||||
)}
|
||||
|
||||
<PoweredByBlitzStars />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
fullBlitzStarsStats(server, accountInfo[id].nickname),
|
||||
supportBlitzStars,
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
files: [image],
|
||||
components: [actionRow],
|
||||
async handler(interaction) {
|
||||
const commandGroup = interaction.options.getSubcommandGroup(
|
||||
true,
|
||||
) as StatType;
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||
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,
|
||||
tankId,
|
||||
start,
|
||||
end,
|
||||
});
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
|
||||
return [
|
||||
await stats(commandGroup, period, player, tankId),
|
||||
primaryButton(path, 'Refresh'),
|
||||
linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
autocomplete: (interaction) => {
|
||||
autocompleteUsername(interaction);
|
||||
autocompleteTanks(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 period = resolvePeriodFromButton(player.region, interaction);
|
||||
|
||||
return await stats(
|
||||
commandGroup,
|
||||
period,
|
||||
player,
|
||||
parseInt(url.searchParams.get('tankId')!),
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,125 +0,0 @@
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
SlashCommandBuilder,
|
||||
} from 'discord.js';
|
||||
import GenericAllStats from '../components/GenericAllStats.js';
|
||||
import NoData, { NoDataType } from '../components/NoData.js';
|
||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||
import TitleBar from '../components/TitleBar.js';
|
||||
import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import tanksAutocomplete from '../core/autocomplete/tanks.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankId from '../core/blitz/resolveTankId.js';
|
||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
|
||||
import getPeriodicStart from '../core/blitzstars/getPeriodStart.js';
|
||||
import getTankStatsOverTime, {
|
||||
emptyAllStats,
|
||||
} from '../core/blitzstars/getTankStatsOverTime.js';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js';
|
||||
import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js';
|
||||
import addStatPeriodChoices, {
|
||||
StatPeriod,
|
||||
statPeriodNames,
|
||||
} from '../core/options/addStatPeriodChoices.js';
|
||||
import addTankChoices from '../core/options/addTankChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('tankstats'))
|
||||
.setDescription('Stats for a tank over a period')
|
||||
.addStringOption(addTankChoices)
|
||||
.addStringOption(addStatPeriodChoices)
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const tank = await resolveTankId(
|
||||
interaction,
|
||||
interaction.options.getString('tank')!,
|
||||
);
|
||||
const period = interaction.options.getString('period') as StatPeriod;
|
||||
const blitzAccount = await getBlitzAccount(interaction);
|
||||
const { id, server } = blitzAccount;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getTankStats(interaction, server, id);
|
||||
let stats: AllStats;
|
||||
const tankId = Number(tank);
|
||||
|
||||
if (period === 'career') {
|
||||
stats =
|
||||
tankStats.find((stats) => stats.tank_id === tankId)?.all ??
|
||||
emptyAllStats;
|
||||
} else {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
getPeriodicStart(period),
|
||||
getPeriodNow(),
|
||||
);
|
||||
|
||||
stats = tankStatsOverTime[tankId] ?? emptyAllStats;
|
||||
}
|
||||
|
||||
const image = await render(
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={`(${resolveTankName(tankId)})`}
|
||||
image={tankopedia[tankId].images.normal}
|
||||
description={`${
|
||||
statPeriodNames[period]
|
||||
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
||||
/>
|
||||
|
||||
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
{stats.battles > 0 && (
|
||||
<GenericAllStats
|
||||
stats={stats}
|
||||
supplementaryStats={{
|
||||
tier: tankopedia[tankId].tier,
|
||||
WN8: getWN8(tankAverages[tankId].all, stats),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<PoweredByBlitzStars />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
fullBlitzStarsStats(server, accountInfo[id].nickname),
|
||||
supportBlitzStars,
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
files: [image],
|
||||
components: [actionRow],
|
||||
});
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
tanksAutocomplete(interaction);
|
||||
usernameAutocomplete(interaction);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
+52
-187
@@ -1,198 +1,63 @@
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
SlashCommandBuilder,
|
||||
} from 'discord.js';
|
||||
import * as Breakdown from '../components/Breakdown/index.js';
|
||||
import NoData, { NoDataType } from '../components/NoData.js';
|
||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||
import TitleBar from '../components/TitleBar.js';
|
||||
import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
||||
import sumStats from '../core/blitz/sumStats.js';
|
||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||
import last5AM from '../core/blitzstars/last5AM.js';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js';
|
||||
import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
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 { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import today from '../renderers/today';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export default {
|
||||
export const todayCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('today'))
|
||||
.setName('today')
|
||||
.setDescription('A general daily breakdown of your performance')
|
||||
.addStringOption(addUsernameOption),
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription(
|
||||
'The maximum number of tanks to display (default: Infinity)',
|
||||
)
|
||||
.setRequired(false)
|
||||
.setMinValue(1),
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const { id, server } = await getBlitzAccount(interaction);
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
last5AM().getTime() / 1000,
|
||||
new Date().getTime() / 1000,
|
||||
);
|
||||
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 careerTankStatsRaw = await getTankStats(interaction, server, id);
|
||||
const careerStats: Record<number, AllStats> = {
|
||||
0: accountInfo[id].statistics.all,
|
||||
};
|
||||
const allStatsToAccumulate: AllStats[] = [];
|
||||
async handler(interaction) {
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const limit = interaction.options.getInteger('limit') ?? Infinity;
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
const path = interactionToURL(interaction, player);
|
||||
|
||||
Object.entries(tankStatsOverTime).forEach(([, tankStats]) => {
|
||||
allStatsToAccumulate.push(tankStats);
|
||||
});
|
||||
Object.entries(careerTankStatsRaw).forEach(([, tankStats]) => {
|
||||
careerStats[tankStats.tank_id] = tankStats.all;
|
||||
});
|
||||
|
||||
const accumulatedStats = sumStats(allStatsToAccumulate);
|
||||
|
||||
if (Object.keys(tankStatsOverTime).length > 0) {
|
||||
tankStatsOverTime[0] = accumulatedStats;
|
||||
}
|
||||
|
||||
const tankStatsOverTimeEntries = Object.entries(tankStatsOverTime);
|
||||
const todayWN8s = tankStatsOverTimeEntries.reduce<Record<number, number>>(
|
||||
(accumulator, [tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
|
||||
return tankId === 0 || tankAverages[tankId] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tankId]: getWN8(tankAverages[tankId].all, tankStats),
|
||||
};
|
||||
},
|
||||
{},
|
||||
);
|
||||
const careerWN8s = careerTankStatsRaw.reduce<Record<number, number>>(
|
||||
(accumulator, { tank_id }) => {
|
||||
return tank_id === 0 || tankAverages[tank_id] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tank_id]: getWN8(
|
||||
tankAverages[tank_id].all,
|
||||
careerStats[tank_id],
|
||||
),
|
||||
};
|
||||
},
|
||||
{},
|
||||
);
|
||||
const todayWN8sEntries = Object.entries(todayWN8s);
|
||||
const careerWN8sEntries = Object.entries(careerWN8s);
|
||||
|
||||
todayWN8s[0] =
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, wn8]) =>
|
||||
accumulator + wn8 * tankStatsOverTime[Number(tankIdString)].battles,
|
||||
0,
|
||||
) /
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString]) =>
|
||||
accumulator + tankStatsOverTime[Number(tankIdString)].battles,
|
||||
0,
|
||||
);
|
||||
careerWN8s[0] =
|
||||
careerWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, WN8]) =>
|
||||
isNaN(WN8)
|
||||
? accumulator
|
||||
: accumulator + WN8 * careerStats[Number(tankIdString)].battles,
|
||||
0,
|
||||
) /
|
||||
careerWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, WN8]) =>
|
||||
isNaN(WN8)
|
||||
? accumulator
|
||||
: accumulator + careerStats[Number(tankIdString)].battles,
|
||||
0,
|
||||
);
|
||||
|
||||
const rows = tankStatsOverTimeEntries.map(([tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const career = careerStats[tankId];
|
||||
|
||||
return (
|
||||
<Breakdown.Row
|
||||
key={tankId}
|
||||
name={tankId === 0 ? 'Total' : resolveTankName(Number(tankIdString))}
|
||||
winrate={tankStats.wins / tankStats.battles}
|
||||
careerWinrate={career.wins / career.battles}
|
||||
WN8={isNaN(todayWN8s[tankId]) ? undefined : todayWN8s[tankId]}
|
||||
careerWN8={isNaN(careerWN8s[tankId]) ? undefined : careerWN8s[tankId]}
|
||||
damage={tankStats.damage_dealt / tankStats.battles}
|
||||
careerDamage={career.damage_dealt / career.battles}
|
||||
survival={tankStats.survived_battles / tankStats.battles}
|
||||
careerSurvival={career.survived_battles / career.battles}
|
||||
battles={tankStats.battles}
|
||||
careerBattles={career.battles}
|
||||
icon={
|
||||
tankId === 0
|
||||
? undefined
|
||||
: tankopedia[tankIdString as unknown as number].images.normal
|
||||
}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
const image = await render(
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={
|
||||
clanData[id]?.clan ? `[${clanData[id]?.clan?.tag}]` : undefined
|
||||
}
|
||||
image={
|
||||
clanData[id]?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||
: undefined
|
||||
}
|
||||
description={`Today's breakdown • ${new Date().toDateString()} • ${
|
||||
BLITZ_SERVERS[server]
|
||||
}`}
|
||||
/>
|
||||
|
||||
{rows.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
{rows.length > 0 && <Breakdown.Root>{rows}</Breakdown.Root>}
|
||||
|
||||
<PoweredByBlitzStars />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
fullBlitzStarsStats(server, accountInfo[id].nickname),
|
||||
supportBlitzStars,
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
files: [image],
|
||||
components: [actionRow],
|
||||
});
|
||||
return [
|
||||
await today(player, limit, false),
|
||||
primaryButton(path, 'Refresh'),
|
||||
linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
autocomplete: autocompleteUsername,
|
||||
|
||||
async button(interaction) {
|
||||
const player = await resolvePlayerFromButton(interaction);
|
||||
|
||||
return await today(player);
|
||||
},
|
||||
};
|
||||
+57
-92
@@ -1,118 +1,83 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
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 { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
|
||||
export default {
|
||||
export const verifyCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('verify'))
|
||||
.setName('verify')
|
||||
.setDescription("Set's the user's username to their in-game name")
|
||||
.addStringOption((option) => addUsernameOption(option).setRequired(true)),
|
||||
.addStringOption((option) => addUsernameChoices(option).setRequired(true)),
|
||||
|
||||
async execute(interaction) {
|
||||
const blitzAccount = await getBlitzAccount(interaction);
|
||||
const { id, server } = blitzAccount;
|
||||
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}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.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`,
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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')) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(
|
||||
`${markdownEscape(interaction.user.username)} failed to verify`,
|
||||
)
|
||||
.setDescription(
|
||||
"I don't have the permission to change your nickname.",
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
return;
|
||||
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?",
|
||||
);
|
||||
}
|
||||
|
||||
if (interaction.member) {
|
||||
const member = interaction.guild?.members.cache.get(
|
||||
interaction.member?.user.id,
|
||||
);
|
||||
try {
|
||||
await member.setNickname(`${accountInfo[id].nickname}${clanTag}`);
|
||||
|
||||
if (member) {
|
||||
try {
|
||||
await member.setNickname(`${accountInfo[id].nickname}${clanTag}`);
|
||||
|
||||
if (interaction.guildId === discord.sklld_guild_id) {
|
||||
if (
|
||||
!interaction.guild?.members.me?.permissions.has('ManageRoles')
|
||||
) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(
|
||||
`${markdownEscape(
|
||||
interaction.user.username,
|
||||
)} failed to verify`,
|
||||
)
|
||||
.setDescription(
|
||||
"I don't have the permission to change your manage roles.",
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await member.roles.remove(discord.sklld_verify_role);
|
||||
await member.roles.add(discord.sklld_peasant_role);
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${markdownEscape(
|
||||
accountInfo[id].nickname,
|
||||
)}${markdownEscape(clanTag)}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} failed to verify`)
|
||||
.setDescription(
|
||||
"I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.",
|
||||
),
|
||||
],
|
||||
});
|
||||
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: usernameAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
autocomplete: autocompleteUsername,
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Percentile } from '../../../../../constants/percentiles';
|
||||
import hslToHex from '../../../../../core/node/hslToHex';
|
||||
import { PERCENTILE_COLORS } from '../../../../PercentileIndicator';
|
||||
|
||||
export enum GlowSide {
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
export interface GlowProps {
|
||||
percentile: Percentile;
|
||||
side: GlowSide;
|
||||
}
|
||||
|
||||
export function Glow({ percentile, side }: GlowProps) {
|
||||
const color = PERCENTILE_COLORS[percentile];
|
||||
const color1 = hslToHex(color);
|
||||
const color2 = `${color1}00`;
|
||||
|
||||
const background = `linear-gradient(${
|
||||
side === GlowSide.Top ? 0 : 180
|
||||
}deg, ${color1} 0%, ${color2} 100%)`;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: side === GlowSide.Top ? 'flex-end' : 'flex-start',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<div style={{ height: 54, width: 16, background }} />
|
||||
<div style={{ height: 72, width: 16, background }} />
|
||||
<div style={{ height: 80, width: 16, background }} />
|
||||
<div style={{ height: 72, width: 16, background }} />
|
||||
<div style={{ height: 54, width: 16, background }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { Percentile } from '../../../../constants/percentiles';
|
||||
import getWN8Percentile from '../../../../core/blitz/getWN8Percentile';
|
||||
import { theme } from '../../../../stitches.config';
|
||||
import { PERCENTILE_COLORS } from '../../../PercentileIndicator';
|
||||
import { Glow, GlowSide } from './components/Glow';
|
||||
|
||||
export interface WN8DisplayProps {
|
||||
WN8?: number;
|
||||
}
|
||||
|
||||
export const PERCENTILE_NAMES = {
|
||||
[Percentile.VeryBad]: 'Very Bad',
|
||||
[Percentile.Bad]: 'Bad',
|
||||
[Percentile.BelowAverage]: 'Below Average',
|
||||
[Percentile.Average]: 'Average',
|
||||
[Percentile.AboveAverage]: 'Above Average',
|
||||
[Percentile.Good]: 'Good',
|
||||
[Percentile.VeryGood]: 'Very Good',
|
||||
[Percentile.Great]: 'Great',
|
||||
[Percentile.Unicum]: 'Unicum',
|
||||
[Percentile.SuperUnicum]: 'Super Unicum',
|
||||
};
|
||||
|
||||
export function WN8Display({ WN8 }: WN8DisplayProps) {
|
||||
const percentile =
|
||||
WN8 === undefined ? Percentile.VeryBad : getWN8Percentile(WN8);
|
||||
const color = PERCENTILE_COLORS[percentile];
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
width: 128 * 2, // idk why twice the width turns into the correct width
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: -16,
|
||||
}}
|
||||
>
|
||||
<Glow percentile={percentile} side={GlowSide.Top} />
|
||||
|
||||
<div
|
||||
style={{
|
||||
width: 128,
|
||||
height: 80,
|
||||
backgroundColor: color,
|
||||
borderRadius: 40,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: -4,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
fontWeight: 900,
|
||||
fontSize: 32,
|
||||
color: theme.colors.textHighContrast,
|
||||
}}
|
||||
>
|
||||
{WN8 === undefined ? '--' : WN8.toFixed(0)}
|
||||
</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 16,
|
||||
color: theme.colors.textHighContrast,
|
||||
}}
|
||||
>
|
||||
{PERCENTILE_NAMES[percentile]}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Glow percentile={percentile} side={GlowSide.Bottom} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { theme } from '../../../stitches.config';
|
||||
|
||||
export enum WN8SurroundingStatAlign {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
export interface WN8SurroundingStatProps {
|
||||
label: string;
|
||||
value: string | number;
|
||||
align?: WN8SurroundingStatAlign;
|
||||
padded?: boolean;
|
||||
}
|
||||
|
||||
export function WN8SurroundingStat({
|
||||
label,
|
||||
value,
|
||||
align = WN8SurroundingStatAlign.Left,
|
||||
padded = false,
|
||||
}: WN8SurroundingStatProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems:
|
||||
align === WN8SurroundingStatAlign.Left ? 'flex-start' : 'flex-end',
|
||||
paddingLeft: padded && align === WN8SurroundingStatAlign.Left ? 32 : 0,
|
||||
paddingRight:
|
||||
padded && align === WN8SurroundingStatAlign.Right ? 32 : 0,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textHighContrast,
|
||||
fontSize: 24,
|
||||
fontWeight: 'bold',
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</span>
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 16 }}>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { AllStats, SupplementaryStats } from '../../types/accountInfo';
|
||||
import { WN8Display } from './components/WN8Display';
|
||||
import {
|
||||
WN8SurroundingStat,
|
||||
WN8SurroundingStatAlign,
|
||||
} from './components/WN8SurroundingStat';
|
||||
|
||||
export interface AllStatsOverviewProps {
|
||||
stats: AllStats;
|
||||
supplementaryStats: SupplementaryStats;
|
||||
}
|
||||
|
||||
export default function AllStatsOverview({
|
||||
stats,
|
||||
supplementaryStats,
|
||||
}: AllStatsOverviewProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: -64,
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 8,
|
||||
alignItems: 'flex-end',
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<WN8SurroundingStat
|
||||
label="Battles"
|
||||
value={stats.battles.toLocaleString()}
|
||||
align={WN8SurroundingStatAlign.Right}
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Winrate"
|
||||
value={`${(100 * (stats.wins / stats.battles)).toFixed(2)}%`}
|
||||
align={WN8SurroundingStatAlign.Right}
|
||||
padded
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Damage"
|
||||
value={Math.round(
|
||||
stats.damage_dealt / stats.battles,
|
||||
).toLocaleString()}
|
||||
align={WN8SurroundingStatAlign.Right}
|
||||
padded
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Dmg. ratio"
|
||||
value={(stats.damage_dealt / stats.damage_received).toFixed(2)}
|
||||
align={WN8SurroundingStatAlign.Right}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<WN8Display WN8={supplementaryStats.WN8} />
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 8,
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<WN8SurroundingStat
|
||||
label="Tier"
|
||||
value={
|
||||
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
|
||||
}
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Survival"
|
||||
value={`${(100 * (stats.survived_battles / stats.battles)).toFixed(
|
||||
2,
|
||||
)}%`}
|
||||
padded
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Accuracy"
|
||||
value={`${(100 * (stats.hits / stats.shots)).toFixed(2)}%`}
|
||||
padded
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Kill ratio"
|
||||
value={(
|
||||
stats.frags /
|
||||
(stats.battles - stats.survived_battles)
|
||||
).toFixed(2)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export interface RootProps {
|
||||
|
||||
export function Root({ children }: RootProps) {
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import getWN8Percentile from '../../../core/blitz/getWN8Percentile.js';
|
||||
import { RowDiscriminator } from './RowDiscriminator.js';
|
||||
import { RowStat } from './RowStat.js';
|
||||
import getWN8Percentile from '../../../core/blitz/getWN8Percentile';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import { RowDiscriminator } from './RowDiscriminator';
|
||||
import { RowStat } from './RowStat';
|
||||
|
||||
export interface RowProps {
|
||||
name: string;
|
||||
@@ -10,14 +11,17 @@ export interface RowProps {
|
||||
careerWN8?: number;
|
||||
damage: number;
|
||||
careerDamage: number;
|
||||
survival: number;
|
||||
careerSurvival: number;
|
||||
battles: number;
|
||||
careerBattles: number;
|
||||
icon?: string;
|
||||
minimized: boolean;
|
||||
isListing: boolean;
|
||||
naked?: boolean;
|
||||
}
|
||||
|
||||
export function Row({
|
||||
isListing,
|
||||
minimized,
|
||||
name,
|
||||
winrate,
|
||||
careerWinrate,
|
||||
@@ -25,44 +29,46 @@ export function Row({
|
||||
careerWN8,
|
||||
damage,
|
||||
careerDamage,
|
||||
survival,
|
||||
careerSurvival,
|
||||
battles,
|
||||
careerBattles,
|
||||
icon,
|
||||
naked,
|
||||
}: RowProps) {
|
||||
return (
|
||||
<div style={{ display: 'flex', gap: 16 }}>
|
||||
<RowDiscriminator name={name} icon={icon} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
borderRadius: 4,
|
||||
backgroundColor: isListing
|
||||
? theme.colors.componentInteractive
|
||||
: theme.colors.appBackground2,
|
||||
padding: 8,
|
||||
}}
|
||||
>
|
||||
<RowDiscriminator minimized={minimized} name={name} icon={icon} />
|
||||
|
||||
<RowStat
|
||||
name="Winrate"
|
||||
minimized={minimized}
|
||||
name={`Winrate • ${(careerWinrate * 100).toFixed(2)}%`}
|
||||
value={`${(winrate * 100).toFixed(2)}%`}
|
||||
career={`${(careerWinrate * 100).toFixed(2)}%`}
|
||||
delta={winrate - careerWinrate}
|
||||
/>
|
||||
<RowStat
|
||||
name="WN8"
|
||||
minimized={minimized}
|
||||
name={`WN8 • ${careerWN8 === undefined ? '--' : careerWN8.toFixed(0)}`}
|
||||
value={WN8 === undefined ? '--' : WN8.toFixed(0)}
|
||||
career={careerWN8 === undefined ? '--' : careerWN8.toFixed(0)}
|
||||
percentile={WN8 === undefined ? undefined : getWN8Percentile(WN8)}
|
||||
/>
|
||||
<RowStat
|
||||
name="Damage"
|
||||
value={damage.toFixed(2)}
|
||||
career={careerDamage.toFixed(2)}
|
||||
minimized={minimized}
|
||||
name={`Damage • ${careerDamage.toFixed(0)}`}
|
||||
value={damage.toFixed(0)}
|
||||
delta={damage - careerDamage}
|
||||
/>
|
||||
<RowStat
|
||||
name="Survival"
|
||||
value={`${(survival * 100).toFixed(2)}%`}
|
||||
career={`${(careerSurvival * 100).toFixed(2)}%`}
|
||||
delta={survival - careerSurvival}
|
||||
/>
|
||||
<RowStat
|
||||
name="Battles"
|
||||
minimized={minimized}
|
||||
name={`Battles • ${careerBattles.toFixed(0)}`}
|
||||
value={battles.toFixed(0)}
|
||||
career={careerBattles.toFixed(0)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { theme } from '../../../stitches.config.js';
|
||||
import { theme } from '../../../stitches.config';
|
||||
|
||||
export interface RowDiscriminatorProps {
|
||||
name: string;
|
||||
icon?: string;
|
||||
minimized: boolean;
|
||||
}
|
||||
|
||||
export function RowDiscriminator({ name, icon }: RowDiscriminatorProps) {
|
||||
export function RowDiscriminator({
|
||||
name,
|
||||
icon,
|
||||
minimized,
|
||||
}: RowDiscriminatorProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
@@ -19,7 +24,7 @@ export function RowDiscriminator({ name, icon }: RowDiscriminatorProps) {
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
{icon && (
|
||||
{!minimized && icon && (
|
||||
<img
|
||||
src={icon}
|
||||
height={0}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { Percentile } from '../../../constants/percentiles.js';
|
||||
import { theme } from '../../../stitches.config.js';
|
||||
import PercentileIndicator from '../../PercentileIndicator.js';
|
||||
import { Percentile } from '../../../constants/percentiles';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import PercentileIndicator from '../../PercentileIndicator';
|
||||
|
||||
export interface RowStatProps {
|
||||
name: string;
|
||||
value: string;
|
||||
career: string;
|
||||
value: string | number;
|
||||
delta?: number;
|
||||
percentile?: Percentile;
|
||||
minimized?: boolean;
|
||||
}
|
||||
|
||||
export function RowStat({
|
||||
name,
|
||||
value,
|
||||
career,
|
||||
delta,
|
||||
percentile,
|
||||
minimized,
|
||||
}: RowStatProps) {
|
||||
return (
|
||||
<div
|
||||
@@ -28,10 +28,6 @@ export function RowStat({
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 12 }}>
|
||||
{career}
|
||||
</span>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
@@ -58,16 +54,17 @@ export function RowStat({
|
||||
style={{
|
||||
color: theme.colors.textHighContrast,
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 12 }}>
|
||||
{name}
|
||||
</span>
|
||||
{!minimized && (
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 12 }}>
|
||||
{name}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './components/Root.js';
|
||||
export * from './components/Row.js';
|
||||
export * from './components/RowDiscriminator.js';
|
||||
export * from './components/RowStat.js';
|
||||
export * from './components/Root';
|
||||
export * from './components/Row';
|
||||
export * from './components/RowDiscriminator';
|
||||
export * from './components/RowStat';
|
||||
@@ -1,55 +0,0 @@
|
||||
import getWN8Percentile from '../core/blitz/getWN8Percentile.js';
|
||||
import { AllStats, SupplementaryStats } from '../types/accountInfo.js';
|
||||
import GenericStats from './GenericStats/index.js';
|
||||
|
||||
export interface GenericAllStatsProps {
|
||||
stats: AllStats;
|
||||
supplementaryStats?: SupplementaryStats;
|
||||
}
|
||||
|
||||
export default function GenericAllStats({
|
||||
stats,
|
||||
supplementaryStats,
|
||||
}: GenericAllStatsProps) {
|
||||
return (
|
||||
<GenericStats
|
||||
stats={[
|
||||
['Winrate', `${(100 * (stats.wins / stats.battles)).toFixed(2)}%`],
|
||||
[
|
||||
'WN8',
|
||||
supplementaryStats
|
||||
? supplementaryStats.WN8 === undefined
|
||||
? '--'
|
||||
: supplementaryStats.WN8.toFixed(0)
|
||||
: undefined,
|
||||
supplementaryStats?.WN8 === undefined
|
||||
? undefined
|
||||
: getWN8Percentile(supplementaryStats.WN8),
|
||||
],
|
||||
[
|
||||
'Survival',
|
||||
`${(100 * (stats.survived_battles / stats.battles)).toFixed(2)}%`,
|
||||
],
|
||||
['Accuracy', `${((stats.hits / stats.shots) * 100).toFixed(2)}%`],
|
||||
['Battles', stats.battles],
|
||||
['Wins', stats.wins],
|
||||
['Losses', stats.losses],
|
||||
['Average damage', (stats.damage_dealt / stats.battles).toFixed(0)],
|
||||
['Average tier', supplementaryStats?.tier.toFixed(2)],
|
||||
['Average XP', (stats.xp / stats.battles).toFixed(0)],
|
||||
['Average shots', (stats.shots / stats.battles).toFixed(2)],
|
||||
['Average hits', (stats.hits / stats.battles).toFixed(2)],
|
||||
['Average kills', (stats.frags / stats.battles).toFixed(2)],
|
||||
['Average spots', (stats.spotted / stats.battles).toFixed(2)],
|
||||
[
|
||||
'Damage ratio',
|
||||
(stats.damage_dealt / stats.damage_received).toFixed(2),
|
||||
],
|
||||
[
|
||||
'Kills to death ratio',
|
||||
(stats.frags / (stats.battles - stats.survived_battles)).toFixed(2),
|
||||
],
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Percentile } from '../../../constants/percentiles';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import PercentileIndicator from '../../PercentileIndicator';
|
||||
|
||||
export interface CardItem {
|
||||
label: string;
|
||||
value: string | number | undefined;
|
||||
percentile?: Percentile;
|
||||
}
|
||||
|
||||
export interface CardProps {
|
||||
items: CardItem[];
|
||||
title: string;
|
||||
}
|
||||
|
||||
export function Card({ items, title }: CardProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 16,
|
||||
flex: 1,
|
||||
borderRadius: 4,
|
||||
backgroundColor: theme.colors.componentInteractive,
|
||||
padding: 8,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textHighContrast,
|
||||
fontSize: 24,
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</span>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
{items.map((item) => (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 16, color: theme.colors.textLowContrast }}>
|
||||
{item.label}
|
||||
</span>
|
||||
|
||||
<div
|
||||
style={{
|
||||
flex: 1,
|
||||
height: 1,
|
||||
borderRadius: 0.5,
|
||||
backgroundColor: theme.colors.borderNonInteractive,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 4,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
{item.percentile !== undefined && (
|
||||
<PercentileIndicator percentile={item.percentile} />
|
||||
)}
|
||||
<span
|
||||
style={{ fontSize: 16, color: theme.colors.textHighContrast }}
|
||||
>
|
||||
{item.value === undefined || Number.isNaN(item.value)
|
||||
? '--'
|
||||
: item.value}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loaded 100 of 233 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user