Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

World of WarPlanes #32

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions builds/class/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { AcceptedTypes, APIError, WarCordError } from "../../packages/warcord/functions/error"


class BaseClass {
error: (send: string | APIError, type: AcceptedTypes) => void
warn: (message: string, type: AcceptedTypes) => void
constructor(app_id: string) {
Object.defineProperty(this, 'id', { value: app_id })
this.error = new WarCordError().createError
this.warn = new WarCordError().createWarn
}
}

Expand Down
12 changes: 11 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { WOTTanksResolve } from './packages/wargaming/world-of-tanks/src/interfa
import { WOTTopTanksResolve } from './packages/wargaming/world-of-tanks/src/interfaces/tank/top-tanks'
import { WOTUserResolve } from './packages/wargaming/world-of-tanks/src/interfaces/user/user-return'
import { UserSearchResolve } from './packages/wargaming/build/interfaces/search-resolve'
import { WOWPPlayer } from './packages/wargaming/world-of-warplanes/src/functions/player'
import { WOWPAirCraft } from './packages/wargaming/world-of-warplanes/src/functions/aircraft'

export declare type AllRealms = | 'na' | 'eu' | 'ru' | 'asia'

Expand Down Expand Up @@ -54,10 +56,14 @@ export class WarCord extends BaseClass {
clan: WOTCClan,
pedia: WOTCTankopedia
}
wowp: {
player: WOWPPlayer,
planes: WOWPAirCraft
}

/**
* @param {string} app_id The ID of your WarGaming App.
* @param {string} [realm=na] Location language. Not valid for World of Tanks Console (WOTC).
* @param {string} [realm="na"] Location language. Not valid for World of Tanks Console (WOTC).
*/
constructor(app_id: string, realm?: AllRealms) {
super(app_id)
Expand All @@ -83,6 +89,10 @@ export class WarCord extends BaseClass {
clan: new WOTCClan(this.app.id),
pedia: new WOTCTankopedia(this.app.id)
}
this.wowp = {
player: new WOWPPlayer(this.app.id),
planes: new WOWPAirCraft(this.app.id)
}
}

private idChecker(id: string): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/warcord/functions/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { emitWarning } from "process"

type AcceptedTypes = "WARCORD" | "API"
export type AcceptedTypes = "WARCORD" | "API"

