fix: more linting

This commit is contained in:
TrèsAbhi committed 2025-09-27 18:01:20 -05:00
1 parent 766801826c
commit 6261dfc9cd
10 files changed
+377 -383

No files matched your search

+37 -37
View File
@@ -6,23 +6,23 @@ import {
getTankStats,
getWN8Percentile,
TankDefinition,
} from '@blitzkit/core';
import { literals } from '@blitzkit/i18n';
import { Locale } from 'discord.js';
import { chunk } from 'lodash-es';
import * as Breakdown from '../../components/Breakdown';
import { CommandWrapper } from '../../components/CommandWrapper';
import { NoData } from '../../components/NoData';
import { TitleBar } from '../../components/TitleBar';
import { filtersToDescription } from '../../core/blitzkit/filtersToDescription';
import { tankDefinitions } from '../../core/blitzkit/nonBlockingPromises';
import { UserError } from '../../core/blitzkit/userError';
import { filterStats, StatFilters } from '../../core/blitzstars/filterStats';
import { getStatsInPeriod } from '../../core/blitzstars/getStatsInPeriod';
import { blitzStarsTankAverages } from '../../core/blitzstars/tankAverages';
import { ResolvedPeriod } from '../../core/discord/resolvePeriodFromCommand';
import { ResolvedPlayer } from '../../core/discord/resolvePlayerFromCommand';
import { translator } from '../../core/localization/translator';
} from "@blitzkit/core";
import { literals } from "@blitzkit/i18n";
import { Locale } from "discord.js";
import { chunk } from "lodash-es";
import * as Breakdown from "../../components/Breakdown";
import { CommandWrapper } from "../../components/CommandWrapper";
import { NoData } from "../../components/NoData";
import { TitleBar } from "../../components/TitleBar";
import { filtersToDescription } from "../../core/blitzkit/filtersToDescription";
import { tankDefinitions } from "../../core/blitzkit/nonBlockingPromises";
import { UserError } from "../../core/blitzkit/userError";
import { filterStats, StatFilters } from "../../core/blitzstars/filterStats";
import { getStatsInPeriod } from "../../core/blitzstars/getStatsInPeriod";
import { blitzStarsTankAverages } from "../../core/blitzstars/tankAverages";
import { ResolvedPeriod } from "../../core/discord/resolvePeriodFromCommand";
import { ResolvedPlayer } from "../../core/discord/resolvePlayerFromCommand";
import { translator } from "../../core/localization/translator";
const ROWS_PER_PAGE = 8;
const MAX_PAGES = 9;
@@ -31,7 +31,7 @@ export async function renderBreakdown(
{ region, id }: ResolvedPlayer,
{ start, end, name }: ResolvedPeriod,
filters: StatFilters,
locale: Locale,
locale: Locale
) {
const { strings, unwrap } = translator(locale);
const awaitedTankDefinitions = await tankDefinitions;
@@ -39,7 +39,7 @@ export async function renderBreakdown(
const statsInPeriod = await getStatsInPeriod(region, id, start, end, locale);
const { filteredOrder } = await filterStats(statsInPeriod, filters);
const accountInfo = await getAccountInfo(region, id);
const clanData = await getClanAccountInfo(region, id, ['clan']);
const clanData = await getClanAccountInfo(region, id, ["clan"]);
const tankStats = await getTankStats(region, id);
const filterDescriptions = await filtersToDescription(filters, locale);
const orderedCurrentStats: BlitzStats[] = [];
@@ -74,63 +74,63 @@ export async function renderBreakdown(
orderedCareerWN8Full.push(
tankAveragesEntry
? calculateWN8(tankAveragesEntry.all, tank.all)
: undefined,
: undefined
);
});
const currentBattles = orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.battles,
0,
0
);
const careerBattles = tankStats.reduce(
(accumulator, current) => accumulator + current.all.battles,
0,
0
);
const currentWinrate =
orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.wins,
0,
0
) / currentBattles;
const careerWinrate =
tankStats.reduce(
(accumulator, current) => accumulator + current.all.wins,
0,
0
) / careerBattles;
const currentWN8 =
orderedCurrentWN8.reduce<number>(
(accumulator, current, index) =>
accumulator + (current ?? 0) * orderedCurrentStats[index].battles,
0,
0
) /
orderedCurrentStats.reduce(
(accumulator, current, index) =>
accumulator +
(orderedCurrentWN8[index] === undefined ? 0 : current.battles),
0,
0
);
const careerWN8 =
orderedCareerWN8Full.reduce<number>(
(accumulator, current) => accumulator + (current ?? 0),
0,
0
) /
tankStats.reduce(
(accumulator, current, index) =>
accumulator +
(orderedCareerWN8Full[index] === undefined ? 0 : current.all.battles),
0,
0
);
const currentDamage =
orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.damage_dealt,
0,
0
) / currentBattles;
const careerDamage =
tankStats.reduce(
(accumulator, current) => accumulator + current.all.damage_dealt,
0,
0
) / careerBattles;
const children: JSX.Element[] = [];
const children: React.JSX.Element[] = [];
if (filteredOrder.length > 0) {
children.push(
@@ -172,7 +172,7 @@ export async function renderBreakdown(
delta: currentDamage - careerDamage,
},
]}
/>,
/>
);
filteredOrder.forEach((id, index) => {
@@ -206,7 +206,7 @@ export async function renderBreakdown(
{
title: strings.bot.commands.breakdown.body.winrate,
current: `${(100 * (current.wins / current.battles)).toFixed(
2,
2
)}%`,
career: `${(100 * (career.wins / career.battles)).toFixed(2)}%`,
delta:
@@ -230,24 +230,24 @@ export async function renderBreakdown(
{
title: strings.bot.commands.breakdown.body.damage,
current: Math.round(
current.damage_dealt / current.battles,
current.damage_dealt / current.battles
).toLocaleString(),
career: Math.round(
career.damage_dealt / career.battles,
career.damage_dealt / career.battles
).toLocaleString(),
delta:
current.damage_dealt / current.battles -
career.damage_dealt / career.battles,
},
]}
/>,
/>
);
});
}
const pages = chunk(
children,
Math.max(Math.ceil(children.length / MAX_PAGES), ROWS_PER_PAGE),
Math.max(Math.ceil(children.length / MAX_PAGES), ROWS_PER_PAGE)
);
if (filteredOrder.length > 0) {
+3 -3
View File
@@ -1,7 +1,7 @@
import { jsxToSvg } from './jsxToSvg';
import { svgToPng } from './svgToPng';
import { jsxToSvg } from "./jsxToSvg";
import { svgToPng } from "./svgToPng";
export async function jsxToPng(jsx: JSX.Element) {
export async function jsxToPng(jsx: React.JSX.Element) {
const svg = await jsxToSvg(jsx);
const png = svgToPng(svg);
@@ -1,10 +1,10 @@
import { jsxToSvg } from './jsxToSvg';
import { RenderConfiguration } from './renderConfiguration';
import { svgToPngThreaded } from './svgToPngThreaded';
import { jsxToSvg } from "./jsxToSvg";
import { RenderConfiguration } from "./renderConfiguration";
import { svgToPngThreaded } from "./svgToPngThreaded";
export async function jsxToPngThreaded(
jsx: JSX.Element,
renderConfiguration: RenderConfiguration,
jsx: React.JSX.Element,
renderConfiguration: RenderConfiguration
) {
const svg = await jsxToSvg(jsx, renderConfiguration);
const png = await svgToPngThreaded(svg);
@@ -1,9 +1,9 @@
import { readFile } from 'fs/promises';
import satori from 'satori';
import { RenderConfiguration } from '../renderConfiguration';
import robotoBlack from './Roboto-Black.ttf';
import robotoBold from './Roboto-Bold.ttf';
import roboto from './Roboto.ttf';
import { readFile } from "fs/promises";
import satori from "satori";
import { RenderConfiguration } from "../renderConfiguration";
import robotoBlack from "./Roboto-Black.ttf";
import robotoBold from "./Roboto-Bold.ttf";
import roboto from "./Roboto.ttf";
const fontsPromise = [
{ file: roboto, weight: 400 as const },
@@ -11,12 +11,12 @@ const fontsPromise = [
{ file: robotoBlack, weight: 900 as const },
].map(async ({ file, weight }) => {
const data = await readFile(`${__dirname}/${file}`);
return { name: 'Roboto', weight, data };
return { name: "Roboto", weight, data };
});
export async function jsxToSvg(
jsx: JSX.Element,
renderConfiguration = new RenderConfiguration(),
jsx: React.JSX.Element,
renderConfiguration = new RenderConfiguration()
) {
const fonts = await Promise.all(fontsPromise);
return await satori(jsx, { width: renderConfiguration.width, fonts });
@@ -6,14 +6,14 @@ import {
InteractionEditReplyOptions,
InteractionReplyOptions,
MessageEditOptions,
} from 'discord.js';
import { InteractionReturnable } from '../../events/interactionCreate';
import { Writeable } from '../../types/writable';
import { jsxToPngThreaded } from '../blitzkit/jsxToPngThreaded';
import { RenderConfiguration } from '../blitzkit/renderConfiguration';
} from "discord.js";
import { InteractionReturnable } from "../../events/interactionCreate";
import { Writeable } from "../../types/writable";
import { jsxToPngThreaded } from "../blitzkit/jsxToPngThreaded";
import { RenderConfiguration } from "../blitzkit/renderConfiguration";
export async function normalizeInteractionReturnable(
returnable: InteractionReturnable,
returnable: InteractionReturnable
) {
const images: [number, Buffer][] = [];
const reply: InteractionEditReplyOptions &
@@ -27,7 +27,7 @@ export async function normalizeInteractionReturnable(
await Promise.all(
normalizedReturnable.map(async (item, index) => {
if (typeof item === 'string') {
if (typeof item === "string") {
reply.content = item;
} else if (item instanceof EmbedBuilder) {
if (!reply.embeds) reply.embeds = [];
@@ -36,7 +36,7 @@ export async function normalizeInteractionReturnable(
if (!reply.components)
reply.components = [new ActionRowBuilder<ButtonBuilder>()];
(reply.components[0] as ActionRowBuilder<ButtonBuilder>).addComponents(
item,
item
);
} else if (item instanceof AttachmentBuilder) {
if (!reply.files) reply.files = [];
@@ -49,14 +49,14 @@ export async function normalizeInteractionReturnable(
const image = await jsxToPngThreaded(item, renderConfiguration);
images.push([index, image]);
}
}),
})
);
if (images.length > 0) {
images.sort(([a], [b]) => b - a);
if (!reply.files) reply.files = [];
images.forEach(([, image]) =>
(reply.files as Writeable<typeof reply.files>)?.push(image),
(reply.files as Writeable<typeof reply.files>)?.push(image)
);
}
@@ -1,7 +1,7 @@
import { DEFAULT_LOCALE, SupportedLocale } from '@blitzkit/i18n';
import { Locale } from 'discord.js';
import locales from "@blitzkit/i18n/locales.json";
import { Locale } from "discord.js";
const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
const SUPPORTED_LOCALES_DISCORD_MAP: Record<string, Locale> = {
en: Locale.EnglishUS,
es: Locale.SpanishES,
pt: Locale.PortugueseBR,
@@ -14,12 +14,12 @@ const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
};
export const SUPPORTED_LOCALES_DISCORD_MAP_INVERSE = Object.fromEntries(
Object.entries(SUPPORTED_LOCALES_DISCORD_MAP).map(([k, v]) => [v, k]),
) as Record<Locale, SupportedLocale>;
Object.entries(SUPPORTED_LOCALES_DISCORD_MAP).map(([k, v]) => [v, k])
) as Record<Locale, string>;
export const SUPPORTED_LOCALES_DISCORD = Object.values(
SUPPORTED_LOCALES_DISCORD_MAP,
SUPPORTED_LOCALES_DISCORD_MAP
);
export const DEFAULT_LOCALE_DISCORD =
SUPPORTED_LOCALES_DISCORD_MAP[DEFAULT_LOCALE];
SUPPORTED_LOCALES_DISCORD_MAP[locales.default];
@@ -1,4 +1,4 @@
import { assertSecret } from '@blitzkit/core';
import { assertSecret } from "@blitzkit/core";
import {
AttachmentBuilder,
AutocompleteInteraction,
@@ -13,30 +13,30 @@ import {
SlashCommandBuilder,
SlashCommandOptionsOnlyBuilder,
SlashCommandSubcommandsOnlyBuilder,
} from 'discord.js';
import { aboutCommand } from '../../commands/about';
import { breakdownCommand } from '../../commands/breakdown';
import { debugCommand } from '../../commands/debug';
import { evolutionCommand } from '../../commands/evolution';
import { fullStatsCommand } from '../../commands/fullStats';
import { inactiveCommand } from '../../commands/inactive';
import { verifyCommand } from '../../commands/link';
import { ownedTanksCommand } from '../../commands/ownedTanks';
import { permissionsCommand } from '../../commands/permissions';
import { pingCommand } from '../../commands/ping';
import { playerInfoCommand } from '../../commands/playerInfo';
import { ratingCommand } from '../../commands/rating';
import { ratingLeaderboardCommand } from '../../commands/ratingLeaderboard';
import { replayCommand } from '../../commands/replay';
import { researchCommand } from '../../commands/research';
import { searchClansCommand } from '../../commands/searchClans';
import { searchPlayersCommand } from '../../commands/searchPlayers';
import { statsCommand } from '../../commands/stats';
import { todayCommand } from '../../commands/today';
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
import { handleAutocomplete } from './handlers/autocomplete';
import { handleButton } from './handlers/button';
import { handleChatInputCommand } from './handlers/chatInputCommand';
} from "discord.js";
import { aboutCommand } from "../../commands/about";
import { breakdownCommand } from "../../commands/breakdown";
import { debugCommand } from "../../commands/debug";
import { evolutionCommand } from "../../commands/evolution";
import { fullStatsCommand } from "../../commands/fullStats";
import { inactiveCommand } from "../../commands/inactive";
import { verifyCommand } from "../../commands/link";
import { ownedTanksCommand } from "../../commands/ownedTanks";
import { permissionsCommand } from "../../commands/permissions";
import { pingCommand } from "../../commands/ping";
import { playerInfoCommand } from "../../commands/playerInfo";
import { ratingCommand } from "../../commands/rating";
import { ratingLeaderboardCommand } from "../../commands/ratingLeaderboard";
import { replayCommand } from "../../commands/replay";
import { researchCommand } from "../../commands/research";
import { searchClansCommand } from "../../commands/searchClans";
import { searchPlayersCommand } from "../../commands/searchPlayers";
import { statsCommand } from "../../commands/stats";
import { todayCommand } from "../../commands/today";
import { RenderConfiguration } from "../../core/blitzkit/renderConfiguration";
import { handleAutocomplete } from "./handlers/autocomplete";
import { handleButton } from "./handlers/button";
import { handleChatInputCommand } from "./handlers/chatInputCommand";
export type InteractionRawReturnable =
| string
@@ -44,7 +44,7 @@ export type InteractionRawReturnable =
| ButtonBuilder
| AttachmentBuilder
| RenderConfiguration
| JSX.Element
| React.JSX.Element
| null;
export type InteractionIterableReturnable =
| InteractionRawReturnable
@@ -58,7 +58,7 @@ interface CommandRegistryBase {
| SlashCommandBuilder
| SlashCommandSubcommandsOnlyBuilder
| SlashCommandOptionsOnlyBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
| Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
@@ -72,7 +72,7 @@ interface CommandRegistryImplicit extends CommandRegistryBase {
interface CommandRegistryExplicit extends CommandRegistryBase {
handlesInteraction?: false;
handler: (
interaction: ChatInputCommandInteraction<CacheType>,
interaction: ChatInputCommandInteraction<CacheType>
) => InteractionReturnable;
}
@@ -104,16 +104,16 @@ export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
return rawCommands.reduce<Record<string, CommandRegistry>>(
(commands, registry, index) => {
if (registry.status === 'rejected') {
if (registry.status === "rejected") {
console.warn(
`Command ${index} failed to load; skipping...`,
registry.reason,
registry.reason
);
return commands;
}
return { ...commands, [registry.value.command.name]: registry.value };
},
{},
{}
);
});
@@ -121,12 +121,12 @@ const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
commands.then((awaitedCommands) => {
const body = Object.values(awaitedCommands).map((registry) =>
registry.command.toJSON(),
registry.command.toJSON()
);
rest.put(
Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
{ body },
{ body }
);
});
File diff suppressed because it is too large. Load diff
+12 -15
View File
@@ -1,29 +1,26 @@
import {
DEFAULT_LOCALE,
SUPPORTED_LOCALES,
TranslationTree,
} from '@blitzkit/i18n';
import { writeFile } from 'fs/promises';
import { type TranslationTree } from "@blitzkit/i18n";
import locales from "@blitzkit/i18n/locales.json";
import { writeFile } from "fs/promises";
const ROOT = '@blitzkit/i18n/strings';
const WORKING_ROOT = '../../packages/i18n/strings';
const ROOT = "@blitzkit/i18n/strings";
const WORKING_ROOT = "../../packages/i18n/strings";
const defaultStrings = require(`${ROOT}/${DEFAULT_LOCALE}.json`).default;
const nonDefaultLocales = SUPPORTED_LOCALES.filter(
(locale) => locale !== DEFAULT_LOCALE,
const defaultStrings = require(`${ROOT}/${locales.default}.json`).default;
const nonDefaultLocales = locales.supported.filter(
({ locale }) => locale !== locales.default
);
function prune(defaultStrings: TranslationTree, strings: TranslationTree) {
for (const key in strings) {
if (key in defaultStrings) {
if (typeof defaultStrings[key] === typeof strings[key]) {
if (typeof strings[key] === 'string') {
if (typeof strings[key] === "string") {
if (
// are equivalent regardless of %s flavor
(defaultStrings[key] as string).replaceAll(/%s\d/g, '%s') ===
(strings[key] as string).replaceAll(/%s\d/g, '%s') ||
(defaultStrings[key] as string).replaceAll(/%s\d/g, "%s") ===
(strings[key] as string).replaceAll(/%s\d/g, "%s") ||
// string is empty
strings[key] === '' ||
strings[key] === "" ||
// string has old flavor of %s
strings[key].match(/%s([^\d]|$)/g) !== null
) {
@@ -1,7 +1,7 @@
import { CaretRightIcon } from '@radix-ui/react-icons';
import { Box, Flex, Link, Text } from '@radix-ui/themes';
import { Var } from '../../../core/radix/var';
import type { TankGuide } from '../../../pages/[...locale]/tanks/[slug]/index.astro';
import { CaretRightIcon } from "@radix-ui/react-icons";
import { Box, Flex, Link, Text } from "@radix-ui/themes";
import { Var } from "../../../core/radix/var";
import type { TankGuide } from "../../../pages/[...locale]/tanks/[slug]/index.astro";
interface Props {
guide: TankGuide;
@@ -16,10 +16,10 @@ export function GuideSection({ guide }: Props) {
underline="none"
highContrast
style={{
display: 'flex',
maxWidth: '35rem',
flexDirection: 'column',
gap: Var('space-4'),
display: "flex",
maxWidth: "35rem",
flexDirection: "column",
gap: Var("space-4"),
}}
>
<Flex maxWidth="35rem" direction="column" gap="4">
@@ -28,9 +28,9 @@ export function GuideSection({ guide }: Props) {
<Flex width="100%" justify="start" align="center" gap="2">
<img
style={{
width: '1.5em',
height: '1.5em',
objectFit: 'contain',
width: "1.5em",
height: "1.5em",
objectFit: "contain",
}}
src="https://guidesblitz.com/wp-content/uploads/2023/11/cropped-logo-1.png"
/>
@@ -39,7 +39,7 @@ export function GuideSection({ guide }: Props) {
</Text>
<Text size="2">{guide.description}</Text>
<img style={{ width: '100%' }} src={guide.image} />
<img style={{ width: "100%" }} src={guide.image} />
<Box
position="absolute"
@@ -48,7 +48,7 @@ export function GuideSection({ guide }: Props) {
height="100%"
left="0"
style={{
background: `linear-gradient(${Var('gray-a1')}, ${Var('gray-1')})`,
background: `linear-gradient(${Var("gray-a1")}, ${Var("gray-1")})`,
}}
/>
</Flex>