feat: player clan data typings

This commit is contained in:
TresAbhi committed 2023-04-24 00:50:40 +00:00
1 parent ab88be7c94
commit 3cd52b2688
8 files changed
+31 -18

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ try {
const data = (await rest.put(
Routes.applicationGuildCommands(getClientId(), discord.guild_id),
{ body: commands },
)) as { length: number };
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully reloaded ${data.length} command(s).`);
} catch (error) {
-2
View File
@@ -11,8 +11,6 @@ import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
export const inDev = true;
export const CLANS = {
sklld: {
name: 'Skilled',
+3 -5
View File
@@ -10,8 +10,6 @@ import { ClanDetails } from '../types/clanDetails.js';
import { PlayerPersonalData } from '../types/playerPersonalData.js';
import { CLANS } from './eligible.js';
export const inDev = true;
const DEFAULT_THRESHOLD = 7;
export async function execute(
@@ -28,7 +26,7 @@ export async function execute(
).json()) as ClanDetails;
const clan = clanData.data[CLANS[clanName].id];
const memberIds = clan.members_ids;
const accountInfo = (await (
const playerPersonalData = (await (
await fetch(
`https://api.wotblitz.com/wotb/account/info/?application_id=${
process.env.WARGAMING_APPLICATION_ID
@@ -38,10 +36,10 @@ export async function execute(
const inactiveInfo = memberIds
.map((memberId) => {
const member = accountInfo.data[memberId];
const member = playerPersonalData.data[memberId];
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
return [member.nickname, inactiveDays] as [string, number];
return [member.nickname, inactiveDays] as const;
})
.filter(([, inactiveDays]) => inactiveDays >= threshold)
.sort((a, b) => b[1] - a[1])
-2
View File
@@ -11,8 +11,6 @@ import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
export const inDev = true;
export async function execute(
interaction: ChatInputCommandInteraction<CacheType>,
) {
+3 -6
View File
@@ -8,10 +8,9 @@ import fetch from 'node-fetch';
import discord from '../../discord.json' assert { type: 'json' };
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
import { SERVERS } from '../constants/servers.js';
import { PlayerClanData } from '../types/playerClanData.js';
import getBlitzAccount from '../utilities/getBlitzAccount.js';
export const inDev = true;
export async function execute(
interaction: ChatInputCommandInteraction<CacheType>,
) {
@@ -24,11 +23,9 @@ export async function execute(
// good match
const clanData = (await fetch(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${account.account_id}&extra=clan`,
).then((response) => response.json())) as {
data: { [key: number]: { clan: { tag: string } | null } };
};
).then((response) => response.json())) as PlayerClanData;
const clan = clanData.data[account.account_id].clan;
const clanTag = clan === null ? '' : ` [${clan.tag}]`;
const clanTag = clan === null ? '' : ` [${clan!.tag}]`;
if (interaction.member && interaction.guild) {
const member = interaction.guild?.members.cache.get(
+1 -1
View File
@@ -2,7 +2,7 @@ import { WargamingResponse } from './wargamingResponse.js';
export interface ClanDetails extends WargamingResponse {
data: {
[key: number]: {
[accountId: number]: {
recruiting_options: {
vehicles_level: number;
wins_ratio: number;
+22
View File
@@ -0,0 +1,22 @@
import { WargamingResponse } from './wargamingResponse.js';
export interface PlayerClanData extends WargamingResponse {
data: {
[accountId: number]: {
account_id: number;
joined_at: number;
clan_id: number;
role: string;
account_name: string;
clan?: {
members_count: number;
name: string;
created_at: number;
tag: string;
clan_id: number;
emblem_set_id: number;
};
};
};
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { WargamingResponse } from './wargamingResponse.js';
export interface PlayerPersonalData extends WargamingResponse {
data: {
[key: number]: {
[accountId: number]: {
statistics: {
clan: {
spotted: number;