Files
blitzkit/src/commands/inactive.tsx
T

69 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-06-06 01:31:16 +00:00
import { SlashCommandBuilder } from 'discord.js';
2023-10-14 11:06:03 -05:00
import addClanChoices from '../LEGACY_core/discord/addClanChoices';
import autocompleteClan from '../LEGACY_core/discord/autocompleteClan';
import resolveClanFromCommand from '../LEGACY_core/discord/resolveClanFromCommand';
2023-07-11 19:54:57 +00:00
import GenericStats from '../components/GenericStats';
import NoData, { NoDataType } from '../components/NoData';
import TitleBar from '../components/TitleBar';
import Wrapper from '../components/Wrapper';
2023-10-14 11:06:03 -05:00
import { getAccountInfo } from '../core/blitz/getAccountInfo';
import { getClanInfo } from '../core/blitz/getClanInfo';
2023-07-11 19:54:57 +00:00
import { CommandRegistry } from '../events/interactionCreate';
2023-06-06 01:31:16 +00:00
const DEFAULT_THRESHOLD = 7;
2023-07-05 01:15:18 +00:00
export const inactiveCommand: CommandRegistry = {
2023-06-06 01:31:16 +00:00
inProduction: true,
inPublic: true,
command: new SlashCommandBuilder()
.setName('inactive')
2023-06-06 01:31:16 +00:00
.setDescription('Lists all inactive players')
.addStringOption(addClanChoices)
.addNumberOption((option) =>
option
.setName('threshold')
.setDescription(
`The number of days inactive (default: ${DEFAULT_THRESHOLD})`,
)
.setMinValue(0),
),
2023-06-27 01:43:30 +00:00
async handler(interaction) {
2023-09-07 03:24:07 +00:00
const { region, id } = await resolveClanFromCommand(interaction);
2023-06-06 01:31:16 +00:00
const threshold =
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
const time = new Date().getTime() / 1000;
2023-10-12 13:00:33 -05:00
const clanInfo = await getClanInfo(region, id);
const accountInfo = await getAccountInfo(region, clanInfo.members_ids);
const inactive = accountInfo
.map(
(account) =>
[
account.nickname,
(time - account.last_battle_time) / 60 / 60 / 24,
] as [string, number],
2023-06-06 01:31:16 +00:00
)
.filter(([, inactiveDays]) => inactiveDays >= threshold)
.sort((a, b) => b[1] - a[1])
.map(
([name, days]) => [name, `${days.toFixed(0)} days`] as [string, string],
);
const hasInactiveMembers = inactive.length > 0;
2023-06-16 02:01:06 +00:00
return (
2023-06-06 01:31:16 +00:00
<Wrapper>
<TitleBar
2023-10-12 13:00:33 -05:00
name={clanInfo.name}
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanInfo.emblem_set_id}.png`}
2023-08-07 22:54:55 +00:00
description={`Inactive for ${threshold}+ Days • ${new Date().toDateString()}`}
2023-06-06 01:31:16 +00:00
/>
2023-06-06 16:53:13 +00:00
{!hasInactiveMembers && <NoData type={NoDataType.PlayersInPeriod} />}
2023-06-06 01:31:16 +00:00
{hasInactiveMembers && <GenericStats stats={inactive} />}
2023-06-16 02:01:06 +00:00
</Wrapper>
2023-06-06 01:31:16 +00:00
);
},
2023-06-27 02:22:28 +00:00
autocomplete: autocompleteClan,
2023-07-05 01:15:18 +00:00
};