mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
331040bbdf | ||
|
|
70e1d4b30d | ||
|
|
03dbd797fb | ||
|
|
28172f7f8f | ||
|
|
cb5347cbb8 | ||
|
|
1ce0781d2d | ||
|
|
1257aa76d7 | ||
|
|
6ec3835896 | ||
|
|
506fe7d9bd | ||
|
|
14ef9f6295 | ||
|
|
0d76e1a29e | ||
|
|
9e42d7e8f5 | ||
|
|
364f97332b | ||
|
|
caa7bb8a65 | ||
|
|
3e956b34c1 | ||
|
|
038374e5aa | ||
|
|
dafd54f830 | ||
|
|
cb65e6b0af | ||
|
|
4ca8590c83 | ||
|
|
c5ef02d7e6 | ||
|
|
8175aa8715 | ||
|
|
b426634659 | ||
|
|
e92da1b700 | ||
|
|
7e0a2e88ee | ||
|
|
16afa8c2d4 | ||
|
|
907288455a | ||
|
|
64689e4e3b | ||
|
|
294377846a | ||
|
|
70e4cbaba2 | ||
|
|
9e2f9526fb | ||
|
|
84bec20fa5 | ||
|
|
e9a492fde6 | ||
|
|
76a69f08b4 | ||
|
|
893110d3ef | ||
|
|
70575fa9cf | ||
|
|
bb2450eb3c | ||
|
|
ab56689326 | ||
|
|
a9cf07480a | ||
|
|
c81de2d758 | ||
|
|
aa1c7639f2 | ||
|
|
d448101b32 | ||
|
|
e806f0ede2 | ||
|
|
8253c27333 | ||
|
|
254392370f | ||
|
|
d2319688a5 | ||
|
|
ffebe6c696 | ||
|
|
9e4094f3a9 | ||
|
|
f7eadb08a9 | ||
|
|
d511cfa4cc | ||
|
|
270a3051b7 | ||
|
|
81bc9f9ba6 | ||
|
|
338cec4f18 | ||
|
|
b455e3380f | ||
|
|
92761f2c55 | ||
|
|
7823b8ad2e | ||
|
|
cac82f3124 | ||
|
|
4b892d06e4 | ||
|
|
92149b0f00 | ||
|
|
399aa4c03c | ||
|
|
d5de715032 | ||
|
|
e6fb179184 | ||
|
|
af54f12ec3 | ||
|
|
909cabd517 | ||
|
|
a734a71d2f | ||
|
|
91dc45c880 | ||
|
|
91f364b76a | ||
|
|
23dd088466 | ||
|
|
2cabcc57f4 | ||
|
|
dd6092a5e7 |
No files matched your search
@@ -29,4 +29,4 @@ jobs:
|
||||
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
|
||||
run: NODE_ENV=production GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} node --enable-source-maps --trace-warnings bot.cjs
|
||||
@@ -1,4 +1,7 @@
|
||||
import { DefaultTheme, defineConfig } from 'vitepress';
|
||||
import { compareVersions } from 'compare-versions';
|
||||
import { readdirSync } from 'fs';
|
||||
import { parse } from 'path';
|
||||
import { defineConfig } from 'vitepress';
|
||||
import { getSidebar } from 'vitepress-plugin-auto-sidebar';
|
||||
|
||||
export default defineConfig({
|
||||
@@ -9,17 +12,27 @@ export default defineConfig({
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Home', link: '/' },
|
||||
{ text: 'Examples', link: '/markdown-examples' },
|
||||
{ text: 'Guide', link: '/guide/about' },
|
||||
],
|
||||
|
||||
sidebar: getSidebar({
|
||||
collapsed: false,
|
||||
contentDirs: ['guide', 'legal', 'changelogs'],
|
||||
contentRoot: '/docs/',
|
||||
}) as DefaultTheme.Sidebar,
|
||||
sidebar: [
|
||||
...getSidebar({
|
||||
collapsed: false,
|
||||
contentDirs: ['guide', 'legal'],
|
||||
contentRoot: '/docs/',
|
||||
}),
|
||||
|
||||
{
|
||||
text: 'Changelogs',
|
||||
items: readdirSync('./docs/changelogs')
|
||||
.map((file) => parse(file).name)
|
||||
.sort(compareVersions)
|
||||
.map((name) => ({ text: name, link: `/changelogs/${name}.html` })),
|
||||
},
|
||||
],
|
||||
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
|
||||
{ icon: 'github', link: 'https://github.com/tresabhi/blitzkrieg' },
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -12,7 +12,7 @@ I am going on vacation so I thought I'd publish this a bit prematurely without a
|
||||
- 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
|
||||
## Fixes
|
||||
|
||||
- Removed region "Europe" in `/verify` example
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# Blitzkrieg 1.12.0
|
||||
|
||||
_Houston, permission to return to Earth? A new update dropped._
|
||||
|
||||
## Features
|
||||
|
||||
- Added `multi-tank` filters to `/stats` and `/full-stats`
|
||||
- This lets you pull up the stats by combining filters of `nation`, `tank-type`, `tier`, and `tree-type`
|
||||
- Added `/ratings neighbours`
|
||||
- Lets you see your rank and the neighbours around you
|
||||
- Added a bunch more `/today` parameters (thank you for the suggestions, HisRoyalFatness!)
|
||||
- `cutoff`: the max number of rows to show (excluding the total row)
|
||||
- `maximized`: the max number of rows that show the full non-collapsed stats (default: `4`)
|
||||
- `show-total`: show the total row or not (default: `true`)
|
||||
- Tank search is now accent-tolerant
|
||||
|
||||
## Changes
|
||||
|
||||
- `/ratings` has been moved out of preview and is now accessible to all
|
||||
- `/today` now has a more appealing look with more efficient space management
|
||||
- `/stats`, `/full-stats`, and `/evolution` now have less convoluted commands
|
||||
- All periods now fall under `period` and `custom`
|
||||
- `period` has preset periods like `today`, `career`, `30`, `60`, `90`
|
||||
- `custom` lets you set a start and end day
|
||||
- Added dashes to command names, subcommands, options, etc. to make them more readable
|
||||
- Titlebar
|
||||
- Removed the Blitzkrieg logo
|
||||
- Removed region
|
||||
- Center aligned items
|
||||
- Footers are now center alinged when they do no have footer text on the left
|
||||
- Moved several title discriminators into the description
|
||||
- `/ratings` is now data-driven
|
||||
- Embeds now auto refresh every `30` seconds instead of `60`
|
||||
- Added numbers besides roman numerals in tier choice
|
||||
- I forgot to implement this in places other than `/owned-tanks`... oh well!
|
||||
- Increased precision of winrate in `/evolution` to `2` decimals
|
||||
|
||||
## Fixes
|
||||
|
||||
- Removed duplicate "Efficiency" cards in `/full-stats`
|
||||
- Titlebar gap is now `4px` just like Figma
|
||||
- Renamed `/statsfull` to `/full-stats` in the `/stats` footer
|
||||
- Rewards in `/ratings` are now properly aligned
|
||||
- `/ratings` now uses the correct source of information per region instead of getting it from a cached North American source
|
||||
- Search parameters are now passed onto the URL parser correctly
|
||||
- Custom date ranges now work correctly once again as the start is now the maximum days ago from today and the end is the minimum
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- All generated images are now `480px` wide instead of `640px` to combat the unnecessary amounts of negative space
|
||||
- Changed all relevant typings to be sourced from `stats` instead of `full-stats`
|
||||
- Added minimum character limit to clan search
|
||||
- Username auto-completing now only takes in regex-accepted parts of the input
|
||||
- Search parameters are now longer automatically generated by inferring command interactions
|
||||
@@ -0,0 +1,8 @@
|
||||
# Blitzkrieg 1.12.1
|
||||
|
||||
A duo of nasty bugs fixed.
|
||||
|
||||
## Fixes
|
||||
|
||||
- Fixed a tank index and id mismatch
|
||||
- Reverted username pattern infrence in command username inputs
|
||||
@@ -0,0 +1,29 @@
|
||||
# Blitzkrieg 1.12.2
|
||||
|
||||
A much needed room service is here!
|
||||
|
||||
## Changes
|
||||
|
||||
- Tier selection is now easier
|
||||
- Tier options across all commands have been unified to a single style
|
||||
- Tiers are now sorted from `10` to `1`
|
||||
- Tiers now show up in the format `Tier {tier_number} - {tier_roman_numeral}` (example: `Tier 8 - VIII`)
|
||||
- Removed powered by footer as links are provided regardless
|
||||
- Changed invite instructions to instead use application directory
|
||||
|
||||
## Fixes
|
||||
|
||||
- Guide link on the website is now fixed
|
||||
- Versions now show up in the correct order in the navigation bar
|
||||
- Added Blitzkrieg's GitHub link instead of the default Vitepress
|
||||
- Changed examples to guide in the navigation bar
|
||||
- Clan name and icon now show up with multi-tank filters
|
||||
- Removed a random `console.log`
|
||||
|
||||
## Technical Changes
|
||||
|
||||
- Added `knip`
|
||||
- Removed a lot of unused files and dependencies
|
||||
- Updated all dependencies to their latest
|
||||
- Code split `bot.ts`
|
||||
- `client` and `octokit` now reside separately
|
||||
@@ -0,0 +1,13 @@
|
||||
# Blitzkrieg 1.12.3
|
||||
|
||||
3-day downtime fixed!
|
||||
|
||||
## Changes
|
||||
|
||||
- Split `/ratings` into `/ratings current` and `/ratings archive`
|
||||
- `current` now properly handles when there is no ongoing ratings season
|
||||
- `archive` displays older archived seasons
|
||||
|
||||
## Fixes
|
||||
|
||||
- The bot is now no ratings seasons tolerant
|
||||
@@ -1,10 +1,3 @@
|
||||
# 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.
|
||||
Go to [application directory for Blitzkrieg](https://discord.com/application-directory/1097673957865443370) and click "Add to Server." Voila! You're ready to go.
|
||||
+1
-1
@@ -15,7 +15,7 @@ hero:
|
||||
link: guide/install
|
||||
- theme: alt
|
||||
text: Guide
|
||||
link: /guide
|
||||
link: /guide/about
|
||||
|
||||
features:
|
||||
- title: Clean and Efficient UI
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"main": "server.cjs",
|
||||
"main": "server.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node --enable-source-maps --trace-warnings server.cjs"
|
||||
}
|
||||
|
||||
+21
-19
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "blitzkrieg",
|
||||
"version": "1.10.2",
|
||||
"description": "",
|
||||
"version": "1.12.1",
|
||||
"description": "🎉 All-in-one Discord bot for everything World of Tanks Blitz",
|
||||
"main": "src/server.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build:bot": "vite-node --script scripts/build --build=bot",
|
||||
"build:server": "vite-node --script scripts/build --build=server",
|
||||
"build:bot": "node scripts/build --build=bot",
|
||||
"build:server": "node scripts/build --build=server",
|
||||
"build:docs": "vitepress build docs",
|
||||
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
||||
"build": "vite-node --script scripts/build --build=all",
|
||||
"build": "node 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",
|
||||
@@ -19,37 +19,39 @@
|
||||
"publish:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard --publish",
|
||||
"zip": "zip -r dist.zip dist",
|
||||
"lint": "npx tsc",
|
||||
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\""
|
||||
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
|
||||
"knip": "knip",
|
||||
"update": "yarn upgrade --latest"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.1",
|
||||
"@radix-ui/colors": "^0.1.8",
|
||||
"@radix-ui/colors": "^2.1.0",
|
||||
"@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",
|
||||
"discord.js": "^14.13.0",
|
||||
"esbuild": "^0.19.2",
|
||||
"express": "^4.18.2",
|
||||
"false": "^0.0.4",
|
||||
"fuzzysort": "^2.0.4",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-escape": "^2.0.0",
|
||||
"react": "^18.2.0",
|
||||
"satori": "^0.9.1",
|
||||
"vite-node": "^0.33.0",
|
||||
"satori": "^0.10.3",
|
||||
"vite-node": "^0.34.2",
|
||||
"vitepress-plugin-auto-sidebar": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@total-typescript/ts-reset": "^0.4.2",
|
||||
"@total-typescript/ts-reset": "^0.5.1",
|
||||
"@types/escape-html": "^1.0.2",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/lodash": "^4.14.197",
|
||||
"@types/markdown-escape": "^1.1.0",
|
||||
"@types/node": "^20.2.1",
|
||||
"@types/react": "^18.2.7",
|
||||
"prettier": "^3.0.0",
|
||||
"@types/node": "^20.5.3",
|
||||
"@types/react": "^18.2.21",
|
||||
"compare-versions": "^6.1.0",
|
||||
"knip": "^2.19.9",
|
||||
"prettier": "^3.0.2",
|
||||
"typescript": "^5.0.4",
|
||||
"vitepress": "^1.0.0-beta.3"
|
||||
"vitepress": "^1.0.0-rc.4"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BuildOptions, build } from 'esbuild';
|
||||
import { copyFile, mkdir, rm } from 'fs/promises';
|
||||
import { build } from 'esbuild';
|
||||
import { copyFile, mkdirSync, rmSync } from 'fs';
|
||||
import { argv } from 'process';
|
||||
|
||||
const isProd = !argv.includes('--dev');
|
||||
@@ -10,25 +10,26 @@ 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 });
|
||||
rmSync('dist', { recursive: true, force: true });
|
||||
console.log('Dist removed');
|
||||
|
||||
console.log('Creating dist...');
|
||||
await mkdir('dist');
|
||||
mkdirSync('dist');
|
||||
console.log('Dist created');
|
||||
|
||||
console.log('Copying package.json...');
|
||||
copyFile('package.dist.json', 'dist/package.json').then(() =>
|
||||
copyFile('package.dist.json', 'dist/package.json', () =>
|
||||
console.log('package.json copied'),
|
||||
);
|
||||
}
|
||||
|
||||
const commonOptions: BuildOptions = {
|
||||
const commonOptions = {
|
||||
platform: 'node',
|
||||
loader: {
|
||||
'.node': 'copy',
|
||||
'.ttf': 'file',
|
||||
},
|
||||
format: 'cjs',
|
||||
|
||||
bundle: true,
|
||||
sourcemap: true,
|
||||
+1
-14
@@ -1,19 +1,6 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { client } from './core/discord/client';
|
||||
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);
|
||||
@@ -1,8 +1,8 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import packageJSON from '../../package.json' assert { type: 'json' };
|
||||
import { client } from '../bot';
|
||||
import { tankopedia } from '../core/blitz/tankopedia';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||
import { client } from '../core/discord/client';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import markdownTable from '../core/discord/markdownTable';
|
||||
import getClientId from '../core/node/getClientId';
|
||||
@@ -12,7 +12,7 @@ const executionStart = new Date().getTime();
|
||||
|
||||
export const debugCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
@@ -26,7 +26,7 @@ export const SKILLED_CLANS: Record<SkilledClan, string> = {
|
||||
|
||||
export const eligibleCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: false,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
+74
-67
@@ -13,75 +13,82 @@ 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 { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import evolution from '../renderers/evolution';
|
||||
import { StatType } from '../renderers/fullStats';
|
||||
import { StatType } from '../renderers/stats';
|
||||
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')!),
|
||||
export const evolutionCommand = new Promise<CommandRegistryRaw>(
|
||||
async (resolve) => {
|
||||
const command = await addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('evolution')
|
||||
.setDescription('Evolution of statistics'),
|
||||
false,
|
||||
);
|
||||
|
||||
resolve({
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command,
|
||||
|
||||
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')!),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
);
|
||||
+96
-65
@@ -1,4 +1,5 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { TreeTypeString } from '../components/Tanks';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
@@ -13,72 +14,102 @@ 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 { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import fullStats from '../renderers/fullStats';
|
||||
import { MultiTankFilters, StatType } from '../renderers/stats';
|
||||
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')!),
|
||||
export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
||||
async (resolve) => {
|
||||
const command = await addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('full-stats')
|
||||
.setDescription('Full in-game statistics'),
|
||||
);
|
||||
|
||||
resolve({
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command,
|
||||
|
||||
async handler(interaction) {
|
||||
const commandGroup = interaction.options.getSubcommandGroup(
|
||||
true,
|
||||
) as StatType;
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const resolvedPeriod = resolvePeriodFromCommand(
|
||||
player.region,
|
||||
interaction,
|
||||
);
|
||||
const period = interaction.options.getString('period');
|
||||
const tankIdRaw = interaction.options.getString('tank')!;
|
||||
const tankId =
|
||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
||||
const start = interaction.options.getInteger('start');
|
||||
const end = interaction.options.getInteger('end');
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
tankId,
|
||||
start,
|
||||
end,
|
||||
period,
|
||||
});
|
||||
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 tierOption = interaction.options.getString('tier');
|
||||
|
||||
return [
|
||||
await fullStats(
|
||||
commandGroup,
|
||||
resolvedPeriod,
|
||||
player,
|
||||
commandGroup === 'tank'
|
||||
? tankId
|
||||
: commandGroup === 'multi-tank'
|
||||
? ({
|
||||
'tank-type':
|
||||
interaction.options.getString('tank-type') ?? undefined,
|
||||
nation: interaction.options.getString('nation') ?? undefined,
|
||||
tier: tierOption ? parseInt(tierOption) : undefined,
|
||||
'tree-type': (interaction.options.getString('tree-type') ??
|
||||
undefined) as TreeTypeString | undefined,
|
||||
} satisfies Partial<MultiTankFilters>)
|
||||
: null,
|
||||
),
|
||||
primaryButton(path, 'Refresh'),
|
||||
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
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')!),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
);
|
||||
@@ -30,7 +30,7 @@ function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) {
|
||||
|
||||
export const helpCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: addDocsSubcommands(
|
||||
@@ -44,13 +44,14 @@ export const helpCommand: CommandRegistry = {
|
||||
),
|
||||
),
|
||||
|
||||
handler(interaction) {
|
||||
async 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,
|
||||
return `# Commands\n\nBlitzkrieg offers the following commands:\n\n${(
|
||||
await Promise.all(COMMANDS_RAW)
|
||||
)
|
||||
.filter((registry) => registry.inPublic && registry.inProduction)
|
||||
.map(
|
||||
(registry) =>
|
||||
`- \`/${registry.command.name}\`: ${registry.command.description}`,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { SlashCommandBuilder } from 'discord.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';
|
||||
@@ -18,7 +16,7 @@ const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
export const inactiveCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -69,17 +67,12 @@ export const inactiveCommand: CommandRegistry = {
|
||||
<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()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{!hasInactiveMembers && <NoData type={NoDataType.PlayersInPeriod} />}
|
||||
{hasInactiveMembers && <GenericStats stats={inactive} />}
|
||||
|
||||
<PoweredBy type={PoweredByType.Wargaming} />
|
||||
</Wrapper>
|
||||
);
|
||||
},
|
||||
|
||||
+88
-64
@@ -1,19 +1,20 @@
|
||||
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,
|
||||
TankopediaEntry,
|
||||
Tier,
|
||||
tankopedia,
|
||||
tankopediaInfo,
|
||||
} from '../core/blitz/tankopedia';
|
||||
import addTierChoices from '../core/discord/addTierChoices';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
@@ -45,30 +46,13 @@ const COMP_TANKS = [
|
||||
|
||||
export const ownedTanksCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('ownedtanks')
|
||||
.setName('owned-tanks')
|
||||
.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(addTierChoices)
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
async handler(interaction) {
|
||||
@@ -79,73 +63,113 @@ export const ownedTanksCommand: CommandRegistry = {
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getTankStats(server, id);
|
||||
const tanks = (
|
||||
const filteredTanks = (
|
||||
await Promise.all(
|
||||
tankStats.map(async (tankData) => ({
|
||||
...(await tankopedia)[tankData.tank_id],
|
||||
tankopedia: (await tankopedia)[tankData.tank_id]!,
|
||||
tank_id: tankData.tank_id,
|
||||
})),
|
||||
)
|
||||
).filter((tank) => tank?.tier === tier);
|
||||
).filter((tank) => tank.tankopedia?.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);
|
||||
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
||||
const nations: string[] = [];
|
||||
|
||||
filteredTanks.forEach((tank) => {
|
||||
if (groupedTanks[tank.tankopedia.nation] === undefined) {
|
||||
groupedTanks[tank.tankopedia.nation] = [tank.tankopedia];
|
||||
nations.push(tank.tankopedia.nation);
|
||||
} else {
|
||||
groupedTanks[tank.tankopedia.nation].push(tank.tankopedia);
|
||||
}
|
||||
});
|
||||
|
||||
nations.sort();
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier as Tier]})`}
|
||||
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={`Owned tanks • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
description={`Tier ${
|
||||
TIER_ROMAN_NUMERALS[tier as Tier]
|
||||
} tanks • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{tanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
||||
{filteredTanks.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>
|
||||
)}
|
||||
{filteredTanks.length > 0 &&
|
||||
(await Promise.all(
|
||||
nations.map(async (nation) => {
|
||||
const tanks = groupedTanks[nation];
|
||||
const leftColumnSize = Math.ceil(tanks.length / 2);
|
||||
const leftColumn = tanks.slice(0, leftColumnSize);
|
||||
const rightColumn = tanks.slice(leftColumnSize);
|
||||
|
||||
<PoweredBy type={PoweredByType.Wargaming} />
|
||||
return (
|
||||
<Tanks.Root>
|
||||
<Tanks.Title>
|
||||
{(await tankopediaInfo).vehicle_nations[nation]}
|
||||
</Tanks.Title>
|
||||
|
||||
<Tanks.Row>
|
||||
<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.Row>
|
||||
</Tanks.Root>
|
||||
);
|
||||
}),
|
||||
))}
|
||||
</Wrapper>
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: autocompleteUsername,
|
||||
};
|
||||
|
||||
// TODO: make this work in the future
|
||||
// console.log('Caching tank images...');
|
||||
// TANKS.then((tanks) =>
|
||||
// jsxToSvg(
|
||||
// <div style={{ display: 'flex' }}>
|
||||
// {tanks.map(({ images, tank_id }) => {
|
||||
// return (
|
||||
// images.normal && <img key={tank_id} src={images.normal} width={0} />
|
||||
// );
|
||||
// })}
|
||||
// </div>,
|
||||
// ),
|
||||
// ).then(() => console.log('Cached tank images'));
|
||||
@@ -1,9 +1,9 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export const pingCommand: CommandRegistry<true> = {
|
||||
export const pingCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
handlesInteraction: true,
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ type SortBy = 'name' | 'count';
|
||||
|
||||
export const playerAchievementsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerachievements')
|
||||
.setName('player-achievements')
|
||||
.setDescription("All the player's achievements")
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addStringOption((option) =>
|
||||
|
||||
@@ -12,11 +12,11 @@ import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const playerInfoCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerinfo')
|
||||
.setName('player-info')
|
||||
.setDescription('Basic information about a player')
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
|
||||
+436
-153
@@ -1,13 +1,31 @@
|
||||
import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from 'discord.js';
|
||||
import {
|
||||
APIApplicationCommandOptionChoice,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} 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 { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
||||
import getArchivedRatingsInfo from '../core/blitz/getArchivedRatingsInfo';
|
||||
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
||||
import getMidnightLeaderboard, {
|
||||
DATABASE_REPO,
|
||||
} from '../core/database/getMidnightLeaderboard';
|
||||
import addRegionChoices from '../core/discord/addRegionChoices';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { octokit } from '../core/express/octokit';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import throwError from '../core/node/throwError';
|
||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
|
||||
export interface RatingsPlayer {
|
||||
spa_id: number;
|
||||
@@ -75,188 +93,453 @@ export interface RatingsLeague {
|
||||
percentile: number;
|
||||
}
|
||||
|
||||
export interface RatingsInfo {
|
||||
title: string;
|
||||
icon: string | null;
|
||||
start_at: string;
|
||||
finish_at: string;
|
||||
current_season: number;
|
||||
updated_at: string;
|
||||
count: number;
|
||||
export type RatingsInfo =
|
||||
| {
|
||||
detail: undefined;
|
||||
|
||||
rewards: RatingsReward[];
|
||||
leagues: RatingsLeague[];
|
||||
}
|
||||
title: string;
|
||||
icon: string | null;
|
||||
start_at: string;
|
||||
finish_at: string;
|
||||
current_season: number;
|
||||
updated_at: string;
|
||||
count: number;
|
||||
|
||||
rewards: RatingsReward[];
|
||||
leagues: RatingsLeague[];
|
||||
}
|
||||
| { detail: { error: string } };
|
||||
|
||||
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;
|
||||
});
|
||||
const LEAGUES = [
|
||||
{ name: 'Diamond', minScore: 5000 },
|
||||
{ name: 'Platinum', minScore: 4000 },
|
||||
{ name: 'Gold', minScore: 3000 },
|
||||
{ name: 'Silver', minScore: 2000 },
|
||||
{ name: 'Bronze', minScore: 0 },
|
||||
];
|
||||
|
||||
function optionalParameters(option: SlashCommandSubcommandBuilder) {
|
||||
function addSubcommands(
|
||||
option: SlashCommandSubcommandGroupBuilder,
|
||||
addOptions = (option: SlashCommandSubcommandBuilder) => option,
|
||||
) {
|
||||
return option
|
||||
.addStringOption(addRegionChoices)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('How many rows to display (default: 10)')
|
||||
.setRequired(false)
|
||||
.setMinValue(5)
|
||||
.setMaxValue(30),
|
||||
.addSubcommand((option) =>
|
||||
addOptions(
|
||||
option
|
||||
.setName('neighbours')
|
||||
.setDescription('Your position and neighbours'),
|
||||
)
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('How many neighbours to display (default: 10)')
|
||||
.setRequired(false)
|
||||
.setMinValue(5)
|
||||
.setMaxValue(30),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
addOptions(option.setName('league').setDescription('Top league players'))
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('league')
|
||||
.setDescription('The league to display')
|
||||
.addChoices(
|
||||
...LEAGUES.map(
|
||||
({ name }, value) =>
|
||||
({
|
||||
name,
|
||||
value: `${value}`,
|
||||
}) satisfies APIApplicationCommandOptionChoice<string>,
|
||||
),
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.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 ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||
async (resolve) => {
|
||||
const seasonChoices = await octokit.repos
|
||||
.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: 'com/ratings',
|
||||
})
|
||||
.then(({ data }) => {
|
||||
if (!Array.isArray(data)) {
|
||||
throw throwError('Archived ratings data is malformed');
|
||||
}
|
||||
return data.map(
|
||||
(folder) =>
|
||||
({
|
||||
name: `Season ${folder.name}`,
|
||||
value: folder.name,
|
||||
}) satisfies APIApplicationCommandOptionChoice<string>,
|
||||
);
|
||||
});
|
||||
|
||||
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'),
|
||||
),
|
||||
const command = new SlashCommandBuilder()
|
||||
.setName('ratings')
|
||||
.setDescription('Ratings battles statistics')
|
||||
.addSubcommandGroup((option) =>
|
||||
addSubcommands(
|
||||
option.setName('archive').setDescription('Any previous season'),
|
||||
(option) =>
|
||||
option.addStringOption((option) =>
|
||||
option
|
||||
.setName('season')
|
||||
.setDescription('The season number')
|
||||
.setChoices(...seasonChoices)
|
||||
.setRequired(true),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
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;
|
||||
.addSubcommandGroup((option) =>
|
||||
addSubcommands(
|
||||
option
|
||||
.setName('current')
|
||||
.setDescription('The current running Ratings season'),
|
||||
),
|
||||
);
|
||||
|
||||
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,
|
||||
resolve({
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command,
|
||||
|
||||
async handler(interaction) {
|
||||
interface SimplifiedPlayer {
|
||||
id: number;
|
||||
score: number;
|
||||
position: number;
|
||||
clan: string | undefined;
|
||||
nickname: string;
|
||||
}
|
||||
|
||||
const subcommandGroup = interaction.options.getSubcommandGroup(true) as
|
||||
| 'archive'
|
||||
| 'current';
|
||||
const subcommand = interaction.options.getSubcommand(true) as
|
||||
| 'league'
|
||||
| 'neighbours';
|
||||
const limit = interaction.options.getInteger('limit') ?? 10;
|
||||
const seasonOption = interaction.options.getString('season');
|
||||
const season = seasonOption ? parseInt(seasonOption) : undefined;
|
||||
let titleName: string;
|
||||
let titleImage: string | undefined;
|
||||
let titleNameDiscriminator: string | undefined;
|
||||
let titleDescription: string;
|
||||
let playersBefore: number;
|
||||
let playersAfter: number;
|
||||
let players: SimplifiedPlayer[] | undefined;
|
||||
let midnightLeaderboard: BlitzkriegRatingsLeaderboard | undefined;
|
||||
let playerId: number | undefined;
|
||||
let regionRatingsInfo: RatingsInfo;
|
||||
|
||||
if (subcommand === 'league') {
|
||||
const leagueIndex = parseInt(
|
||||
interaction.options.getString('league')!,
|
||||
);
|
||||
const region = interaction.options.getString('region') as Region;
|
||||
regionRatingsInfo = await (subcommandGroup === 'current'
|
||||
? getRatingsInfo(region)
|
||||
: getArchivedRatingsInfo(season!, region));
|
||||
const regionSubdomain = regionToRegionSubdomain(region);
|
||||
const result =
|
||||
subcommandGroup === 'current'
|
||||
? regionRatingsInfo.detail === undefined
|
||||
? await fetch(
|
||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
||||
)
|
||||
.then((response) => response.json() as Promise<LeagueTop>)
|
||||
.then(async ({ result }) =>
|
||||
result.slice(0, limit).map(
|
||||
(player) =>
|
||||
({
|
||||
id: player.spa_id,
|
||||
score: player.score,
|
||||
position: player.number,
|
||||
clan: player.clan_tag,
|
||||
nickname: player.nickname,
|
||||
}) satisfies SimplifiedPlayer,
|
||||
),
|
||||
)
|
||||
: undefined
|
||||
: await octokit.repos
|
||||
.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${season}/latest.json`,
|
||||
})
|
||||
.then(async ({ data }) => {
|
||||
if (Array.isArray(data) || data.type !== 'file') {
|
||||
throw throwError('Archived ratings data is malformed');
|
||||
}
|
||||
|
||||
const players = (await fetch(data.download_url!).then(
|
||||
(response) => response.json(),
|
||||
)) as BlitzkriegRatingsLeaderboard;
|
||||
const firstPlayerIndex =
|
||||
leagueIndex === 0
|
||||
? 0
|
||||
: players.findIndex(
|
||||
(player) =>
|
||||
player.score < LEAGUES[leagueIndex - 1].minScore,
|
||||
);
|
||||
const lastPlayerIndex = firstPlayerIndex + limit - 1;
|
||||
const trimmed = players.slice(
|
||||
firstPlayerIndex,
|
||||
lastPlayerIndex + 1,
|
||||
);
|
||||
const ids = trimmed.map((player) => player.id).join(',');
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
||||
);
|
||||
|
||||
return trimmed.map(
|
||||
(player, index) =>
|
||||
({
|
||||
id: player.id,
|
||||
score: player.score,
|
||||
position: firstPlayerIndex + index + 1,
|
||||
clan: clanData[player.id]!.clan?.tag,
|
||||
nickname: clanData[player.id]!.account_name,
|
||||
}) satisfies SimplifiedPlayer,
|
||||
);
|
||||
});
|
||||
const leagueInfo =
|
||||
regionRatingsInfo.detail === undefined
|
||||
? regionRatingsInfo.leagues[leagueIndex]
|
||||
: undefined;
|
||||
midnightLeaderboard =
|
||||
subcommandGroup === 'current'
|
||||
? regionRatingsInfo.detail === undefined
|
||||
? await getMidnightLeaderboard(
|
||||
region,
|
||||
regionRatingsInfo.current_season,
|
||||
)
|
||||
: undefined
|
||||
: await getMidnightLeaderboard(region, season!);
|
||||
|
||||
players = result;
|
||||
playersBefore = result ? result[0].position - 1 : 0;
|
||||
playersAfter =
|
||||
regionRatingsInfo.detail === undefined && result !== undefined
|
||||
? regionRatingsInfo.count - result[result.length - 1].position
|
||||
: 0;
|
||||
titleName = `${
|
||||
leagueInfo ? leagueInfo.title : 'No Ongoing Season'
|
||||
} - ${REGION_NAMES_SHORT[region]}`;
|
||||
titleImage = leagueInfo
|
||||
? leagueInfo.big_icon.startsWith('http')
|
||||
? leagueInfo.big_icon
|
||||
: `https:${leagueInfo.big_icon}`
|
||||
: undefined;
|
||||
titleDescription = `Top ${limit} players`;
|
||||
} else {
|
||||
const { region, id } = await resolvePlayerFromCommand(interaction);
|
||||
regionRatingsInfo =
|
||||
subcommandGroup === 'current'
|
||||
? await getRatingsInfo(region)
|
||||
: await octokit.repos
|
||||
.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${season}/info.json`,
|
||||
})
|
||||
.then(async ({ data }) => {
|
||||
if (Array.isArray(data) || data.type !== 'file') {
|
||||
throw throwError('Archived ratings info is malformed');
|
||||
}
|
||||
|
||||
const response = fetch(data.download_url!);
|
||||
return (await response.then((response) =>
|
||||
response.json(),
|
||||
)) as RatingsInfo;
|
||||
});
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const clan = (
|
||||
await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
)
|
||||
)[id]?.clan;
|
||||
const regionSubdomain = regionToRegionSubdomain(region);
|
||||
const neighbors =
|
||||
subcommandGroup === 'current'
|
||||
? regionRatingsInfo.detail === undefined
|
||||
? await fetch(
|
||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${Math.round(
|
||||
limit / 2,
|
||||
)}`,
|
||||
)
|
||||
.then(
|
||||
(response) =>
|
||||
response.json() as Promise<RatingsNeighbors>,
|
||||
)
|
||||
.then((players) =>
|
||||
players.neighbors.map(
|
||||
(player) =>
|
||||
({
|
||||
id: player.spa_id,
|
||||
position: player.number,
|
||||
score: player.score,
|
||||
clan: player.clan_tag,
|
||||
nickname: player.nickname,
|
||||
}) satisfies SimplifiedPlayer,
|
||||
),
|
||||
)
|
||||
: undefined
|
||||
: await octokit.repos
|
||||
.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${season}/latest.json`,
|
||||
})
|
||||
.then(async ({ data }) => {
|
||||
if (Array.isArray(data) || data.type !== 'file') {
|
||||
throw throwError(
|
||||
'Archived ratings latest data is malformed',
|
||||
);
|
||||
}
|
||||
|
||||
const response = fetch(data.download_url!);
|
||||
const players = (await response.then((response) =>
|
||||
response.json(),
|
||||
)) as BlitzkriegRatingsLeaderboard;
|
||||
const playerIndex = players.findIndex(
|
||||
(player) => player.id === id,
|
||||
);
|
||||
|
||||
if (playerIndex === -1) {
|
||||
throw throwError(
|
||||
`${accountInfo[id].nickname} didn't player ratings in season ${season}`,
|
||||
'This player did not participate in this season or did not get past calibration.',
|
||||
);
|
||||
}
|
||||
|
||||
const halfRange = Math.round(limit / 2);
|
||||
const trimmed = players.slice(
|
||||
playerIndex - halfRange,
|
||||
playerIndex + halfRange + 1,
|
||||
);
|
||||
const ids = trimmed.map((player) => player.id).join(',');
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
||||
);
|
||||
|
||||
return trimmed.map((player, index) => ({
|
||||
id: player.id,
|
||||
score: player.score,
|
||||
position: playerIndex + index + 1,
|
||||
clan: clanData[player.id]!.clan?.tag,
|
||||
nickname: clanData[player.id]!.account_name,
|
||||
}));
|
||||
});
|
||||
midnightLeaderboard =
|
||||
subcommandGroup === 'current'
|
||||
? regionRatingsInfo.detail === undefined
|
||||
? await getMidnightLeaderboard(
|
||||
region,
|
||||
regionRatingsInfo.current_season,
|
||||
)
|
||||
: undefined
|
||||
: await getMidnightLeaderboard(region, season!);
|
||||
|
||||
if (clan && neighbors) titleNameDiscriminator = `[${clan.tag}]`;
|
||||
|
||||
players = neighbors;
|
||||
titleImage = neighbors
|
||||
? clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined
|
||||
: undefined;
|
||||
titleName = neighbors
|
||||
? accountInfo[id].nickname
|
||||
: `No Ongoing Season - ${REGION_NAMES_SHORT[region]}`;
|
||||
titleDescription = 'Ratings neighbours';
|
||||
playersBefore = neighbors ? neighbors[0].position - 1 : 0;
|
||||
playersAfter =
|
||||
regionRatingsInfo.detail === undefined
|
||||
? neighbors
|
||||
? regionRatingsInfo.count -
|
||||
neighbors[neighbors.length - 1].position
|
||||
: 0
|
||||
: 0;
|
||||
playerId = id;
|
||||
}
|
||||
|
||||
const items = players?.map((player) => {
|
||||
const reward =
|
||||
regionRatingsInfo.detail === undefined
|
||||
? regionRatingsInfo.rewards.find(
|
||||
(reward) =>
|
||||
player.position >= reward.from_position &&
|
||||
player.position <= reward.to_position,
|
||||
)
|
||||
: undefined;
|
||||
const midnightIndex = midnightLeaderboard?.findIndex(
|
||||
(item) => item.id === player.spa_id,
|
||||
(item) => item.id === player.id,
|
||||
);
|
||||
const midnightScore =
|
||||
midnightIndex === undefined
|
||||
? player.score
|
||||
: midnightLeaderboard![midnightIndex].score;
|
||||
const midnightPosition =
|
||||
midnightIndex === undefined ? player.number : midnightIndex + 1;
|
||||
midnightIndex === undefined ? player.position : midnightIndex + 1;
|
||||
|
||||
return (
|
||||
<Leaderboard.Item
|
||||
nickname={player.nickname}
|
||||
score={player.score}
|
||||
position={player.number}
|
||||
clan={player.clan_tag}
|
||||
position={player.position}
|
||||
clan={player.clan}
|
||||
reward={reward}
|
||||
deltaScore={player.score - midnightScore}
|
||||
deltaPosition={midnightPosition - player.number}
|
||||
key={player.spa_id}
|
||||
deltaPosition={midnightPosition - player.position}
|
||||
key={player.id}
|
||||
highlight={player.id === playerId}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const playersBefore = result[0].number - 1;
|
||||
const playersAfter = awaitedInfo.count - result[result.length - 1].number;
|
||||
return (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={titleName}
|
||||
image={titleImage}
|
||||
nameDiscriminator={titleNameDiscriminator}
|
||||
description={`${titleDescription} • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
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]
|
||||
}`}
|
||||
/>
|
||||
{items && (
|
||||
<Leaderboard.Root>
|
||||
{playersBefore > 0 && (
|
||||
<Leaderboard.Gap number={playersBefore} />
|
||||
)}
|
||||
{items}
|
||||
{playersAfter > 0 && <Leaderboard.Gap number={playersAfter} />}
|
||||
</Leaderboard.Root>
|
||||
)}
|
||||
</Wrapper>
|
||||
);
|
||||
},
|
||||
|
||||
<Leaderboard.Root>
|
||||
{playersBefore > 0 && <Leaderboard.Gap number={playersBefore} />}
|
||||
{items}
|
||||
{playersAfter > 0 && <Leaderboard.Gap number={playersAfter} />}
|
||||
</Leaderboard.Root>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
autocomplete: autocompleteUsername,
|
||||
});
|
||||
},
|
||||
};
|
||||
);
|
||||
@@ -11,11 +11,11 @@ import { ClanList } from '../types/clanList';
|
||||
|
||||
export const searchClansCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchclans')
|
||||
.setName('search-clans')
|
||||
.setDescription('Search clans')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) => addClanChoices(option).setAutocomplete(false))
|
||||
|
||||
@@ -12,11 +12,11 @@ import { AccountList } from '../types/accountList';
|
||||
|
||||
export const searchPlayersCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchplayers')
|
||||
.setName('search-players')
|
||||
.setDescription('Search players in a Blitz server')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) =>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { TANK_NAMES } from '../core/blitz/tankopedia';
|
||||
import { TANK_NAMES_DIACRITICS } 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,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchtanks')
|
||||
.setName('search-tanks')
|
||||
.setDescription('Search tanks')
|
||||
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
@@ -26,9 +26,10 @@ export const searchTanksCommand: CommandRegistry = {
|
||||
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,
|
||||
);
|
||||
const results = go(tank, await TANK_NAMES_DIACRITICS, {
|
||||
limit,
|
||||
keys: ['combined'],
|
||||
}).map((result) => result.obj.original);
|
||||
|
||||
return embedInfo(
|
||||
`Tank search for "${markdownEscape(tank)}"`,
|
||||
|
||||
+96
-60
@@ -1,4 +1,5 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { TreeTypeString } from '../components/Tanks';
|
||||
import { CYCLIC_API } from '../constants/cyclic';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
@@ -13,73 +14,108 @@ 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 { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import stats, { MultiTankFilters, StatType } from '../renderers/stats';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const statsCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: addStatTypeSubCommandGroups(
|
||||
export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
||||
const command = await addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('stats')
|
||||
.setDescription('Regular battles 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];
|
||||
resolve({
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
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',
|
||||
),
|
||||
];
|
||||
},
|
||||
command,
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
autocompleteUsername(interaction);
|
||||
autocompleteTanks(interaction);
|
||||
},
|
||||
async handler(interaction) {
|
||||
const commandGroup = interaction.options.getSubcommandGroup(
|
||||
true,
|
||||
) as StatType;
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const resolvedPeriod = resolvePeriodFromCommand(
|
||||
player.region,
|
||||
interaction,
|
||||
);
|
||||
const period = interaction.options.getString('period');
|
||||
const tankIdRaw = interaction.options.getString('tank')!;
|
||||
const tankId =
|
||||
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
||||
const start = interaction.options.getInteger('start');
|
||||
const end = interaction.options.getInteger('end');
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
tankId,
|
||||
start,
|
||||
end,
|
||||
period,
|
||||
});
|
||||
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];
|
||||
|
||||
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);
|
||||
const tierOption = interaction.options.getString('tier');
|
||||
|
||||
return await stats(
|
||||
commandGroup,
|
||||
period,
|
||||
player,
|
||||
parseInt(url.searchParams.get('tankId')!),
|
||||
);
|
||||
},
|
||||
};
|
||||
return [
|
||||
await stats(
|
||||
commandGroup,
|
||||
resolvedPeriod,
|
||||
player,
|
||||
commandGroup === 'tank'
|
||||
? tankId
|
||||
: commandGroup === 'multi-tank'
|
||||
? ({
|
||||
'tank-type':
|
||||
interaction.options.getString('tank-type') ?? undefined,
|
||||
nation: interaction.options.getString('nation') ?? undefined,
|
||||
tier: tierOption ? parseInt(tierOption) : undefined,
|
||||
'tree-type': (interaction.options.getString('tree-type') ??
|
||||
undefined) as TreeTypeString | undefined,
|
||||
} satisfies Partial<MultiTankFilters>)
|
||||
: null,
|
||||
),
|
||||
primaryButton(path, 'Refresh'),
|
||||
linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
`https://www.blitzstars.com/player/${player.region}/${nickname}`,
|
||||
'BlitzStars',
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
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,
|
||||
commandGroup === 'tank'
|
||||
? parseInt(url.searchParams.get('tankId')!)
|
||||
: commandGroup === 'multi-tank'
|
||||
? ({
|
||||
'tank-type': url.searchParams.get('tank-type')!,
|
||||
nation: url.searchParams.get('nation')!,
|
||||
tier: parseInt(url.searchParams.get('tier')!),
|
||||
'tree-type': url.searchParams.get('tree-type') as TreeTypeString,
|
||||
} satisfies MultiTankFilters)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
+27
-5
@@ -15,7 +15,7 @@ import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const todayCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -24,26 +24,48 @@ export const todayCommand: CommandRegistry = {
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setName('cutoff')
|
||||
.setDescription(
|
||||
'The maximum number of tanks to display (default: Infinity)',
|
||||
)
|
||||
.setRequired(false)
|
||||
.setMinValue(1),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('maximized')
|
||||
.setDescription(
|
||||
'The number of rows with full stats after which all are collapsed (default: 4)',
|
||||
)
|
||||
.setMinValue(0)
|
||||
.setRequired(false),
|
||||
)
|
||||
.addBooleanOption((option) =>
|
||||
option
|
||||
.setName('show-total')
|
||||
.setDescription('Show the total stats at the top (default: true)')
|
||||
.setRequired(false),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const limit = interaction.options.getInteger('limit') ?? Infinity;
|
||||
const cutoff = interaction.options.getInteger('cutoff') ?? undefined;
|
||||
const maximized = interaction.options.getInteger('maximized') ?? undefined;
|
||||
const showTotal = interaction.options.getBoolean('show-total') ?? undefined;
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
const path = interactionToURL(interaction, player);
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
cutoff,
|
||||
maximized,
|
||||
'show-total': showTotal,
|
||||
});
|
||||
|
||||
return [
|
||||
await today(player, limit, false),
|
||||
await today(player, cutoff, maximized, showTotal, false),
|
||||
primaryButton(path, 'Refresh'),
|
||||
linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
||||
linkButton(
|
||||
|
||||
@@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData';
|
||||
|
||||
export const verifyCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import getWN8Percentile from '../../../core/blitz/getWN8Percentile';
|
||||
import { TankType } from '../../../core/blitz/tankopedia';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import { RowDiscriminator } from './RowDiscriminator';
|
||||
import { TREE_TYPE_ICONS, TreeTypeEnum } from '../../Tanks';
|
||||
import { RowStat } from './RowStat';
|
||||
|
||||
export interface RowProps {
|
||||
@@ -13,14 +14,14 @@ export interface RowProps {
|
||||
careerDamage: number;
|
||||
battles: number;
|
||||
careerBattles: number;
|
||||
icon?: string;
|
||||
minimized: boolean;
|
||||
isListing: boolean;
|
||||
naked?: boolean;
|
||||
isTank: boolean;
|
||||
treeType?: TreeTypeEnum;
|
||||
tankType?: TankType;
|
||||
}
|
||||
|
||||
export function Row({
|
||||
isListing,
|
||||
isTank,
|
||||
minimized,
|
||||
name,
|
||||
winrate,
|
||||
@@ -31,45 +32,85 @@ export function Row({
|
||||
careerDamage,
|
||||
battles,
|
||||
careerBattles,
|
||||
icon,
|
||||
naked,
|
||||
treeType,
|
||||
tankType,
|
||||
}: RowProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
borderRadius: 4,
|
||||
backgroundColor: isListing
|
||||
? theme.colors.componentInteractive
|
||||
: theme.colors.appBackground2,
|
||||
padding: 8,
|
||||
backgroundColor: theme.colors.appBackground2,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<RowDiscriminator minimized={minimized} name={name} icon={icon} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 8,
|
||||
gap: 4,
|
||||
backgroundColor: theme.colors.componentInteractive,
|
||||
}}
|
||||
>
|
||||
{isTank && treeType !== undefined && tankType !== undefined && (
|
||||
<img
|
||||
src={TREE_TYPE_ICONS[treeType][tankType]}
|
||||
style={{ width: 16, height: 16 }}
|
||||
/>
|
||||
)}
|
||||
<span
|
||||
style={{
|
||||
color: isTank
|
||||
? treeType === TreeTypeEnum.Collector
|
||||
? theme.colors.textLowContrast_blue
|
||||
: treeType === TreeTypeEnum.Premium
|
||||
? theme.colors.textLowContrast_amber
|
||||
: theme.colors.textHighContrast
|
||||
: theme.colors.textLowContrast,
|
||||
fontWeight: 900,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Winrate • ${(careerWinrate * 100).toFixed(2)}%`}
|
||||
value={`${(winrate * 100).toFixed(2)}%`}
|
||||
delta={winrate - careerWinrate}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`WN8 • ${careerWN8 === undefined ? '--' : careerWN8.toFixed(0)}`}
|
||||
value={WN8 === undefined ? '--' : WN8.toFixed(0)}
|
||||
percentile={WN8 === undefined ? undefined : getWN8Percentile(WN8)}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Damage • ${careerDamage.toFixed(0)}`}
|
||||
value={damage.toFixed(0)}
|
||||
delta={damage - careerDamage}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Battles • ${careerBattles.toFixed(0)}`}
|
||||
value={battles.toFixed(0)}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
paddingTop: 8,
|
||||
paddingBottom: 8,
|
||||
}}
|
||||
>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Battles • ${careerBattles.toFixed(0)}`}
|
||||
value={battles.toFixed(0)}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Winrate • ${(careerWinrate * 100).toFixed(2)}%`}
|
||||
value={`${(winrate * 100).toFixed(2)}%`}
|
||||
delta={winrate - careerWinrate}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`WN8 • ${
|
||||
careerWN8 === undefined ? '--' : careerWN8.toFixed(0)
|
||||
}`}
|
||||
value={WN8 === undefined ? '--' : WN8.toFixed(0)}
|
||||
percentile={WN8 === undefined ? undefined : getWN8Percentile(WN8)}
|
||||
/>
|
||||
<RowStat
|
||||
minimized={minimized}
|
||||
name={`Damage • ${careerDamage.toFixed(0)}`}
|
||||
value={damage.toFixed(0)}
|
||||
delta={damage - careerDamage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import { theme } from '../../../stitches.config';
|
||||
|
||||
export interface RowDiscriminatorProps {
|
||||
name: string;
|
||||
icon?: string;
|
||||
minimized: boolean;
|
||||
}
|
||||
|
||||
export function RowDiscriminator({
|
||||
name,
|
||||
icon,
|
||||
minimized,
|
||||
}: RowDiscriminatorProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
boxSizing: 'border-box',
|
||||
width: 0,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
{!minimized && icon && (
|
||||
<img
|
||||
src={icon}
|
||||
height={0}
|
||||
style={{ flex: 1, width: '100%', objectFit: 'contain' }}
|
||||
/>
|
||||
)}
|
||||
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
textAlign: 'center',
|
||||
display: 'block',
|
||||
whiteSpace: 'nowrap',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'clip',
|
||||
maxWidth: '100%',
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -53,6 +53,7 @@ export function RowStat({
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textHighContrast,
|
||||
fontWeight: 'bold',
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './components/Root';
|
||||
export * from './components/Row';
|
||||
export * from './components/RowDiscriminator';
|
||||
export * from './components/RowStat';
|
||||
|
||||
@@ -96,7 +96,7 @@ export default function GenericAllStats({
|
||||
]}
|
||||
/>
|
||||
<Card
|
||||
title="Efficiency"
|
||||
title="Miscellaneous"
|
||||
items={[
|
||||
{
|
||||
label: 'Average tier',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import { Margin, MarginOrientation } from './Margin';
|
||||
|
||||
export const GRAPH_WIDTH = 544;
|
||||
export const GRAPH_WIDTH = 384;
|
||||
export const GRAPH_HEIGHT = 320;
|
||||
|
||||
export interface MarginInputProps {
|
||||
@@ -20,7 +20,7 @@ export interface RootProps {
|
||||
separations?: number;
|
||||
xMinLabel: string;
|
||||
xMaxLabel: string;
|
||||
xTitle: string;
|
||||
xTitle?: string;
|
||||
}
|
||||
|
||||
export function Root({
|
||||
@@ -91,18 +91,20 @@ export function Root({
|
||||
/>
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{
|
||||
paddingLeft: 64,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 16, color: theme.colors.textLowContrast }}>
|
||||
{xTitle}
|
||||
</span>
|
||||
</div>
|
||||
{xTitle !== undefined && (
|
||||
<div
|
||||
style={{
|
||||
paddingLeft: 64,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 16, color: theme.colors.textLowContrast }}>
|
||||
{xTitle}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export interface ItemProps {
|
||||
reward?: RatingsReward;
|
||||
nickname: string;
|
||||
clan?: string;
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
||||
function normalizeImage(url: string) {
|
||||
@@ -23,13 +24,16 @@ export function Item({
|
||||
reward,
|
||||
nickname,
|
||||
clan,
|
||||
highlight,
|
||||
}: ItemProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
padding: 8,
|
||||
backgroundColor: theme.colors.componentInteractive,
|
||||
backgroundColor: highlight
|
||||
? theme.colors.componentInteractive_blue
|
||||
: theme.colors.componentInteractive,
|
||||
borderRadius: 4,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
@@ -38,7 +42,9 @@ export function Item({
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textLowContrast,
|
||||
color: highlight
|
||||
? theme.colors.textLowContrast_blue
|
||||
: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
@@ -55,7 +61,9 @@ export function Item({
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textHighContrast,
|
||||
color: highlight
|
||||
? theme.colors.textHighContrast_blue
|
||||
: theme.colors.textHighContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
@@ -64,7 +72,9 @@ export function Item({
|
||||
{clan && (
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textLowContrast,
|
||||
color: highlight
|
||||
? theme.colors.textLowContrast_blue
|
||||
: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
@@ -95,7 +105,9 @@ export function Item({
|
||||
/>
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textLowContrast,
|
||||
color: highlight
|
||||
? theme.colors.textLowContrast_blue
|
||||
: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
@@ -109,7 +121,7 @@ export function Item({
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
justifyContent: 'flex-end',
|
||||
gap: 4,
|
||||
}}
|
||||
>
|
||||
@@ -126,7 +138,9 @@ export function Item({
|
||||
{reward && reward.count > 1 && (
|
||||
<span
|
||||
style={{
|
||||
color: theme.colors.textLowContrast,
|
||||
color: highlight
|
||||
? theme.colors.textLowContrast_blue
|
||||
: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
@@ -140,11 +154,19 @@ export function Item({
|
||||
display: 'flex',
|
||||
gap: 4,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
width: 96,
|
||||
justifyContent: 'flex-end',
|
||||
}}
|
||||
>
|
||||
{deltaScore !== 0 && deltaScore !== undefined && (
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 16 }}>
|
||||
<span
|
||||
style={{
|
||||
color: highlight
|
||||
? theme.colors.textLowContrast_blue
|
||||
: theme.colors.textLowContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
{Math.abs(deltaScore).toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
@@ -161,7 +183,14 @@ export function Item({
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<span style={{ color: theme.colors.textHighContrast, fontSize: 16 }}>
|
||||
<span
|
||||
style={{
|
||||
color: highlight
|
||||
? theme.colors.textHighContrast_blue
|
||||
: theme.colors.textHighContrast,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
{score.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { theme } from '../stitches.config';
|
||||
|
||||
export enum PoweredByType {
|
||||
BlitzStars,
|
||||
Wargaming,
|
||||
}
|
||||
|
||||
export interface PoweredByProps {
|
||||
type: PoweredByType;
|
||||
footer?: ReactNode;
|
||||
}
|
||||
|
||||
const POWERED_BY_IMAGES: Record<PoweredByType, string> = {
|
||||
[PoweredByType.BlitzStars]:
|
||||
'https://www.blitzstars.com/assets/images/4b4cb591.TankyMcPewpew.png',
|
||||
[PoweredByType.Wargaming]: 'https://i.imgur.com/jADGWm0.png',
|
||||
};
|
||||
|
||||
const POWERED_BY_NAMES: Record<PoweredByType, string> = {
|
||||
[PoweredByType.BlitzStars]: 'BlitzStars',
|
||||
[PoweredByType.Wargaming]: 'Wargaming',
|
||||
};
|
||||
|
||||
export default function PoweredBy({ type, footer }: PoweredByProps) {
|
||||
return (
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<div style={{ display: 'flex' }}>{footer}</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 4 }}>
|
||||
<img src={POWERED_BY_IMAGES[type]} style={{ height: 16, width: 16 }} />
|
||||
<span style={{ color: theme.colors.textLowContrast, fontSize: 16 }}>
|
||||
Powered by {POWERED_BY_NAMES[type]}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,32 +2,35 @@ import {
|
||||
TANK_ICONS,
|
||||
TANK_ICONS_COLLECTOR,
|
||||
TANK_ICONS_PREMIUM,
|
||||
TankType,
|
||||
} from '../../../core/blitz/tankopedia';
|
||||
import { theme } from '../../../stitches.config';
|
||||
|
||||
export enum TreeType {
|
||||
export enum TreeTypeEnum {
|
||||
TechTree,
|
||||
Premium,
|
||||
Collector,
|
||||
}
|
||||
|
||||
export type TreeTypeString = 'techtree' | 'premium' | 'collector';
|
||||
|
||||
export interface ItemProps {
|
||||
image?: string;
|
||||
tankType?: string;
|
||||
tankType?: TankType;
|
||||
name: string;
|
||||
treeType: TreeType;
|
||||
treeType: TreeTypeEnum;
|
||||
}
|
||||
|
||||
const TREE_TYPE_COLOR = {
|
||||
[TreeType.TechTree]: '',
|
||||
[TreeType.Premium]: '_amber',
|
||||
[TreeType.Collector]: '_blue',
|
||||
[TreeTypeEnum.TechTree]: '',
|
||||
[TreeTypeEnum.Premium]: '_amber',
|
||||
[TreeTypeEnum.Collector]: '_blue',
|
||||
} as const;
|
||||
|
||||
const TREE_TYPE_ICONS = {
|
||||
[TreeType.TechTree]: TANK_ICONS,
|
||||
[TreeType.Premium]: TANK_ICONS_PREMIUM,
|
||||
[TreeType.Collector]: TANK_ICONS_COLLECTOR,
|
||||
export const TREE_TYPE_ICONS = {
|
||||
[TreeTypeEnum.TechTree]: TANK_ICONS,
|
||||
[TreeTypeEnum.Premium]: TANK_ICONS_PREMIUM,
|
||||
[TreeTypeEnum.Collector]: TANK_ICONS_COLLECTOR,
|
||||
};
|
||||
|
||||
export function Item({ image, tankType, name, treeType }: ItemProps) {
|
||||
|
||||
@@ -9,7 +9,8 @@ export function Root({ children }: RootProps) {
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
flexDirection: 'column',
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
export interface RowProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function Row({ children }: RowProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { theme } from '../../../stitches.config';
|
||||
|
||||
export interface TitleProps {
|
||||
children: string;
|
||||
}
|
||||
|
||||
export function Title({ children }: TitleProps) {
|
||||
return (
|
||||
<span
|
||||
style={{
|
||||
fontWeight: 900,
|
||||
color: theme.colors.textHighContrast,
|
||||
fontSize: 24,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from './components/Column';
|
||||
export * from './components/Item';
|
||||
export * from './components/Root';
|
||||
export * from './components/Row';
|
||||
export * from './components/Title';
|
||||
+12
-15
@@ -1,4 +1,3 @@
|
||||
import isDev from '../core/node/isDev';
|
||||
import { theme } from '../stitches.config';
|
||||
|
||||
export interface TitleBarProps {
|
||||
@@ -19,10 +18,11 @@ export default function TitleBar({
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 16,
|
||||
justifyContent: 'center',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', gap: 8, flex: 1 }}>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
{image && (
|
||||
<img
|
||||
style={{ width: 64, height: 64, objectFit: 'contain' }}
|
||||
@@ -31,13 +31,18 @@ export default function TitleBar({
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{ display: 'flex', flexDirection: 'column', gap: 8, flex: 1 }}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
gap: 4,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 4,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<span
|
||||
@@ -46,6 +51,8 @@ export default function TitleBar({
|
||||
color: theme.colors.textHighContrast,
|
||||
fontWeight: 900,
|
||||
whiteSpace: 'nowrap',
|
||||
maxWidth: nameDiscriminator === undefined ? Infinity : 240,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
@@ -53,7 +60,6 @@ export default function TitleBar({
|
||||
{nameDiscriminator && (
|
||||
<span
|
||||
style={{
|
||||
flex: 1,
|
||||
fontSize: 32,
|
||||
color: theme.colors.textLowContrast,
|
||||
fontWeight: 900,
|
||||
@@ -70,15 +76,6 @@ export default function TitleBar({
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<img
|
||||
style={{ width: 64, height: 64 }}
|
||||
src={
|
||||
isDev()
|
||||
? 'https://i.imgur.com/j6TItdy.png'
|
||||
: 'https://i.imgur.com/pP6RN0x.png'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export default function Wrapper({ children, naked }: WrapperProps) {
|
||||
flexDirection: 'column',
|
||||
padding: 16,
|
||||
gap: 32,
|
||||
width: 640,
|
||||
width: 480,
|
||||
color: theme.colors.textHighContrast,
|
||||
|
||||
...(!naked && {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const CYCLIC_API = 'https://blitzkrieg.cyclic.app';
|
||||
export const CYCLIC_API = 'https://blitzkrieg-embeds.cyclic.app';
|
||||
@@ -7,6 +7,13 @@ export const REGION_NAMES: Record<Region, string> = {
|
||||
asia: 'Asia',
|
||||
};
|
||||
|
||||
// https://planetarynames.wr.usgs.gov/Abbreviations
|
||||
export const REGION_NAMES_SHORT: Record<Region, string> = {
|
||||
com: 'NA',
|
||||
eu: 'EU',
|
||||
asia: 'AS',
|
||||
};
|
||||
|
||||
export const REGION_SUBDOMAIN_NAMES: Record<RegionSubdomain, string> = {
|
||||
na: 'North America',
|
||||
eu: 'Europe',
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
|
||||
export default function diffStats(stats1: AllStats, stats2: AllStats) {
|
||||
function diff(value: (allStats: AllStats) => number) {
|
||||
return value(stats2) - value(stats1);
|
||||
}
|
||||
function max(value: (allStats: AllStats) => number) {
|
||||
return Math.max(value(stats1), value(stats2));
|
||||
}
|
||||
|
||||
return {
|
||||
battles: diff((a) => a.battles),
|
||||
wins: diff((a) => a.wins),
|
||||
capture_points: diff((a) => a.capture_points),
|
||||
damage_dealt: diff((a) => a.damage_dealt),
|
||||
damage_received: diff((a) => a.damage_received),
|
||||
dropped_capture_points: diff((a) => a.dropped_capture_points),
|
||||
frags: diff((a) => a.frags),
|
||||
frags8p: diff((a) => a.frags8p),
|
||||
hits: diff((a) => a.hits),
|
||||
losses: diff((a) => a.losses),
|
||||
max_frags: max((a) => a.max_frags),
|
||||
max_xp: max((a) => a.max_xp),
|
||||
shots: diff((a) => a.shots),
|
||||
spotted: diff((a) => a.spotted),
|
||||
survived_battles: diff((a) => a.survived_battles),
|
||||
win_and_survived: diff((a) => a.win_and_survived),
|
||||
xp: diff((a) => a.xp),
|
||||
} satisfies AllStats;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { DATABASE_REPO } from '../database/getMidnightLeaderboard';
|
||||
import { octokit } from '../express/octokit';
|
||||
import throwError from '../node/throwError';
|
||||
|
||||
export default async function getArchivedRatingsInfo(
|
||||
season: number,
|
||||
region: Region,
|
||||
) {
|
||||
const { data } = await octokit.repos.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${season}/info.json`,
|
||||
});
|
||||
|
||||
if (Array.isArray(data) || data.type !== 'file')
|
||||
throw throwError('Archived ratings info is malformed');
|
||||
|
||||
const content = Buffer.from(data.content, 'base64').toString();
|
||||
const jsonContent = JSON.parse(content) as RatingsInfo & {
|
||||
detail: undefined;
|
||||
};
|
||||
|
||||
return jsonContent;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export default async function getRatingsInfo(region: Region) {
|
||||
const response = await fetch(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
);
|
||||
|
||||
return (await response.json()) as Promise<RatingsInfo>;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { TreeType } from '../../components/Tanks';
|
||||
import { TreeTypeEnum } from '../../components/Tanks';
|
||||
import { tankopedia } from './tankopedia';
|
||||
|
||||
export default async function getTreeType(id: number) {
|
||||
const entry = (await tankopedia)[id];
|
||||
|
||||
if (entry?.is_collectible) return TreeType.Collector;
|
||||
if (entry?.is_premium) return TreeType.Premium;
|
||||
if (entry?.is_collectible) return TreeTypeEnum.Collector;
|
||||
if (entry?.is_premium) return TreeTypeEnum.Premium;
|
||||
|
||||
return TreeType.TechTree;
|
||||
return TreeTypeEnum.TechTree;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Thanks, August!
|
||||
* https://stackoverflow.com/a/41358305/12294756
|
||||
*/
|
||||
const ROMAN = {
|
||||
M: 1000,
|
||||
CM: 900,
|
||||
D: 500,
|
||||
CD: 400,
|
||||
C: 100,
|
||||
XC: 90,
|
||||
L: 50,
|
||||
XL: 40,
|
||||
X: 10,
|
||||
IX: 9,
|
||||
V: 5,
|
||||
IV: 4,
|
||||
I: 1,
|
||||
};
|
||||
const ROMAN_KEYS = Object.keys(ROMAN) as (keyof typeof ROMAN)[];
|
||||
|
||||
export default function numberToRomanNumeral(value: number) {
|
||||
let string = '';
|
||||
|
||||
ROMAN_KEYS.forEach((index) => {
|
||||
const part = Math.floor(value / ROMAN[index]);
|
||||
value -= part * ROMAN[index];
|
||||
string += index.repeat(part);
|
||||
});
|
||||
|
||||
return string;
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
import { deburr } from 'lodash';
|
||||
import { secrets } from '../node/secrets';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
||||
|
||||
export interface TankopediaEntry {
|
||||
name: string;
|
||||
nation: string;
|
||||
@@ -7,7 +13,7 @@ export interface TankopediaEntry {
|
||||
cost: { price_credit: number; price_gold: number };
|
||||
images: { preview: string; normal: string };
|
||||
tank_id: number;
|
||||
type: string;
|
||||
type: TankType;
|
||||
description: string;
|
||||
}
|
||||
|
||||
@@ -31,22 +37,54 @@ export const TANKS = new Promise<TankopediaEntry[]>(async (resolve) => {
|
||||
export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
|
||||
resolve((await entries).map(({ name }) => name));
|
||||
});
|
||||
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) =>
|
||||
Promise.all(
|
||||
tankNames.map(async (tankName, index) => {
|
||||
const id = (await TANKS)[index].tank_id;
|
||||
const name = tankName ?? `Unknown Tank ${id}`;
|
||||
const diacriticless = deburr(name);
|
||||
|
||||
export const TANK_ICONS: Record<string, string> = {
|
||||
return {
|
||||
original: name,
|
||||
diacriticless,
|
||||
combined: `${name}${diacriticless}`,
|
||||
id,
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export interface TankopediaInfo {
|
||||
achievement_sections: Record<string, { name: string; order: number }>;
|
||||
tanks_updated_at: number;
|
||||
languages: Record<string, string>;
|
||||
vehicle_types: Record<string, string>;
|
||||
vehicle_nations: Record<string, string>;
|
||||
game_version: string;
|
||||
}
|
||||
|
||||
// this is blocking because info is needed for command creation
|
||||
console.log('Caching tankopedia info...');
|
||||
export const tankopediaInfo = getWargamingResponse<TankopediaInfo>(
|
||||
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}`,
|
||||
);
|
||||
console.log('Cached tankopedia info');
|
||||
|
||||
export const TANK_ICONS: Record<TankType, string> = {
|
||||
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
|
||||
lightTank: 'https://i.imgur.com/CSNha5V.png',
|
||||
mediumTank: 'https://i.imgur.com/wvf3ltm.png',
|
||||
heavyTank: 'https://i.imgur.com/ECeqlZa.png',
|
||||
};
|
||||
|
||||
export const TANK_ICONS_PREMIUM: Record<string, string> = {
|
||||
export const TANK_ICONS_PREMIUM: Record<TankType, string> = {
|
||||
'AT-SPG': 'https://i.imgur.com/TCu3EdR.png',
|
||||
lightTank: 'https://i.imgur.com/zdkpTRb.png',
|
||||
mediumTank: 'https://i.imgur.com/3z7eHX6.png',
|
||||
heavyTank: 'https://i.imgur.com/P3vbmyA.png',
|
||||
};
|
||||
|
||||
export const TANK_ICONS_COLLECTOR: Record<string, string> = {
|
||||
export const TANK_ICONS_COLLECTOR: Record<TankType, string> = {
|
||||
'AT-SPG': 'https://i.imgur.com/WTjeirB.png',
|
||||
lightTank: 'https://i.imgur.com/EwhtKkU.png',
|
||||
mediumTank: 'https://i.imgur.com/u8YDMBh.png',
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize } from '../discord/addPeriodSubCommands';
|
||||
import getTimeDaysAgo from './getTimeDaysAgo';
|
||||
|
||||
export default function getPeriodStart(
|
||||
server: Region,
|
||||
period: Exclude<Period, 'custom'>,
|
||||
) {
|
||||
if (period === 'career') {
|
||||
return -Infinity;
|
||||
} else if (period === 'today') {
|
||||
return getTimeDaysAgo(server, 1);
|
||||
} else {
|
||||
return getTimeDaysAgo(server, parseInt(period));
|
||||
}
|
||||
export default function getPeriodStart(region: Region, period: PeriodSize) {
|
||||
return period === 'career' ? 0 : getTimeDaysAgo(region, parseInt(period));
|
||||
}
|
||||
@@ -6,13 +6,13 @@ export const TIME_ZONE_MAPPINGS: Record<Region, number> = {
|
||||
asia: +7, // Central Asia Standard Time
|
||||
};
|
||||
|
||||
export default function getTimeDaysAgo(server: Region, daysAgo: number) {
|
||||
export default function getTimeDaysAgo(region: Region, daysAgo: number) {
|
||||
const now = new Date();
|
||||
if (daysAgo === 0) now.getTime() / 1000;
|
||||
|
||||
const time = new Date();
|
||||
|
||||
time.setUTCHours(-TIME_ZONE_MAPPINGS[server], 0, 0, 0);
|
||||
time.setUTCHours(-TIME_ZONE_MAPPINGS[region], 0, 0, 0);
|
||||
if (time > now) time.setUTCDate(time.getUTCDate() - 1);
|
||||
time.setUTCDate(time.getUTCDate() - daysAgo + 1);
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import sumStats from '../blitz/sumStats';
|
||||
import { emptyAllStats } from './getDiffedTankStats';
|
||||
import { tankAverages } from './tankAverages';
|
||||
|
||||
console.log('Calculating player average...');
|
||||
export const playerAverage = Object.entries(await tankAverages).reduce(
|
||||
(accumulator, [, tankAverage]) => {
|
||||
return sumStats([accumulator, tankAverage.all]);
|
||||
},
|
||||
emptyAllStats,
|
||||
);
|
||||
console.log('Calculated player average');
|
||||
@@ -0,0 +1,27 @@
|
||||
import { BlitzkriegRatingsLeaderboard } from '../../../scripts/buildRatingsLeaderboard';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { octokit } from '../express/octokit';
|
||||
|
||||
export const DATABASE_REPO = { owner: 'tresabhi', repo: 'blitzkrieg-db' };
|
||||
|
||||
export default async function getMidnightLeaderboard(
|
||||
region: Region,
|
||||
season: number,
|
||||
) {
|
||||
try {
|
||||
const { data } = await octokit.repos.getContent({
|
||||
...DATABASE_REPO,
|
||||
path: `${region}/ratings/${season}/midnight.json`,
|
||||
});
|
||||
|
||||
if (!Array.isArray(data) && data.type === 'file') {
|
||||
const response = await fetch(data.download_url!);
|
||||
|
||||
return (await response.json()) as BlitzkriegRatingsLeaderboard;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`No midnight leaderboard found for season ${season}, region ${region}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ import {
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { PERIOD_NAMES } from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
||||
export type PeriodType = 'period' | 'custom';
|
||||
export type PeriodSize = `${number}` | 'career';
|
||||
|
||||
export default function addPeriodSubCommands(
|
||||
option: SlashCommandSubcommandGroupBuilder,
|
||||
@@ -14,36 +14,41 @@ export default function addPeriodSubCommands(
|
||||
) {
|
||||
return option
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('today').setDescription(PERIOD_NAMES.today)),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('30').setDescription(PERIOD_NAMES[30])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('60').setDescription(PERIOD_NAMES[60])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('90').setDescription(PERIOD_NAMES[90])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('career').setDescription(PERIOD_NAMES.career)),
|
||||
extra(
|
||||
option
|
||||
.setName('period' satisfies PeriodType)
|
||||
.setDescription("Preset period's statistics")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('period')
|
||||
.setDescription('A preset period')
|
||||
.setChoices(
|
||||
{ name: 'Today', value: '1' satisfies PeriodSize },
|
||||
{ name: '30 days', value: '30' satisfies PeriodSize },
|
||||
{ name: '60 days', value: '60' satisfies PeriodSize },
|
||||
{ name: '90 days', value: '90' satisfies PeriodSize },
|
||||
{ name: 'Career', value: 'career' satisfies PeriodSize },
|
||||
)
|
||||
.setRequired(true),
|
||||
),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('custom')
|
||||
.setDescription(PERIOD_NAMES.custom)
|
||||
.setName('custom' satisfies PeriodType)
|
||||
.setDescription("Custom period's statistics")
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('start')
|
||||
.setDescription('Start of period in days ago from today')
|
||||
.setDescription('Days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('end')
|
||||
.setDescription('End of period in days ago from today')
|
||||
.setDescription('Days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { TreeTypeString } from '../../components/Tanks';
|
||||
import { StatType } from '../../renderers/stats';
|
||||
import { tankopediaInfo } from '../blitz/tankopedia';
|
||||
import addPeriodSubCommands from './addPeriodSubCommands';
|
||||
import addTankChoices from './addTankChoices';
|
||||
import addTierChoices from './addTierChoices';
|
||||
import addUsernameChoices from './addUsernameChoices';
|
||||
|
||||
export default function addStatTypeSubCommandGroups(
|
||||
export default async function addStatTypeSubCommandGroups(
|
||||
option: SlashCommandBuilder,
|
||||
addMultiTank = true,
|
||||
) {
|
||||
return option
|
||||
const awaitedTankopediaInfo = await tankopediaInfo;
|
||||
|
||||
option
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
option.addStringOption(addUsernameChoices),
|
||||
)
|
||||
.setName('player')
|
||||
.setDescription("Player's statistics"),
|
||||
.setName('player' satisfies StatType)
|
||||
.setDescription('Player statistics'),
|
||||
)
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
@@ -20,7 +27,65 @@ export default function addStatTypeSubCommandGroups(
|
||||
.addStringOption(addTankChoices)
|
||||
.addStringOption(addUsernameChoices),
|
||||
)
|
||||
.setName('tank')
|
||||
.setDescription("Tank's statistics"),
|
||||
.setName('tank' satisfies StatType)
|
||||
.setDescription('Tank statistics'),
|
||||
);
|
||||
|
||||
if (addMultiTank)
|
||||
option.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
option
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addStringOption((option) => {
|
||||
option
|
||||
.setName('nation')
|
||||
.setDescription('Nation')
|
||||
.addChoices(
|
||||
...Object.entries(awaitedTankopediaInfo.vehicle_nations).map(
|
||||
([type, name]) => ({ name, value: type }),
|
||||
),
|
||||
);
|
||||
|
||||
return option;
|
||||
})
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('tank-type')
|
||||
.setDescription('Type')
|
||||
.addChoices(
|
||||
...Object.entries(awaitedTankopediaInfo.vehicle_types).map(
|
||||
([type, name]) => ({
|
||||
name: name.replace(' Tank', ''),
|
||||
value: type,
|
||||
}),
|
||||
),
|
||||
)
|
||||
.setRequired(false),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
addTierChoices(option).setRequired(false),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('tree-type')
|
||||
.setDescription('Tech tree type')
|
||||
.addChoices(
|
||||
{
|
||||
name: 'Tech Tree',
|
||||
value: 'techtree' satisfies TreeTypeString,
|
||||
},
|
||||
{ name: 'Premium', value: 'premium' satisfies TreeTypeString },
|
||||
{
|
||||
name: 'Collector',
|
||||
value: 'collector' satisfies TreeTypeString,
|
||||
},
|
||||
)
|
||||
.setRequired(false),
|
||||
),
|
||||
)
|
||||
.setName('multi-tank' satisfies StatType)
|
||||
.setDescription('Multiple tanks'),
|
||||
);
|
||||
|
||||
return option;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
import { range } from 'lodash';
|
||||
import numberToRomanNumeral from '../blitz/numberToRomanNumeral';
|
||||
|
||||
export default function addTierChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('tier')
|
||||
.setDescription('The tier you want to see')
|
||||
.setChoices(
|
||||
...range(10, 0).map((tier) => ({
|
||||
name: `Tier ${tier} - ${numberToRomanNumeral(tier)}`,
|
||||
value: `${tier}`,
|
||||
})),
|
||||
)
|
||||
.setRequired(true);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export default async function autocompleteClan(
|
||||
) {
|
||||
const focusedOption = interaction.options.getFocused(true);
|
||||
if (focusedOption.name !== 'clan') return;
|
||||
if (focusedOption.value.length < 2) return interaction.respond([]);
|
||||
const players = await listClans(focusedOption.value);
|
||||
|
||||
await interaction.respond(
|
||||
|
||||
@@ -4,8 +4,7 @@ import {
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import resolveTankName from '../blitz/resolveTankName';
|
||||
import { TANKS } from '../blitz/tankopedia';
|
||||
import { TANK_NAMES_DIACRITICS } from '../blitz/tankopedia';
|
||||
|
||||
export default async function autocompleteTanks(
|
||||
interaction: AutocompleteInteraction<CacheType>,
|
||||
@@ -16,16 +15,14 @@ export default async function autocompleteTanks(
|
||||
await interaction.respond(
|
||||
focusedOption.value
|
||||
? await Promise.all(
|
||||
go(focusedOption.value, await TANKS, {
|
||||
keys: ['name'],
|
||||
go(focusedOption.value, await TANK_NAMES_DIACRITICS, {
|
||||
keys: ['combined'],
|
||||
limit: 10,
|
||||
}).map(
|
||||
async (item) =>
|
||||
({
|
||||
name: item.obj.name
|
||||
? item.obj.name
|
||||
: await resolveTankName(item.obj.tank_id),
|
||||
value: `${item.obj.tank_id}`,
|
||||
name: item.obj.original,
|
||||
value: `${item.obj.id}`,
|
||||
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
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);
|
||||
@@ -19,12 +19,7 @@ export default function interactionToURL(
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('/');
|
||||
const params = [
|
||||
...interaction.options.data.map(
|
||||
(option) => [option.name, option.value] as const,
|
||||
),
|
||||
...Object.entries(parameters ?? {}),
|
||||
]
|
||||
const params = (parameters ? Object.entries(parameters) : [])
|
||||
.filter(([, value]) => value !== undefined && value !== null)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('&');
|
||||
|
||||
@@ -3,25 +3,11 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize, PeriodType } from '../discord/addPeriodSubCommands';
|
||||
|
||||
export const PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's statistics",
|
||||
30: "30 days' statistics",
|
||||
60: "60 days' statistics",
|
||||
90: "90 days' statistics",
|
||||
career: 'Career statistics',
|
||||
custom: 'Custom period',
|
||||
};
|
||||
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's evolution",
|
||||
30: "30 days' evolution",
|
||||
60: "60 days' evolution",
|
||||
90: "90 days' evolution",
|
||||
career: 'Career evolution',
|
||||
custom: 'Custom period',
|
||||
};
|
||||
export function getPeriodOptionName(period: PeriodSize) {
|
||||
return period === 'career' ? 'Career' : `${period}-day`;
|
||||
}
|
||||
|
||||
export interface ResolvedPeriod {
|
||||
statsName: string;
|
||||
@@ -31,29 +17,30 @@ export interface ResolvedPeriod {
|
||||
}
|
||||
|
||||
export default function resolvePeriodFromCommand(
|
||||
server: Region,
|
||||
region: Region,
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
let statsName: string;
|
||||
let evolutionName: string;
|
||||
let start: number;
|
||||
let end: number;
|
||||
const period = interaction.options.getSubcommand() as Period;
|
||||
const periodSubcommand = interaction.options.getSubcommand() as PeriodType;
|
||||
const periodOption = interaction.options.getString('period') as PeriodSize;
|
||||
|
||||
if (period === 'custom') {
|
||||
const startRaw = interaction.options.getInteger('start')!;
|
||||
const endRaw = interaction.options.getInteger('end')!;
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
const endMax = Math.max(startRaw, endRaw);
|
||||
if (periodSubcommand === 'custom') {
|
||||
const startRaw = interaction.options.getInteger('start', true);
|
||||
const endRaw = interaction.options.getInteger('end', true);
|
||||
const startDaysAgoMin = Math.min(startRaw, endRaw);
|
||||
const endDaysAgoMax = Math.max(startRaw, endRaw);
|
||||
|
||||
statsName = `${startMin} to ${endMax} days' statistics`;
|
||||
evolutionName = `${startMin} to ${endMax} days' evolution`;
|
||||
start = getTimeDaysAgo(server, startMin);
|
||||
end = getTimeDaysAgo(server, endMax);
|
||||
statsName = `${startDaysAgoMin} to ${endDaysAgoMax} days' statistics`;
|
||||
evolutionName = `${startDaysAgoMin} to ${endDaysAgoMax} days' evolution`;
|
||||
start = getTimeDaysAgo(region, endDaysAgoMax);
|
||||
end = getTimeDaysAgo(region, startDaysAgoMin);
|
||||
} else {
|
||||
statsName = PERIOD_NAMES[period];
|
||||
evolutionName = EVOLUTION_PERIOD_NAMES[period];
|
||||
start = getPeriodStart(server, period);
|
||||
statsName = `${getPeriodOptionName(periodOption)} Statistics`;
|
||||
evolutionName = `${getPeriodOptionName(periodOption)} Evolution`;
|
||||
start = getPeriodStart(region, periodOption);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
|
||||
// TODO: ADD THIS AGAIN IMMEDIATELY
|
||||
export const supportBlitzStars = new ButtonBuilder()
|
||||
.setLabel('Support BlitzStars')
|
||||
.setURL('https://www.blitzstars.com/supporters')
|
||||
.setStyle(ButtonStyle.Link);
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { secrets } from '../node/secrets';
|
||||
|
||||
export const octokit = new Octokit({ auth: secrets.GH_TOKEN });
|
||||
@@ -7,5 +7,5 @@ export default function resolvePeriodFromRequest(
|
||||
server: Region,
|
||||
request: Request,
|
||||
) {
|
||||
return resolvePeriodFromURL(server, `${CYCLIC_API}${request.path}`);
|
||||
return resolvePeriodFromURL(server, `${CYCLIC_API}${request.url}`);
|
||||
}
|
||||
@@ -2,11 +2,10 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize, PeriodType } from '../discord/addPeriodSubCommands';
|
||||
import {
|
||||
EVOLUTION_PERIOD_NAMES,
|
||||
PERIOD_NAMES,
|
||||
ResolvedPeriod,
|
||||
getPeriodOptionName,
|
||||
} from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromURL(
|
||||
@@ -19,29 +18,25 @@ export default function resolvePeriodFromURL(
|
||||
let end: number;
|
||||
const url = new URL(urlString);
|
||||
const path = url.pathname.split('/').filter(Boolean);
|
||||
const period = path[path.length - 1] as Period;
|
||||
const periodSubcommand = path[path.length - 1] as PeriodType;
|
||||
const periodOption = url.searchParams.get('period') as PeriodSize;
|
||||
|
||||
if (period === 'custom') {
|
||||
if (periodSubcommand === 'custom') {
|
||||
const startRaw = parseInt(url!.searchParams.get('start')!);
|
||||
const endRaw = parseInt(url!.searchParams.get('end')!);
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
const endMax = Math.max(startRaw, endRaw);
|
||||
const startDaysAgoMin = Math.min(startRaw, endRaw);
|
||||
const endDaysAgoMax = Math.max(startRaw, endRaw);
|
||||
|
||||
statsName = `${startMin} to ${endMax} days' statistics`;
|
||||
evolutionName = `${startMin} to ${endMax} days' evolution`;
|
||||
start = getTimeDaysAgo(server, startMin);
|
||||
end = getTimeDaysAgo(server, endMax);
|
||||
statsName = `${startDaysAgoMin} to ${endDaysAgoMax} days' statistics`;
|
||||
evolutionName = `${startDaysAgoMin} to ${endDaysAgoMax} days' evolution`;
|
||||
start = getTimeDaysAgo(server, endDaysAgoMax);
|
||||
end = getTimeDaysAgo(server, startDaysAgoMin);
|
||||
} else {
|
||||
statsName = PERIOD_NAMES[period];
|
||||
evolutionName = EVOLUTION_PERIOD_NAMES[period];
|
||||
start = getPeriodStart(server, period);
|
||||
statsName = `${getPeriodOptionName(periodOption)} Statistics`;
|
||||
evolutionName = `${getPeriodOptionName(periodOption)} Evolution`;
|
||||
start = getPeriodStart(server, periodOption);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
return {
|
||||
statsName,
|
||||
evolutionName,
|
||||
start,
|
||||
end,
|
||||
} satisfies ResolvedPeriod;
|
||||
return { statsName, evolutionName, start, end } satisfies ResolvedPeriod;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ Promise.all(
|
||||
|
||||
export default async function jsxToSvg(jsx: JSX.Element) {
|
||||
return await satori(jsx, {
|
||||
width: 640,
|
||||
width: 480,
|
||||
fonts: [
|
||||
{ data: roboto, name: FONT_NAME, weight: 400 },
|
||||
{ data: robotoBold, name: FONT_NAME, weight: 700 },
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { EmbedBuilder, TextChannel } from 'discord.js';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import { client } from '../bot';
|
||||
import { NEGATIVE_COLOR } from '../constants/colors';
|
||||
import { client } from '../core/discord/client';
|
||||
import isDev from '../core/node/isDev';
|
||||
|
||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { AutocompleteInteraction, CacheType } from 'discord.js';
|
||||
import { commands } from '..';
|
||||
|
||||
export default function handleAutocomplete(
|
||||
export default async function handleAutocomplete(
|
||||
interaction: AutocompleteInteraction<CacheType>,
|
||||
) {
|
||||
const command = commands[interaction.commandName];
|
||||
const command = (await commands)[interaction.commandName];
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
|
||||
@@ -11,7 +11,7 @@ export default async function handleButton(
|
||||
|
||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
||||
const commandName = url.pathname.split('/')[1];
|
||||
const button = commands[commandName]?.button;
|
||||
const button = (await commands)[commandName]?.button;
|
||||
|
||||
if (!button) {
|
||||
throwError(`Button handler not found for "${commandName}"`);
|
||||
|
||||
@@ -16,7 +16,7 @@ import { handleError } from '../../error';
|
||||
export default async function handleChatInputCommand(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
const registry = commands[interaction.commandName];
|
||||
const registry = (await commands)[interaction.commandName];
|
||||
|
||||
console.log(interaction.toString());
|
||||
await interaction.deferReply();
|
||||
|
||||
@@ -54,22 +54,30 @@ export interface Registry {
|
||||
inProduction: boolean;
|
||||
}
|
||||
|
||||
export interface CommandRegistry<HandlesInteraction extends boolean = boolean>
|
||||
extends Registry {
|
||||
export type CommandRegistryRaw = Registry & {
|
||||
inPublic: boolean;
|
||||
inPreview?: boolean;
|
||||
handlesInteraction?: HandlesInteraction;
|
||||
|
||||
command:
|
||||
| SlashCommandBuilder
|
||||
| SlashCommandSubcommandsOnlyBuilder
|
||||
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
|
||||
handler: (
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) => HandlesInteraction extends true ? void : InteractionReturnable;
|
||||
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
|
||||
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
|
||||
}
|
||||
} & (
|
||||
| {
|
||||
handlesInteraction: true;
|
||||
handler: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
||||
}
|
||||
| {
|
||||
handlesInteraction?: false;
|
||||
handler: (
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) => InteractionReturnable;
|
||||
}
|
||||
);
|
||||
export type CommandRegistry = CommandRegistryRaw | Promise<CommandRegistryRaw>;
|
||||
|
||||
const rest = new REST().setToken(secrets.DISCORD_TOKEN);
|
||||
|
||||
@@ -92,12 +100,19 @@ export const COMMANDS_RAW: CommandRegistry[] = [
|
||||
statsCommand,
|
||||
ratingsCommand,
|
||||
];
|
||||
export const commands: Record<string, CommandRegistry> = COMMANDS_RAW.reduce(
|
||||
(accumulator, registry) => {
|
||||
if (isDev()) registry.command.setDefaultMemberPermissions(0);
|
||||
return { ...accumulator, [registry.command.name]: registry };
|
||||
},
|
||||
{},
|
||||
|
||||
export const commands = Promise.all(COMMANDS_RAW).then((rawCommands) =>
|
||||
rawCommands.reduce<Record<string, CommandRegistryRaw>>(
|
||||
(accumulator, registry) => {
|
||||
if (isDev()) registry.command.setDefaultMemberPermissions(0);
|
||||
|
||||
return {
|
||||
...accumulator,
|
||||
[registry.command.name]: registry,
|
||||
};
|
||||
},
|
||||
{},
|
||||
),
|
||||
);
|
||||
|
||||
export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
|
||||
@@ -105,48 +120,50 @@ export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
|
||||
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
|
||||
[];
|
||||
|
||||
Object.entries(commands).forEach(([, registry]) => {
|
||||
if (isDev() ? registry.inDevelopment : registry.inProduction) {
|
||||
const json = registry.command.toJSON();
|
||||
commands.then((awaitedCommands) => {
|
||||
Object.entries(awaitedCommands).forEach(([, registry]) => {
|
||||
if (isDev() ? registry.inDevelopment : registry.inProduction) {
|
||||
const json = registry.command.toJSON();
|
||||
|
||||
if (registry.inPublic) {
|
||||
publicCommands.push(json);
|
||||
} else {
|
||||
guildCommands.push(json);
|
||||
if (registry.inPublic) {
|
||||
publicCommands.push(json);
|
||||
} else {
|
||||
guildCommands.push(json);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
console.log(`Refreshing ${publicCommands.length} public command(s).`);
|
||||
rest
|
||||
.put(Routes.applicationCommands(getClientId()), { body: publicCommands })
|
||||
.then((publicData) => {
|
||||
console.log(
|
||||
`Successfully refreshed ${
|
||||
(publicData as RESTPostAPIChatInputApplicationCommandsJSONBody[])
|
||||
.length
|
||||
} public command(s).`,
|
||||
);
|
||||
});
|
||||
|
||||
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
|
||||
rest
|
||||
.put(
|
||||
Routes.applicationGuildCommands(getClientId(), discord.tres_guild_id),
|
||||
{ body: guildCommands },
|
||||
)
|
||||
.then((guildData) => {
|
||||
console.log(
|
||||
`Successfully refreshed ${
|
||||
(guildData as unknown[]).length
|
||||
} guild command(s).`,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
console.log(`Refreshing ${publicCommands.length} public command(s).`);
|
||||
rest
|
||||
.put(Routes.applicationCommands(getClientId()), { body: publicCommands })
|
||||
.then((publicData) => {
|
||||
console.log(
|
||||
`Successfully refreshed ${
|
||||
(publicData as RESTPostAPIChatInputApplicationCommandsJSONBody[])
|
||||
.length
|
||||
} public command(s).`,
|
||||
);
|
||||
});
|
||||
|
||||
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
|
||||
rest
|
||||
.put(
|
||||
Routes.applicationGuildCommands(getClientId(), discord.tres_guild_id),
|
||||
{ body: guildCommands },
|
||||
)
|
||||
.then((guildData) => {
|
||||
console.log(
|
||||
`Successfully refreshed ${
|
||||
(guildData as unknown[]).length
|
||||
} guild command(s).`,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
export default async function interactionCreate(
|
||||
interaction: Interaction<CacheType>,
|
||||
) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import * as Graph from '../components/Graph';
|
||||
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 getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankName from '../core/blitz/resolveTankName';
|
||||
import { tankopedia } from '../core/blitz/tankopedia';
|
||||
@@ -15,7 +13,7 @@ import { secrets } from '../core/node/secrets';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { Histories } from '../types/histories';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { StatType } from './fullStats';
|
||||
import { StatType } from './stats';
|
||||
|
||||
export default async function evolution<Type extends StatType>(
|
||||
type: Type,
|
||||
@@ -88,20 +86,17 @@ export default async function evolution<Type extends StatType>(
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={nameDiscriminator}
|
||||
image={image}
|
||||
description={`${evolutionName} • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
description={`${evolutionName} • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{/* goofy ahh bug forces me to call them as functions */}
|
||||
{plot.length > 0 && (
|
||||
<Graph.Root
|
||||
xTitle="Battles"
|
||||
verticalMargin={{
|
||||
min: minY,
|
||||
max: maxY,
|
||||
suffix: '%',
|
||||
precision: 1,
|
||||
precision: 2,
|
||||
}}
|
||||
horizontalMargin={{
|
||||
min: minX,
|
||||
@@ -122,8 +117,6 @@ export default async function evolution<Type extends StatType>(
|
||||
)}
|
||||
|
||||
{plot.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
|
||||
<PoweredBy type={PoweredByType.BlitzStars} />
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
+80
-76
@@ -1,10 +1,8 @@
|
||||
import GenericAllStats from '../components/GenericAllStats';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import PoweredBy, { PoweredByType } from '../components/PoweredBy';
|
||||
import TierWeights, { TierWeightsRecord } from '../components/TierWeights';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { REGION_NAMES } from '../constants/regions';
|
||||
import calculateWN8 from '../core/blitz/calculateWN8';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankName from '../core/blitz/resolveTankName';
|
||||
@@ -21,20 +19,22 @@ import {
|
||||
SupplementaryStats,
|
||||
} from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export type StatType = 'player' | 'tank';
|
||||
import { MultiTankFilters, StatType } from './stats';
|
||||
|
||||
export default async function fullStats<Type extends StatType>(
|
||||
type: Type,
|
||||
{ start, end, statsName }: ResolvedPeriod,
|
||||
{ region: server, id }: ResolvedPlayer,
|
||||
tankId: Type extends 'tank' ? number : null,
|
||||
filters: Type extends 'tank'
|
||||
? number
|
||||
: Type extends 'multi-tank'
|
||||
? Partial<MultiTankFilters>
|
||||
: null,
|
||||
) {
|
||||
let nameDiscriminator: string | undefined;
|
||||
let image: string | undefined;
|
||||
|
||||
if (type === 'player') {
|
||||
if (type === 'player' || type === 'multi-tank') {
|
||||
const clan = (
|
||||
await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
@@ -46,89 +46,97 @@ export default async function fullStats<Type extends StatType>(
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!]?.images.normal;
|
||||
nameDiscriminator = `(${await resolveTankName(filters as number)})`;
|
||||
image = (await tankopedia)[filters as number]?.images.normal;
|
||||
}
|
||||
|
||||
const { diffed } = await getDiffedTankStats(server, id, start, end);
|
||||
let stats: AllStats;
|
||||
const { diffed, order } = await getDiffedTankStats(server, id, start, end);
|
||||
const awaitedTankopedia = await tankopedia;
|
||||
let stats: AllStats | undefined;
|
||||
let supplementaryStats: SupplementaryStats;
|
||||
let tierWeights: TierWeightsRecord;
|
||||
|
||||
if (type === 'player') {
|
||||
const entries = Object.entries(diffed);
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
const battlesOfTanksWithAverages = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage ? (await accumulator) + stats.battles : accumulator;
|
||||
}, 0);
|
||||
const battlesOfTanksWithTankopediaEntry = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + stats.battles
|
||||
: accumulator;
|
||||
}, 0);
|
||||
if (type === 'player' || type === 'multi-tank') {
|
||||
const typedFilters = filters as Partial<MultiTankFilters> | null;
|
||||
const filteredOrder = order.filter(
|
||||
(id) =>
|
||||
typedFilters === null ||
|
||||
((typedFilters.nation === undefined ||
|
||||
awaitedTankopedia[id]?.nation === typedFilters.nation) &&
|
||||
(typedFilters['tank-type'] === undefined ||
|
||||
awaitedTankopedia[id]?.type === typedFilters['tank-type']) &&
|
||||
(typedFilters.tier === undefined ||
|
||||
awaitedTankopedia[id]?.tier === typedFilters.tier) &&
|
||||
(typedFilters['tree-type'] === undefined ||
|
||||
(typedFilters['tree-type'] === 'collector' &&
|
||||
awaitedTankopedia[id]?.is_collectible) ||
|
||||
(typedFilters['tree-type'] === 'premium' &&
|
||||
awaitedTankopedia[id]?.is_premium) ||
|
||||
(typedFilters['tree-type'] === 'techtree' &&
|
||||
!awaitedTankopedia[id]?.is_collectible &&
|
||||
!awaitedTankopedia[id]?.is_premium))),
|
||||
);
|
||||
const awaitedTankAverages = await tankAverages;
|
||||
stats = sumStats(filteredOrder.map((id) => diffed[id]));
|
||||
const battlesOfTanksWithAverages = filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankAverages[id]
|
||||
? accumulator + diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
);
|
||||
const battlesOfTanksWithTankopediaEntry = filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankopedia[id] ? accumulator + diffed[id].battles : accumulator,
|
||||
0,
|
||||
);
|
||||
|
||||
supplementaryStats = {
|
||||
WN8:
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage
|
||||
? (await accumulator) +
|
||||
calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankAverages[id]
|
||||
? accumulator +
|
||||
calculateWN8(awaitedTankAverages[id].all, diffed[id]) *
|
||||
diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
)) / battlesOfTanksWithAverages,
|
||||
) / battlesOfTanksWithAverages,
|
||||
tier:
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankopedia[id]
|
||||
? accumulator + awaitedTankopedia[id]!.tier * diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
)) / battlesOfTanksWithTankopediaEntry,
|
||||
) / battlesOfTanksWithTankopediaEntry,
|
||||
};
|
||||
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
tierWeights = filteredOrder.reduce<TierWeightsRecord>((accumulator, id) => {
|
||||
const tankopediaEntry = awaitedTankopedia[id];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tier = tankopediaEntry.tier as Tier;
|
||||
const tier = tankopediaEntry.tier as Tier;
|
||||
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
} else {
|
||||
(await accumulator)[tier] = stats.battles;
|
||||
}
|
||||
if (accumulator[tier]) {
|
||||
accumulator[tier]! += diffed[id].battles;
|
||||
} else {
|
||||
accumulator[tier] = diffed[id].battles;
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
},
|
||||
{},
|
||||
);
|
||||
return accumulator;
|
||||
}, {});
|
||||
} else {
|
||||
stats = diffed[tankId!];
|
||||
stats = diffed[(filters as number)!];
|
||||
|
||||
supplementaryStats = {
|
||||
WN8: calculateWN8((await tankAverages)[tankId!].all, diffed[tankId!]),
|
||||
tier: (await tankopedia)[tankId!]?.tier,
|
||||
WN8: stats
|
||||
? calculateWN8(
|
||||
(await tankAverages)[(filters as number)!].all,
|
||||
diffed[(filters as number)!],
|
||||
)
|
||||
: undefined,
|
||||
tier: (await tankopedia)[(filters as number)!]?.tier,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -142,9 +150,7 @@ export default async function fullStats<Type extends StatType>(
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={nameDiscriminator}
|
||||
image={image}
|
||||
description={`${statsName} • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
description={`${statsName} • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
@@ -157,8 +163,6 @@ export default async function fullStats<Type extends StatType>(
|
||||
supplementaryStats={supplementaryStats}
|
||||
/>
|
||||
)}
|
||||
|
||||
<PoweredBy type={PoweredByType.BlitzStars} />
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
+78
-83
@@ -1,15 +1,13 @@
|
||||
import AllStatsOverview from '../components/AllStatsOverview';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import PoweredBy, { PoweredByType } from '../components/PoweredBy';
|
||||
import { TierWeightsRecord } from '../components/TierWeights';
|
||||
import { TreeTypeString } from '../components/Tanks';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { REGION_NAMES } from '../constants/regions';
|
||||
import calculateWN8 from '../core/blitz/calculateWN8';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankName from '../core/blitz/resolveTankName';
|
||||
import sumStats from '../core/blitz/sumStats';
|
||||
import { Tier, tankopedia } from '../core/blitz/tankopedia';
|
||||
import { tankopedia } from '../core/blitz/tankopedia';
|
||||
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||
import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand';
|
||||
@@ -22,21 +20,31 @@ import {
|
||||
SupplementaryStats,
|
||||
} from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export type StatType = 'player' | 'tank';
|
||||
export type StatType = 'player' | 'tank' | 'multi-tank';
|
||||
|
||||
export interface MultiTankFilters {
|
||||
nation: string;
|
||||
'tank-type': string;
|
||||
tier: number;
|
||||
'tree-type': TreeTypeString;
|
||||
}
|
||||
|
||||
export default async function stats<Type extends StatType>(
|
||||
type: Type,
|
||||
{ start, end, statsName }: ResolvedPeriod,
|
||||
{ region: server, id }: ResolvedPlayer,
|
||||
tankId: Type extends 'tank' ? number : null,
|
||||
filters: Type extends 'tank'
|
||||
? number
|
||||
: Type extends 'multi-tank'
|
||||
? Partial<MultiTankFilters>
|
||||
: null,
|
||||
naked = false,
|
||||
) {
|
||||
let nameDiscriminator: string | undefined;
|
||||
let image: string | undefined;
|
||||
|
||||
if (type === 'player') {
|
||||
if (type === 'player' || type === 'multi-tank') {
|
||||
const clan = (
|
||||
await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
@@ -48,91 +56,82 @@ export default async function stats<Type extends StatType>(
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!]?.images.normal;
|
||||
nameDiscriminator = `(${await resolveTankName(filters as number)})`;
|
||||
image = (await tankopedia)[filters as number]?.images.normal;
|
||||
} else {
|
||||
}
|
||||
|
||||
const { diffed } = await getDiffedTankStats(server, id, start, end);
|
||||
const { diffed, order } = await getDiffedTankStats(server, id, start, end);
|
||||
const awaitedTankopedia = await tankopedia;
|
||||
let stats: AllStats | undefined;
|
||||
let supplementaryStats: SupplementaryStats;
|
||||
let tierWeights: TierWeightsRecord;
|
||||
|
||||
if (type === 'player') {
|
||||
const entries = Object.entries(diffed);
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
const battlesOfTanksWithAverages = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage ? (await accumulator) + stats.battles : accumulator;
|
||||
}, 0);
|
||||
const battlesOfTanksWithTankopediaEntry = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + stats.battles
|
||||
: accumulator;
|
||||
}, 0);
|
||||
if (type === 'player' || type === 'multi-tank') {
|
||||
const typedFilters = filters as Partial<MultiTankFilters> | null;
|
||||
const filteredOrder = order.filter(
|
||||
(id) =>
|
||||
typedFilters === null ||
|
||||
((typedFilters.nation === undefined ||
|
||||
awaitedTankopedia[id]?.nation === typedFilters.nation) &&
|
||||
(typedFilters['tank-type'] === undefined ||
|
||||
awaitedTankopedia[id]?.type === typedFilters['tank-type']) &&
|
||||
(typedFilters.tier === undefined ||
|
||||
awaitedTankopedia[id]?.tier === typedFilters.tier) &&
|
||||
(typedFilters['tree-type'] === undefined ||
|
||||
(typedFilters['tree-type'] === 'collector' &&
|
||||
awaitedTankopedia[id]?.is_collectible) ||
|
||||
(typedFilters['tree-type'] === 'premium' &&
|
||||
awaitedTankopedia[id]?.is_premium) ||
|
||||
(typedFilters['tree-type'] === 'techtree' &&
|
||||
!awaitedTankopedia[id]?.is_collectible &&
|
||||
!awaitedTankopedia[id]?.is_premium))),
|
||||
);
|
||||
const awaitedTankAverages = await tankAverages;
|
||||
stats = sumStats(filteredOrder.map((id) => diffed[id]));
|
||||
const battlesOfTanksWithAverages = filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankAverages[id]
|
||||
? accumulator + diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
);
|
||||
const battlesOfTanksWithTankopediaEntry = filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankopedia[id] ? accumulator + diffed[id].battles : accumulator,
|
||||
0,
|
||||
);
|
||||
|
||||
supplementaryStats = {
|
||||
WN8:
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage
|
||||
? (await accumulator) +
|
||||
calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankAverages[id]
|
||||
? accumulator +
|
||||
calculateWN8(awaitedTankAverages[id].all, diffed[id]) *
|
||||
diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
)) / battlesOfTanksWithAverages,
|
||||
) / battlesOfTanksWithAverages,
|
||||
tier:
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
filteredOrder.reduce<number>(
|
||||
(accumulator, id) =>
|
||||
awaitedTankopedia[id]
|
||||
? accumulator + awaitedTankopedia[id]!.tier * diffed[id].battles
|
||||
: accumulator,
|
||||
0,
|
||||
)) / battlesOfTanksWithTankopediaEntry,
|
||||
) / battlesOfTanksWithTankopediaEntry,
|
||||
};
|
||||
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tier = tankopediaEntry.tier as Tier;
|
||||
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
} else {
|
||||
(await accumulator)[tier] = stats.battles;
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
},
|
||||
{},
|
||||
);
|
||||
} else {
|
||||
stats = diffed[tankId!];
|
||||
stats = diffed[(filters as number)!];
|
||||
|
||||
supplementaryStats = {
|
||||
WN8: stats
|
||||
? calculateWN8((await tankAverages)[tankId!].all, diffed[tankId!])
|
||||
? calculateWN8(
|
||||
(await tankAverages)[(filters as number)!].all,
|
||||
diffed[(filters as number)!],
|
||||
)
|
||||
: undefined,
|
||||
tier: (await tankopedia)[tankId!]?.tier,
|
||||
tier: (await tankopedia)[(filters as number)!]?.tier,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ export default async function stats<Type extends StatType>(
|
||||
gap: 4,
|
||||
}}
|
||||
>
|
||||
<u>/statsfull</u> for all statistics
|
||||
<u>/full-stats</u> for all statistics
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -161,17 +160,13 @@ export default async function stats<Type extends StatType>(
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
nameDiscriminator={nameDiscriminator}
|
||||
image={image}
|
||||
description={`${statsName} • ${new Date().toDateString()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
nameDiscriminator={nameDiscriminator}
|
||||
description={`${statsName} • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{!stats?.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
{stats?.battles > 0 && overview}
|
||||
|
||||
<PoweredBy type={PoweredByType.BlitzStars} footer={footer} />
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
+57
-56
@@ -1,11 +1,10 @@
|
||||
import * as Breakdown from '../components/Breakdown';
|
||||
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 calculateWN8 from '../core/blitz/calculateWN8';
|
||||
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 sumStats from '../core/blitz/sumStats';
|
||||
@@ -22,7 +21,9 @@ import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export default async function today(
|
||||
{ region: server, id }: ResolvedPlayer,
|
||||
limit = Infinity,
|
||||
cutoff = Infinity,
|
||||
maximized = 4,
|
||||
showTotal = true,
|
||||
naked?: boolean,
|
||||
) {
|
||||
const { diffed, order } = await getDiffedTankStats(
|
||||
@@ -38,9 +39,11 @@ export default async function today(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const careerTankStatsRaw = await getTankStats(server, id);
|
||||
const careerStats: Record<number, AllStats> = {
|
||||
0: accountInfo[id].statistics.all,
|
||||
};
|
||||
const careerStats: Record<number, AllStats> = showTotal
|
||||
? {
|
||||
0: accountInfo[id].statistics.all,
|
||||
}
|
||||
: {};
|
||||
const allStatsToAccumulate: AllStats[] = [];
|
||||
|
||||
Object.entries(diffed).forEach(([, tankStats]) => {
|
||||
@@ -52,7 +55,7 @@ export default async function today(
|
||||
|
||||
const accumulatedStats = sumStats(allStatsToAccumulate);
|
||||
|
||||
if (Object.keys(diffed).length > 0) {
|
||||
if (showTotal && Object.keys(diffed).length > 0) {
|
||||
diffed[0] = accumulatedStats;
|
||||
}
|
||||
|
||||
@@ -62,7 +65,7 @@ export default async function today(
|
||||
>(async (accumulator, [tankIdString, tankStats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
return tankId === 0 || !(await tankAverages)[tankId]
|
||||
return (showTotal && tankId === 0) || !(await tankAverages)[tankId]
|
||||
? accumulator
|
||||
: {
|
||||
...(await accumulator),
|
||||
@@ -73,7 +76,8 @@ export default async function today(
|
||||
const careerWN8s = await careerTankStatsRaw.reduce<
|
||||
PossiblyPromise<Record<number, number>>
|
||||
>(async (accumulator, { tank_id }) => {
|
||||
return tank_id === 0 || (await tankAverages)[tank_id] === undefined
|
||||
return (showTotal && tank_id === 0) ||
|
||||
(await tankAverages)[tank_id] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...(await accumulator),
|
||||
@@ -86,60 +90,61 @@ export default async function today(
|
||||
const todayWN8sEntries = Object.entries(todayWN8s);
|
||||
const careerWN8sEntries = Object.entries(careerWN8s);
|
||||
|
||||
todayWN8s[0] =
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, wn8]) =>
|
||||
accumulator + wn8 * diffed[Number(tankIdString)].battles,
|
||||
0,
|
||||
) /
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString]) =>
|
||||
accumulator + diffed[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,
|
||||
);
|
||||
if (showTotal) {
|
||||
todayWN8s[0] =
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, wn8]) =>
|
||||
accumulator + wn8 * diffed[Number(tankIdString)].battles,
|
||||
0,
|
||||
) /
|
||||
todayWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString]) =>
|
||||
accumulator + diffed[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 = await Promise.all(
|
||||
[
|
||||
// this code unreadable on god will forget tomorrow no cap
|
||||
...(order.length === 0 ? [] : [0]),
|
||||
...(isFinite(limit) ? order.slice(0, limit) : order),
|
||||
].map(async (tankId, index) => {
|
||||
const tankStats = diffed[tankId];
|
||||
const career = careerStats[tankId];
|
||||
...(order.length === 0 || !showTotal ? [] : [0]),
|
||||
...(isFinite(cutoff) ? order.slice(0, cutoff) : order),
|
||||
].map(async (id, index) => {
|
||||
const tankStats = diffed[id];
|
||||
const career = careerStats[id];
|
||||
const tankopediaEntry = (await tankopedia)[id];
|
||||
|
||||
return (
|
||||
<Breakdown.Row
|
||||
naked={naked}
|
||||
isListing={tankId !== 0}
|
||||
minimized={index > 4}
|
||||
key={tankId}
|
||||
name={tankId === 0 ? 'Total' : await resolveTankName(tankId)}
|
||||
isTank={!showTotal || id !== 0}
|
||||
tankType={tankopediaEntry?.type}
|
||||
treeType={tankopediaEntry ? await getTreeType(id) : undefined}
|
||||
minimized={showTotal ? index > maximized : index + 1 > maximized}
|
||||
key={id}
|
||||
name={showTotal && id === 0 ? 'Total' : await resolveTankName(id)}
|
||||
winrate={tankStats.wins / tankStats.battles}
|
||||
careerWinrate={career.wins / career.battles}
|
||||
WN8={isNaN(todayWN8s[tankId]) ? undefined : todayWN8s[tankId]}
|
||||
careerWN8={isNaN(careerWN8s[tankId]) ? undefined : careerWN8s[tankId]}
|
||||
WN8={isNaN(todayWN8s[id]) ? undefined : todayWN8s[id]}
|
||||
careerWN8={isNaN(careerWN8s[id]) ? undefined : careerWN8s[id]}
|
||||
damage={tankStats.damage_dealt / tankStats.battles}
|
||||
careerDamage={career.damage_dealt / career.battles}
|
||||
battles={tankStats.battles}
|
||||
careerBattles={career.battles}
|
||||
icon={
|
||||
tankId === 0 ? undefined : (await tankopedia)[tankId]?.images.normal
|
||||
}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
@@ -147,7 +152,7 @@ export default async function today(
|
||||
|
||||
return naked ? (
|
||||
<Wrapper naked>
|
||||
<Breakdown.Root>{rows.slice(1)}</Breakdown.Root>
|
||||
<Breakdown.Root>{rows}</Breakdown.Root>
|
||||
</Wrapper>
|
||||
) : (
|
||||
<Wrapper>
|
||||
@@ -161,15 +166,11 @@ export default async function today(
|
||||
? `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()} • ${
|
||||
REGION_NAMES[server]
|
||||
}`}
|
||||
description={`Today's breakdown • ${new Date().toDateString()}`}
|
||||
/>
|
||||
|
||||
{rows.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
{rows.length > 0 && <Breakdown.Root>{rows}</Breakdown.Root>}
|
||||
|
||||
<PoweredBy type={PoweredByType.BlitzStars} />
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { RouteRegistry } from '../server';
|
||||
export const statsRoute: RouteRegistry = {
|
||||
route: '/stats/:type/:period',
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
|
||||
async handler(req) {
|
||||
const type = req.params.type as StatType;
|
||||
|
||||
@@ -5,14 +5,16 @@ import { RouteRegistry } from '../server';
|
||||
export const todayRoute: RouteRegistry = {
|
||||
route: '/today',
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
|
||||
async handler(req) {
|
||||
const player = resolvePlayerFromRequest(req);
|
||||
|
||||
return await today(
|
||||
player,
|
||||
req.query.limit ? parseInt(req.query.limit as string) : undefined,
|
||||
req.query.cutoff ? parseInt(req.query.cutoff as string) : undefined,
|
||||
req.query.maximized ? parseInt(req.query.maximized as string) : undefined,
|
||||
req.query['show-total'] ? req.query['show-total'] === 'true' : undefined,
|
||||
true,
|
||||
);
|
||||
},
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ const app = express();
|
||||
if (registry.handlesInteraction) return;
|
||||
|
||||
res.send(
|
||||
withAutoRefresh(await normalizeRouteReturnable(returnable), 60 * 1000),
|
||||
withAutoRefresh(await normalizeRouteReturnable(returnable), 30 * 1000),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@
|
||||
"resolveJsonModule": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
"include": ["src/**/*.ts", "src/components/Tanks/components/Row.tsx"]
|
||||
}
|
||||
Reference in new issue
Block a user