mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: removed server
This commit is contained in:
1 parent
eb24f49766
commit
38f912dc0a
17 files changed
+14
-181
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import { Region } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from '../express/resolvePeriodFromURL';
|
||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
||||
|
||||
export default function resolvePeriodFromButton(
|
||||
server: Region,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { PeriodSize, PeriodType } from './addPeriodSubCommands';
|
||||
import {
|
||||
ResolvedPeriod,
|
||||
getPeriodOptionName,
|
||||
} from './resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromURL(
|
||||
server: Region,
|
||||
urlString: string,
|
||||
) {
|
||||
let statsName: string;
|
||||
let evolutionName: string;
|
||||
let start: number;
|
||||
let end: number;
|
||||
const url = new URL(urlString);
|
||||
const path = url.pathname.split('/').filter(Boolean);
|
||||
const periodSubcommand = path[path.length - 1] as PeriodType;
|
||||
const periodOption = url.searchParams.get('period') as PeriodSize;
|
||||
|
||||
if (periodSubcommand === 'custom') {
|
||||
const startRaw = parseInt(url!.searchParams.get('start')!);
|
||||
const endRaw = parseInt(url!.searchParams.get('end')!);
|
||||
const startDaysAgoMin = Math.min(startRaw, endRaw);
|
||||
const endDaysAgoMax = Math.max(startRaw, endRaw);
|
||||
|
||||
statsName = `${startDaysAgoMin} to ${endDaysAgoMax} days' statistics`;
|
||||
evolutionName = `${startDaysAgoMin} to ${endDaysAgoMax} days' evolution`;
|
||||
start = getTimeDaysAgo(server, endDaysAgoMax);
|
||||
end = getTimeDaysAgo(server, startDaysAgoMin);
|
||||
} else {
|
||||
statsName = `${getPeriodOptionName(periodOption)} Statistics`;
|
||||
evolutionName = `${getPeriodOptionName(periodOption)} Evolution`;
|
||||
start = getPeriodStart(server, periodOption);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
return { statsName, evolutionName, start, end } satisfies ResolvedPeriod;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import resolvePlayerFromURL from '../express/resolvePlayerFromURL';
|
||||
import resolvePlayerFromURL from './resolvePlayerFromURL';
|
||||
|
||||
export default async function resolvePlayerFromButton(
|
||||
interaction: ButtonInteraction<CacheType>,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { ResolvedPlayer } from '../discord/resolvePlayerFromCommand';
|
||||
|
||||
export default function resolvePlayerFromURL(urlString: string) {
|
||||
const url = new URL(urlString);
|
||||
|
||||
return {
|
||||
id: parseInt(url.searchParams.get('id')!),
|
||||
region: url.searchParams.get('region') as Region,
|
||||
} satisfies ResolvedPlayer;
|
||||
}
|
||||
Reference in new issue
Block a user