mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: code split a lot
This commit is contained in:
1 parent
78e4c82f20
commit
d2668974f7
18 files changed
+155
-133
No files matched your search
@@ -1,13 +1,43 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { ButtonInteraction } from 'discord.js';
|
||||
import { Region } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { PeriodType } from './addPeriodSubCommands';
|
||||
import {
|
||||
ResolvedPeriod,
|
||||
getPeriodOptionName,
|
||||
} from './resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromButton(
|
||||
server: Region,
|
||||
interaction: ButtonInteraction<CacheType>,
|
||||
region: Region,
|
||||
interaction: ButtonInteraction,
|
||||
) {
|
||||
return resolvePeriodFromURL(
|
||||
server,
|
||||
`https://example.com/${interaction.customId}`,
|
||||
);
|
||||
let name: string;
|
||||
let start: number;
|
||||
let end: number;
|
||||
const url = new URL(`https://example.com/${interaction.customId}`);
|
||||
const path = url.pathname.split('/');
|
||||
const periodSubcommand = path[2] as PeriodType;
|
||||
|
||||
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);
|
||||
|
||||
name = `${startDaysAgoMin} - ${endDaysAgoMax} days`;
|
||||
start = getTimeDaysAgo(region, endDaysAgoMax);
|
||||
end = getTimeDaysAgo(region, startDaysAgoMin);
|
||||
} else {
|
||||
name = getPeriodOptionName(periodSubcommand);
|
||||
start = getPeriodStart(region, periodSubcommand);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
start,
|
||||
end,
|
||||
} satisfies ResolvedPeriod;
|
||||
}
|
||||
Reference in new issue
Block a user