From c42aa597a97839a6bfc005151ac97d7ecf921a39 Mon Sep 17 00:00:00 2001 From: GardZock Date: Sun, 20 Feb 2022 19:15:41 -0300 Subject: [PATCH] User, Clan, Tank ADD --- .../src/functions/clan.ts | 26 +++++++++ .../src/functions/tank.ts | 21 ++++++++ .../src/functions/user.ts | 47 ++++++++++++++++ .../src/interfaces/clan/clan-resolve.ts | 31 +++++++++++ .../src/interfaces/tank/tank-resolve.ts | 21 ++++++++ .../src/interfaces/tank/tank-top.ts | 33 ++++++++++++ .../src/interfaces/user/user-return.ts | 53 +++++++++++++++++++ 7 files changed, 232 insertions(+) create mode 100644 packages/wargaming/world-of-tanks-blitz/src/functions/clan.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/functions/tank.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/functions/user.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/interfaces/clan/clan-resolve.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-resolve.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-top.ts create mode 100644 packages/wargaming/world-of-tanks-blitz/src/interfaces/user/user-return.ts diff --git a/packages/wargaming/world-of-tanks-blitz/src/functions/clan.ts b/packages/wargaming/world-of-tanks-blitz/src/functions/clan.ts new file mode 100644 index 0000000..52564c6 --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/functions/clan.ts @@ -0,0 +1,26 @@ +import { BaseClass } from "../../../../../builds/class/base"; +import axios from "axios"; +import { WOTBClanResolve } from '../interfaces/clan/clan-resolve' + +class WOTBClan extends BaseClass { + + app: { id: string } + constructor(app_id: string) { + super(app_id) + this.app = { id: app_id } + } + + public async get(clanID: string | number): Promise { + let data = await (await axios.get(`https://api.wotblitz.com/wotb/clans/info/?application_id=${this.app.id}&clan_id=${clanID}`)).data + if (data.status == "error") return null + return data.data[clanID] + } + + public async search(clanNameOrTag: string): Promise { + let data = await (await axios.get(`https://api.wotblitz.com/wotb/clans/list/?application_id=${this.app.id}&search=${clanNameOrTag}`)).data + if (data.status == "error" || data.data.length <= 0) return null + return data.data + } +} + +export { WOTBClan } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/functions/tank.ts b/packages/wargaming/world-of-tanks-blitz/src/functions/tank.ts new file mode 100644 index 0000000..3ce6d6d --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/functions/tank.ts @@ -0,0 +1,21 @@ +import { BaseClass } from "../../../../../builds/class/base"; +import axios from "axios"; +import { WOTBTankResolve } from '../interfaces/tank/tank-resolve' + +class WOTBTank extends BaseClass { + + app: { id: string } + constructor(app_id: string) { + super(app_id) + this.app = { id: app_id } + } + + public async get(tankID: string | number): Promise { + var data = await (await axios.get(`https://api.wotblitz.com/wotb/encyclopedia/vehicles/?application_id=${this.app.id}&tank_id=${tankID}`)).data + if (data.status == "error") return null + + return data.data[tankID] + } +} + +export { WOTBTank } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/functions/user.ts b/packages/wargaming/world-of-tanks-blitz/src/functions/user.ts new file mode 100644 index 0000000..023c76e --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/functions/user.ts @@ -0,0 +1,47 @@ +import { BaseClass } from "../../../../../builds/class/base"; +import axios from "axios"; +import { WOTBUserResolve } from '../interfaces/user/user-return'; +import { UserSearchResolve } from '../../../build/interfaces/search-resolve'; +import { WOTBTankTop } from '../interfaces/tank/tank-top' + +class WOTBUser extends BaseClass { + + app: { id: string } + constructor(app_id: string) { + super(app_id) + this.app = { id: app_id } + } + + + public async get(userID: string | number): Promise { + let data = await (await axios.get(`https://api.wotblitz.com/wotb/account/info/?application_id=${this.app.id}&account_id=${userID}`)).data + if (data.status == "error") return null + data = data.data[userID] + return { + statistics: { + clan: data.statistics.clan, + all: data.statistics.all + }, + account_id: data.account_id, + created_at: data.created_at, + last_battle_time: data.last_battle_time, + nickname: data.nickname + } + } + + public async search(userName: string): Promise { + let data = await (await axios.get(`https://api.wotblitz.com/wotb/account/list/?application_id=${this.app.id}&search=${userName}`)).data + if (data.status == "error" || data.data.length <= 0) return null + return data.data + } + + public async topTanks(userID: string | number): Promise { + let data = await (await axios.get(`https://api.wotblitz.com/wotb/tanks/stats/?application_id=${this.app.id}&account_id=${userID}`)).data + if (data.status == "error" || data.data.length <= 0) return null + data = data.data[userID] + data.length = 5 + return data + } +} + +export { WOTBUser } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/interfaces/clan/clan-resolve.ts b/packages/wargaming/world-of-tanks-blitz/src/interfaces/clan/clan-resolve.ts new file mode 100644 index 0000000..621693f --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/interfaces/clan/clan-resolve.ts @@ -0,0 +1,31 @@ +interface WOTBClanResolve { + + recruiting_options: { + vehicles_level: number | null, + wins_ratio: number | null, + average_battles_per_day: number | null, + battles: number | null, + average_damage: number | null + }, + members_count: number | null, + name: string | null, + creator_name: string | null, + clan_id: number | null, + created_at: number | null, + updated_at: number | null, + leader_name: string | null, + members_ids: number[], + recruiting_policy: string | null, + tag: string | null, + is_clan_disbanded: boolean, + old_name: string | null, + emblem_set_id: number | null, + creator_id: number | null, + motto: string | null, + renamed_at: number | null, + old_tag: string | null, + leader_id: number | null, + description: string | null +} + +export { WOTBClanResolve } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-resolve.ts b/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-resolve.ts new file mode 100644 index 0000000..c67ec38 --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-resolve.ts @@ -0,0 +1,21 @@ +interface WOTBTankResolve { + suspensions: number[] | null, + description: string | null, + engines: number[] | null, + prices_xp: number | null, + next_tanks: any | null, + modules_tree: any, + nation: string | null, + is_premium: boolean, + images: any | null, + cost: number | null, + default_profile: any | null, + tier: number | null, + tank_id: number | null, + type: string | null, + guns: number[], + turrets: number[], + name: string | null +} + +export { WOTBTankResolve } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-top.ts b/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-top.ts new file mode 100644 index 0000000..12cba35 --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/interfaces/tank/tank-top.ts @@ -0,0 +1,33 @@ +interface WOTBTankTop { + + all: { + spotted: number | null, + hits: number | null, + frags: number | null, + max_xp: number | null, + wins: number | null, + losses: number | null, + capture_points: number | null, + battles: number | null, + damage_dealt: number | null, + damage_received: number | null, + max_frags: number | null, + shots: number | null, + frags8p: number | null, + xp: number | null, + win_and_survived: number | null, + survived_battles: number | null, + dropped_capture_points: number | null + }, + last_battle_time: number | null, + account_id: number | null, + max_xp: number | null, + in_garage_updated: number | null, + max_frags: number | null, + mark_of_mastery: number | null, + battle_life_time: number | null, + in_garage: number | null, + tank_id: number | null +} + +export { WOTBTankTop } \ No newline at end of file diff --git a/packages/wargaming/world-of-tanks-blitz/src/interfaces/user/user-return.ts b/packages/wargaming/world-of-tanks-blitz/src/interfaces/user/user-return.ts new file mode 100644 index 0000000..75a1b66 --- /dev/null +++ b/packages/wargaming/world-of-tanks-blitz/src/interfaces/user/user-return.ts @@ -0,0 +1,53 @@ +interface WOTBUserResolve { + + last_battle_time: number | null, + account_id: number | null, + created_at: number | null, + statistics: { + clan: { + spotted: number | null, + max_frags_tank_id: number | null, + hits: number | null, + frags: number | null, + max_xp: number | null, + max_xp_tank_id: number | null, + wins: number | null, + losses: number | null, + capture_points: number | null, + battles: number | null, + damage_dealt: number | null, + damage_received: number | null, + max_frags: number | null, + shots: number | null, + frags8p: number | null, + xp: number | null, + win_and_survived: number | null, + survived_battles: number | null, + dropped_capture_points: number | null + }, + all: { + spotted: number | null, + max_frags_tank_id: number | null, + hits: number | null, + frags: number | null, + max_xp: number | null, + max_xp_tank_id: number | null, + wins: number | null, + losses: number | null, + capture_points: number | null, + battles: number | null, + damage_dealt: number | null, + damage_received: number | null, + max_frags: number | null, + shots: number | null, + frags8p: number | null, + xp: number | null, + win_and_survived: number | null, + survived_battles: number | null, + dropped_capture_points: number | null + } + }, + nickname: string | null +} + +export { WOTBUserResolve } \ No newline at end of file