mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: express responses
This commit is contained in:
1 parent
0f46f333b5
commit
f2ae698438
45 files changed
+153
-93
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import errorWithCause from '../node/errorWithCause.js';
|
||||
import { serverAndIdPattern } from '../options/resolvePlayer.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import listClansPanServer from './listClansPanServer.js';
|
||||
|
||||
export default async function getBlitzClan(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
||||
import { TanksStats } from '../../types/tanksStats.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||
import errorWithCause from '../node/errorWithCause.js';
|
||||
import getWargamingResponse from './getWargamingResponse.js';
|
||||
|
||||
export default async function getTankStats(server: BlitzServer, id: number) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import errorWithCause from '../node/errorWithCause.js';
|
||||
|
||||
export default async function getWargamingResponse<Data extends object>(
|
||||
url: string,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { Account, AccountList } from '../../types/accountList.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||
import getWargamingResponse from './getWargamingResponse.js';
|
||||
|
||||
export type AccountListWithServer = (Account & {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { Clan, ClanList } from '../../types/clanList.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||
import getWargamingResponse from './getWargamingResponse.js';
|
||||
|
||||
export type ClanListWithServer = (Clan & {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { go } from 'fuzzysort';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import errorWithCause from '../node/errorWithCause.js';
|
||||
import { TANKS, tankopedia } from './tankopedia.js';
|
||||
|
||||
export default function resolveTankId(tank: string) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
getHistoriesDefaultOptions,
|
||||
} from '../../types/histories.js';
|
||||
import getWargamingResponse from '../blitz/getWargamingResponse.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||
import { emptyAllStats } from './getTankStatsOverTime.js';
|
||||
|
||||
export interface PlayerHistoryRaw {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ResponderReturnable } from '../../server.js';
|
||||
import jsxToSvg from '../ui/jsxToSvg.js';
|
||||
|
||||
export default async function normalizeResponderReturnable(
|
||||
returnable: ResponderReturnable,
|
||||
) {
|
||||
const awaitedReturnable = await returnable;
|
||||
const svg = await jsxToSvg(awaitedReturnable);
|
||||
|
||||
return svg;
|
||||
}
|
||||
+17
-11
@@ -3,11 +3,12 @@ import {
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
} from 'discord.js';
|
||||
import { Request } from 'express';
|
||||
import { CYCLIC_API } from '../../constants/cyclic.js';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow.js';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart.js';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
|
||||
import { Period } from './addPeriodSubCommands.js';
|
||||
import { Period } from '../options/addPeriodSubCommands.js';
|
||||
|
||||
export const PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's statistics",
|
||||
@@ -34,10 +35,11 @@ export interface ResolvedPeriod {
|
||||
end: number;
|
||||
}
|
||||
|
||||
export default function resolvePeriod(
|
||||
interaction:
|
||||
export default function resolvePeriodFromCommand(
|
||||
input:
|
||||
| ChatInputCommandInteraction<CacheType>
|
||||
| ButtonInteraction<CacheType>,
|
||||
| ButtonInteraction<CacheType>
|
||||
| Request,
|
||||
) {
|
||||
let statsName: string;
|
||||
let evolutionName: string;
|
||||
@@ -46,22 +48,26 @@ export default function resolvePeriod(
|
||||
let url: URL;
|
||||
let period: Period;
|
||||
|
||||
if (interaction instanceof ChatInputCommandInteraction) {
|
||||
period = interaction.options.getSubcommand() as Period;
|
||||
if (input instanceof ChatInputCommandInteraction) {
|
||||
period = input.options.getSubcommand() as Period;
|
||||
} else {
|
||||
url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
||||
url = new URL(
|
||||
`${CYCLIC_API}${
|
||||
input instanceof ButtonInteraction ? `/${input.customId}` : input.path
|
||||
}`,
|
||||
);
|
||||
const path = url.pathname.split('/').filter(Boolean);
|
||||
period = path[path.length - 1] as Period;
|
||||
}
|
||||
|
||||
if (period === 'custom') {
|
||||
const startRaw =
|
||||
interaction instanceof ChatInputCommandInteraction
|
||||
? interaction.options.getInteger('start')!
|
||||
input instanceof ChatInputCommandInteraction
|
||||
? input.options.getInteger('start')!
|
||||
: parseInt(url!.searchParams.get('start')!);
|
||||
const endRaw =
|
||||
interaction instanceof ChatInputCommandInteraction
|
||||
? interaction.options.getInteger('end')!
|
||||
input instanceof ChatInputCommandInteraction
|
||||
? input.options.getInteger('end')!
|
||||
: parseInt(url!.searchParams.get('end')!);
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
const endMax = Math.max(startRaw, endRaw);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -2,7 +2,7 @@ import {
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { PERIOD_NAMES } from './resolvePeriod.js';
|
||||
import { PERIOD_NAMES } from '../interaction/resolvePeriodFromCommand.js';
|
||||
|
||||
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { BlitzServer } from '../../constants/servers.js';
|
||||
import listAccountsPanServer, {
|
||||
usernamePatternWithoutPosition,
|
||||
} from '../blitz/listAccountsPanServer.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import errorWithCause from '../node/errorWithCause.js';
|
||||
|
||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
|
||||
|
||||
Reference in new issue
Block a user