interface APIError {
export interface APIError {
field: string,
message: string,
code: number,
Expand Down
10 changes: 5 additions & 5 deletions packages/wargaming/world-of-tanks/src/functions/clan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class WOTClan extends BaseClass {
* @returns {Promise<WOTClanResolve | null>} Clan data.
* @example
* ...
* const clan = await <Warcord>.wg.wot.clan.get('ID of Clan')
* const clan = await <Warcord>.wot.clan.get('ID of Clan')
*/

public async get(clanID: number | string, options?: { realm?: AllRealms }): Promise<WOTClanResolve | null> {
Expand Down Expand Up @@ -64,10 +64,10 @@ class WOTClan extends BaseClass {
* @returns {Promise<WOTClanSearchResolve[] | null>} Array with clan data.
* @example
* ...
* const searchingClan = await <Warcord>.wg.wot.clan.search('Name or Tag of Clan')
* const searchingClan = await <Warcord>.wot.clan.search('Name or Tag of Clan')
* //this returns an array of the clans found.
*
* const clan = await <Warcord>.wg.wot.clan.get(searchingClan[0].clan_id)
* const clan = await <Warcord>.wot.clan.get(searchingClan[0].clan_id)
* //this returns the first clan data.
*/
public async search(clanNameOrTag: string, options?: { realm?: AllRealms }): Promise<WOTClanSearchResolve[] | null> {
Expand All @@ -89,7 +89,7 @@ class WOTClan extends BaseClass {
* @returns {Object} Clan rating.
* @example
* ...
* const ratingOfClan = await <Warcord>.wg.wot.clan.rating('ID of Clan')
* const ratingOfClan = await <Warcord>.wot.clan.rating('ID of Clan')
*/
public async rating(clanID: string | number, options?: { realm?: AllRealms }): Promise<any | null> {

Expand All @@ -108,7 +108,7 @@ class WOTClan extends BaseClass {
* @property {AllRealms} options.realm The realm of query.
* @returns {Promise<WOTMember | null>} Clan Member data.
* @example
* const memberOfClan = await <Warcord>.wg.wot.clan.member('ID of Member')
* const memberOfClan = await <Warcord>.wot.clan.member('ID of Member')
*/
public async member(memberID: string | number, options?: { realm?: AllRealms }): Promise<WOTMember | null> {

Expand Down
2 changes: 1 addition & 1 deletion packages/wargaming/world-of-tanks/src/functions/tank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class WOTTankopedia extends BaseClass {
* @returns {Promise<WOTTanksResolve | null>} Object with Tank Data.
* @example
* ...
* const tank = await warcord.wot.tank.get('ID of Tank')
* const tank = await <WarCord>.wot.tank.get('ID of Tank')
*/

public async get(tankID: number | string, options?: { realm?: AllRealms }): Promise<WOTTanksResolve | null> {
Expand Down
8 changes: 4 additions & 4 deletions packages/wargaming/world-of-tanks/src/functions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class WOTUser extends BaseClass {
* @returns {Promise<UserSearchResolve[] | null>} Object Array with users data.
* @example
* ...
* const searchingUser = await <Warcord>.wg.wot.user.search('Wargaming NickName of User')
* const searchingUser = await <Warcord>.wot.user.search('Wargaming NickName of User')
* //this returns an array of the users found.
*
* const user = await <Warcord>.wg.wot.user.get(searchingUser[0].id)
* const user = await <Warcord>.wot.user.get(searchingUser[0].id)
* //this returns the first user data.
*/

Expand All @@ -45,7 +45,7 @@ class WOTUser extends BaseClass {
* @returns {Promise<WOTUserResolve | null>} Object of user data.
* @example
* ...
* const user = await <Warcord>.wg.wot.user.get('Wargaming ID of User')
* const user = await <Warcord>.wot.user.get('Wargaming ID of User')
*/

public async get(userID: number | string, options?: { realm?: AllRealms }): Promise<WOTUserResolve | null> {
Expand All @@ -67,7 +67,7 @@ class WOTUser extends BaseClass {
* @returns {Promise<WOTTopTanksResolve[] | null>} Object Array with tanks data.
* @example
* ...
* const topTanks = await <Warcord>.wg.wot.user.topTanks('Wargaming ID of User')
* const topTanks = await <Warcord>.wot.user.topTanks('Wargaming ID of User')
*/
public async topTanks(userID: number | string, options?: { realm?: AllRealms }): Promise<WOTTopTanksResolve[] | null> {

Expand Down
57 changes: 57 additions & 0 deletions packages/wargaming/world-of-warplanes/src/functions/aircraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { BaseClass } from "../../../../../builds/class/base";
import axios from "axios";
import { AllRealms } from "../../../../..";
import { AllLangs } from "../interfaces/types";
import { AirCraft } from "../interfaces/aircraft";

export class WOWPAirCraft extends BaseClass {

private app: { id: string, realm?: AllRealms | "com" }
private langs: string[]
constructor(app_id: string, realm?: AllRealms) {
super(app_id)
this.app = { id: app_id, realm: ["ru", "eu", "na"].includes(realm as string) ? realm : "com" }
this.langs = [ "en", "ru", "pl", "de", "fr", "es", "zh-cn", "tr", "cs", "th", "vi", "ko"]
}


/**
* @name statistics
* @description Get the Statistics on Player's aircraft.
* @param {string} playerId Player account ID.
* @param {Object?} options Options Object.
* @param {AllLangs?} [options.lang="en"] Localization language.
* @param {string?} options.plane_id Aircraft ID.
*/
public async stats(playerId: string, options?: { lang?: AllLangs, plane_id?: string }): Promise<AirCraft[] | null | void> {

if (!playerId) return this.error('Invalid Player ID.', 'WARCORD')

let option = ''
if (options) {

let { lang, plane_id } = options

if (lang) {
if (!this.langs.includes(lang)) return this.error('Invalid Language.', 'WARCORD')
option += `&language=${lang}`
}

if (plane_id) {
option += `&plane_id=${plane_id}`
}
}

let data;
try {
data = (await axios.get(`https://api.worldofwarplanes.${this.app.realm}/wowp/planes/stats/?application_id=${this.app.id}&account_id=${playerId}${option}`)).data
} catch(err: any) {
if (data) return this.error(`ERROR: ${err}\n\nDATA FOUND: ${data}`, 'WARCORD');
console.error(err)
data = undefined;
}

if (data && data.status == "error") return this.error(data, 'API')
return data.data[playerId] as AirCraft[];
}
}
96 changes: 96 additions & 0 deletions packages/wargaming/world-of-warplanes/src/functions/player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { BaseClass } from "../../../../../builds/class/base";
import axios from "axios";
import { AllRealms } from "../../../../..";
import { AllLangs, AllTypes } from "../interfaces/types";
import { FindPlayer, GetPlayer } from "../interfaces/player";

export class WOWPPlayer extends BaseClass {

private app: { id: string, realm?: AllRealms | "com" }
private langs: string[]
constructor(app_id: string, realm?: AllRealms) {
super(app_id)
this.app = { id: app_id, realm: ["ru", "eu", "na"].includes(realm as string) ? realm : "com" }
this.langs = [ "en", "ru", "pl", "de", "fr", "es", "zh-cn", "tr", "cs", "th", "vi", "ko"]
}


/**
* @name find
* @description Used to search a Player by name.
* @param {String} name Name of Player.
* @param {Object} options Options Object.
* @param {AllLangs | String} [options.lang="en"] Language of return.
* @param {Number} options.limit Limit of Search Query.
* @param {AllTypes | String } [options.type="startswith"] Type of Search.
* @return {Promise<any>} Return a Map of Match Players.
*/
public async find(name: string, options?: { lang?: AllLangs, limit?: number, type?: AllTypes }): Promise<FindPlayer[] | null | void> {

if (!name) return this.error('You need to put a name!', 'WARCORD');

let option = '';

if (options) {

let { lang, limit, type } = options


if (lang && !this.langs.includes(lang)) return this.error('Invalid Language.', 'WARCORD')
if (limit && (limit > 100 || limit < 0)) return this.error('Invalid Limit.', 'WARCORD')
if (type && !["startswith", "exact"].includes(type)) return this.error('Invalid Type.', 'WARCORD')

lang ? option += `&language=${lang}` : ''
limit ? option += `&limit=${limit}` : ''
type ? option += `&type=${type}` : ''
}

let data
try {
data = (await axios.get(`https://api.worldofwarplanes.${this.app.realm}/wowp/account/list/?application_id=${this.app.id}&search=${name}${option}`)).data
} catch(err: any) {
if (data) return this.error(`ERROR: ${err}\n\nDATA FOUND: ${data}`, 'WARCORD');
console.error(err)
data = null;
}
if (data && data.status == "error") return this.error(data, 'API')
return data.data as FindPlayer[];
}


/**
* @name get
* @description Get a Player by ID.
* @param {String} playerId Player account ID.
* @param {Object?} options Options Object.
* @param {AllLangs?} [options.lang="en"] Localization language.
*/
public async get(playerId: string, options?: { lang?: AllLangs }): Promise<GetPlayer | void | undefined> {

if (!playerId) return this.error('Invalid Player ID.', 'WARCORD')

let option = ''
if (options) {

let { lang } = options

if (lang) {
if (!this.langs.includes(lang)) return this.error('Invalid Language.', 'WARCORD')
option += `&language=${lang}`
}
}

let data;
try {
data = (await axios.get(`https://api.worldofwarplanes.${this.app.realm}/wowp/account/info2/?application_id=${this.app.id}&account_id=${playerId}${option}`)).data
} catch(err: any) {
if (data) return this.error(`ERROR: ${err}\n\nDATA FOUND: ${data}`, 'WARCORD');
console.error(err)
data = undefined;
}

if (data && data.status == "error") return this.error(data, 'API')
return data?.data ? data.data[playerId] : undefined
}

}
68 changes: 68 additions & 0 deletions packages/wargaming/world-of-warplanes/src/interfaces/aircraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export interface AirCraft {
all: {
avg_xp: number | null,
bombers: {
damage_dealt: number | null,
assisted: number | null,
max_killed: number | null,
max_damage_dealt: number | null,
killed: number | null
},
draws: number | null,
ground_objects: {
avg_killed: number | null,
avg_damage_dealt_per_flight: number | null,
avg_killed_per_flight: number | null,
assisted: number | null,
max_killed: number | null,
max_killed_per_flight: number | null,
killed: number | null,
damage_dealt: number | null,
max_damage_dealt: number | null
},
deaths: number | null,
chosen: number | null,
wins: number | null,
losses: number | null,
battle_score: number | null,
battles: number | null,
zone_captures: number | null,
players: {
avg_killed: number | null,
max_killed_in_defence: number | null,
assisted: number | null,
max_killed: number | null,
killed: number | null,
damage_dealt: number | null,
max_damage_dealt: number | null,
killed_in_defence: number | null
},
flights: number | null,
defenders_and_bombers: {
avg_killed: number | null,
max_killed: number | null,
max_damage_dealt: number | null
},
avg_battle_score: number | null,
defenders: {
damage_dealt: number | null,
assisted: number | null,
max_killed: number | null,
max_damage_dealt: number | null,
killed: number | null
},
avg_flight_time: number | null,
max_battles_score: number | null,
flight_time: number | null,
air_targets: {
avg_killed_per_flight: number | null,
avg_damage_dealt_per_flight: number | null,
max_damage_dealt: number | null,
max_killed_per_flight: number | null
},
chosen_first: number | null
},
account_id: number,
plane_id: number,
updated_at: number | null
}
Loading