mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 19:49:50 +01:00
feat: better typing
This commit is contained in:
1 parent
774d6dc9f5
commit
ab88be7c94
10 files changed
+39
-24
No files matched your search
@@ -11,6 +11,8 @@ import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
|||||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||||
|
|
||||||
|
export const inDev = true;
|
||||||
|
|
||||||
export const CLANS = {
|
export const CLANS = {
|
||||||
sklld: {
|
sklld: {
|
||||||
name: 'Skilled',
|
name: 'Skilled',
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { ClanDetails } from '../types/clanDetails.js';
|
||||||
import { ClanInfo } from '../types/clanInfo.js';
|
import { PlayerPersonalData } from '../types/playerPersonalData.js';
|
||||||
import { CLANS } from './eligible.js';
|
import { CLANS } from './eligible.js';
|
||||||
|
|
||||||
const DEFAULT_THRESHOLD = 7;
|
|
||||||
|
|
||||||
export const inDev = true;
|
export const inDev = true;
|
||||||
|
|
||||||
|
const DEFAULT_THRESHOLD = 7;
|
||||||
|
|
||||||
export async function execute(
|
export async function execute(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
) {
|
) {
|
||||||
@@ -25,7 +25,7 @@ export async function execute(
|
|||||||
await fetch(
|
await fetch(
|
||||||
`https://api.wotblitz.com/wotb/clans/info/?application_id=${process.env.WARGAMING_APPLICATION_ID}&clan_id=${CLANS[clanName].id}`,
|
`https://api.wotblitz.com/wotb/clans/info/?application_id=${process.env.WARGAMING_APPLICATION_ID}&clan_id=${CLANS[clanName].id}`,
|
||||||
)
|
)
|
||||||
).json()) as ClanInfo;
|
).json()) as ClanDetails;
|
||||||
const clan = clanData.data[CLANS[clanName].id];
|
const clan = clanData.data[CLANS[clanName].id];
|
||||||
const memberIds = clan.members_ids;
|
const memberIds = clan.members_ids;
|
||||||
const accountInfo = (await (
|
const accountInfo = (await (
|
||||||
@@ -34,7 +34,7 @@ export async function execute(
|
|||||||
process.env.WARGAMING_APPLICATION_ID
|
process.env.WARGAMING_APPLICATION_ID
|
||||||
}&account_id=${memberIds.join(',')}`,
|
}&account_id=${memberIds.join(',')}`,
|
||||||
)
|
)
|
||||||
).json()) as AccountInfo;
|
).json()) as PlayerPersonalData;
|
||||||
|
|
||||||
const inactiveInfo = memberIds
|
const inactiveInfo = memberIds
|
||||||
.map((memberId) => {
|
.map((memberId) => {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
|||||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||||
|
|
||||||
|
export const inDev = true;
|
||||||
|
|
||||||
export async function execute(
|
export async function execute(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
|||||||
import { SERVERS } from '../constants/servers.js';
|
import { SERVERS } from '../constants/servers.js';
|
||||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
|
|
||||||
|
export const inDev = true;
|
||||||
|
|
||||||
export async function execute(
|
export async function execute(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
export interface Account {
|
|
||||||
nickname: string;
|
|
||||||
account_id: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
type AccountList =
|
|
||||||
| {
|
|
||||||
data?: Account[];
|
|
||||||
}
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
export default AccountList;
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
export interface ClanInfo {
|
import { WargamingResponse } from './wargamingResponse.js';
|
||||||
|
|
||||||
|
export interface ClanDetails extends WargamingResponse {
|
||||||
data: {
|
data: {
|
||||||
[key: number]: {
|
[key: number]: {
|
||||||
recruiting_options: {
|
recruiting_options: {
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
export interface AccountInfo {
|
import { WargamingResponse } from './wargamingResponse.js';
|
||||||
|
|
||||||
|
export interface PlayerPersonalData extends WargamingResponse {
|
||||||
data: {
|
data: {
|
||||||
[key: number]: {
|
[key: number]: {
|
||||||
statistics: {
|
statistics: {
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { WargamingResponse } from './wargamingResponse.js';
|
||||||
|
|
||||||
|
export interface Player {
|
||||||
|
nickname: string;
|
||||||
|
account_id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Players extends WargamingResponse {
|
||||||
|
data: Player[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export interface WargamingResponse {
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
@@ -6,20 +6,24 @@ import {
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||||
import { SERVERS } from '../constants/servers.js';
|
import { SERVERS } from '../constants/servers.js';
|
||||||
import AccountList, { Account } from '../types/accountList.js';
|
import { Player, Players } from '../types/players.js';
|
||||||
|
|
||||||
export default async function getBlitzAccount(
|
export default async function getBlitzAccount(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
ign: string,
|
ign: string,
|
||||||
server: keyof typeof SERVERS,
|
server: keyof typeof SERVERS,
|
||||||
callback: (account: Account) => void,
|
callback: (account: Player) => void,
|
||||||
) {
|
) {
|
||||||
const serverName = SERVERS[server];
|
const serverName = SERVERS[server];
|
||||||
const players = (await fetch(
|
const players = (await fetch(
|
||||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`,
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`,
|
||||||
).then((response) => response.json())) as AccountList;
|
).then((response) => response.json())) as Players;
|
||||||
|
|
||||||
if (players?.data && players.data[0]?.nickname === ign) {
|
if (
|
||||||
|
players.status === 'ok' &&
|
||||||
|
players.data.length > 0 &&
|
||||||
|
players.data[0].nickname === ign
|
||||||
|
) {
|
||||||
callback(players.data[0]);
|
callback(players.data[0]);
|
||||||
} else {
|
} else {
|
||||||
// no exact match
|
// no exact match
|
||||||
|
|||||||
Reference in new issue
Block a user