clashofclans.js 2.8.1 → 3.0.0-dev.392ca4c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/Client.d.ts +3 -72
- package/dist/client/Client.js +7 -12
- package/dist/client/EventManager.d.ts +18 -18
- package/dist/client/EventManager.js +55 -55
- package/dist/client/PollingClient.d.ts +83 -0
- package/dist/client/PollingClient.js +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +23 -22
- package/dist/rest/RequestHandler.js +5 -5
- package/dist/struct/ClanMember.js +1 -1
- package/dist/struct/ClanWar.js +1 -1
- package/dist/struct/League.js +1 -1
- package/dist/struct/Player.js +11 -11
- package/dist/struct/Ranking.js +1 -1
- package/dist/struct/Unit.js +4 -4
- package/dist/struct/WarLeague.js +1 -1
- package/dist/util/Constants.d.ts +37 -37
- package/dist/util/Constants.js +39 -39
- package/dist/util/Util.js +2 -2
- package/package.json +1 -1
package/dist/client/Client.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
|
|
3
|
-
import {
|
|
3
|
+
import { CWLRounds } from '../util/Constants';
|
|
4
4
|
import { RESTManager } from '../rest/RESTManager';
|
|
5
|
-
import { EventManager } from './EventManager';
|
|
6
5
|
import { EventEmitter } from 'events';
|
|
7
6
|
import { Util } from '../util/Util';
|
|
8
7
|
import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, SeasonRankedPlayer, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
|
|
@@ -14,15 +13,11 @@ import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLea
|
|
|
14
13
|
* ```
|
|
15
14
|
*/
|
|
16
15
|
export declare class Client extends EventEmitter {
|
|
17
|
-
/** Event Manager for the client. */
|
|
18
|
-
events: EventManager;
|
|
19
16
|
/** REST Handler of the client. */
|
|
20
17
|
rest: RESTManager;
|
|
21
18
|
constructor(options?: ClientOptions);
|
|
22
19
|
/** Contains various general-purpose utility methods. */
|
|
23
20
|
get util(): typeof Util;
|
|
24
|
-
/** Whether the API is in maintenance break. */
|
|
25
|
-
get inMaintenance(): boolean;
|
|
26
21
|
/**
|
|
27
22
|
* Initialize the client to create keys.
|
|
28
23
|
* @example
|
|
@@ -57,7 +52,7 @@ export declare class Client extends EventEmitter {
|
|
|
57
52
|
*/
|
|
58
53
|
getCurrentWar(clanTag: string | {
|
|
59
54
|
clanTag: string;
|
|
60
|
-
round?: keyof typeof
|
|
55
|
+
round?: keyof typeof CWLRounds;
|
|
61
56
|
}, options?: OverrideOptions): Promise<ClanWar | null>;
|
|
62
57
|
/**
|
|
63
58
|
* Get info about currently running CWL round.
|
|
@@ -72,7 +67,7 @@ export declare class Client extends EventEmitter {
|
|
|
72
67
|
*/
|
|
73
68
|
getLeagueWar(clanTag: string | {
|
|
74
69
|
clanTag: string;
|
|
75
|
-
round?: keyof typeof
|
|
70
|
+
round?: keyof typeof CWLRounds;
|
|
76
71
|
}, options?: OverrideOptions): Promise<ClanWar | null>;
|
|
77
72
|
/** Returns active wars (last 2) of the CWL group. */
|
|
78
73
|
getLeagueWars(clanTag: string, options?: OverrideOptions): Promise<ClanWar[]>;
|
|
@@ -131,68 +126,4 @@ export declare class Client extends EventEmitter {
|
|
|
131
126
|
getPlayerLabels(options?: SearchOptions): Promise<Label[]>;
|
|
132
127
|
/** Get info about gold pass season. */
|
|
133
128
|
getGoldPassSeason(options?: OverrideOptions): Promise<GoldPassSeason>;
|
|
134
|
-
/**
|
|
135
|
-
* Emits when a new season starts.
|
|
136
|
-
*
|
|
137
|
-
* **Parameters**
|
|
138
|
-
*
|
|
139
|
-
* | Name | Type | Description |
|
|
140
|
-
* | :--: | :------: | :-------------------: |
|
|
141
|
-
* | `id` | `string` | Id of the new season. |
|
|
142
|
-
* @public
|
|
143
|
-
* @event
|
|
144
|
-
*/
|
|
145
|
-
private static newSeasonStart;
|
|
146
|
-
/**
|
|
147
|
-
* Emits when maintenance break starts in the API.
|
|
148
|
-
* @public
|
|
149
|
-
* @event
|
|
150
|
-
*/
|
|
151
|
-
private static maintenanceStart;
|
|
152
|
-
/**
|
|
153
|
-
* Emits when maintenance break ends in the API.
|
|
154
|
-
*
|
|
155
|
-
* **Parameters**
|
|
156
|
-
*
|
|
157
|
-
* | Name | Type | Description |
|
|
158
|
-
* | :--------: | :------: | :------------------------------------------------: |
|
|
159
|
-
* | `duration` | `number` | Duration of the maintenance break in milliseconds. |
|
|
160
|
-
* @public
|
|
161
|
-
* @event
|
|
162
|
-
*/
|
|
163
|
-
private static maintenanceEnd;
|
|
164
|
-
/** @internal */
|
|
165
|
-
on<K extends keyof ClientEvents>(event: K, listeners: (...args: ClientEvents[K]) => void): this;
|
|
166
|
-
/** @internal */
|
|
167
|
-
on<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: CustomEvents[S]) => void): this;
|
|
168
|
-
/** @internal */ on<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: any[]) => void): this;
|
|
169
|
-
/** @internal */
|
|
170
|
-
once<K extends keyof ClientEvents>(event: K, listeners: (...args: ClientEvents[K]) => void): this;
|
|
171
|
-
/** @internal */
|
|
172
|
-
once<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: CustomEvents[S]) => void): this;
|
|
173
|
-
/** @internal */ once<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: any[]) => void): this;
|
|
174
|
-
/** @internal */
|
|
175
|
-
emit<K extends keyof ClientEvents>(event: K, ...args: ClientEvents[K]): boolean;
|
|
176
|
-
/** @internal */
|
|
177
|
-
emit<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, ...args: CustomEvents[S]): this;
|
|
178
|
-
/** @internal */ emit<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, ...args: any[]): boolean;
|
|
179
|
-
}
|
|
180
|
-
interface ClientEvents {
|
|
181
|
-
[EVENTS.NEW_SEASON_START]: [id: string];
|
|
182
|
-
[EVENTS.MAINTENANCE_START]: [];
|
|
183
|
-
[EVENTS.MAINTENANCE_END]: [duration: number];
|
|
184
|
-
[EVENTS.CLAN_LOOP_START]: [];
|
|
185
|
-
[EVENTS.CLAN_LOOP_END]: [];
|
|
186
|
-
[EVENTS.PLAYER_LOOP_START]: [];
|
|
187
|
-
[EVENTS.PLAYER_LOOP_END]: [];
|
|
188
|
-
[EVENTS.WAR_LOOP_START]: [];
|
|
189
|
-
[EVENTS.WAR_LOOP_END]: [];
|
|
190
|
-
[EVENTS.ERROR]: [error: unknown];
|
|
191
|
-
[EVENTS.DEBUG]: [path: string, status: string, message: string];
|
|
192
|
-
}
|
|
193
|
-
interface CustomEvents {
|
|
194
|
-
[key: `clan${string}`]: [oldClan: Clan, newClan: Clan];
|
|
195
|
-
[key: `war${string}`]: [oldWar: ClanWar, newWar: ClanWar];
|
|
196
|
-
[key: `player${string}`]: [oldPlayer: Player, newPlayer: Player];
|
|
197
129
|
}
|
|
198
|
-
export {};
|
package/dist/client/Client.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.Client = void 0;
|
|
|
4
4
|
const Constants_1 = require("../util/Constants");
|
|
5
5
|
const HTTPError_1 = require("../rest/HTTPError");
|
|
6
6
|
const RESTManager_1 = require("../rest/RESTManager");
|
|
7
|
-
const EventManager_1 = require("./EventManager");
|
|
8
7
|
const events_1 = require("events");
|
|
9
8
|
const Util_1 = require("../util/Util");
|
|
10
9
|
const struct_1 = require("../struct");
|
|
@@ -19,17 +18,11 @@ class Client extends events_1.EventEmitter {
|
|
|
19
18
|
constructor(options) {
|
|
20
19
|
super();
|
|
21
20
|
this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true });
|
|
22
|
-
this.events = new EventManager_1.EventManager(this);
|
|
23
21
|
}
|
|
24
22
|
/** Contains various general-purpose utility methods. */
|
|
25
23
|
get util() {
|
|
26
24
|
return Util_1.Util;
|
|
27
25
|
}
|
|
28
|
-
/** Whether the API is in maintenance break. */
|
|
29
|
-
get inMaintenance() {
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
return this.events._inMaintenance;
|
|
32
|
-
}
|
|
33
26
|
/**
|
|
34
27
|
* Initialize the client to create keys.
|
|
35
28
|
* @example
|
|
@@ -116,7 +109,7 @@ class Client extends events_1.EventEmitter {
|
|
|
116
109
|
*/
|
|
117
110
|
async getLeagueWar(clanTag, options) {
|
|
118
111
|
const args = typeof clanTag === 'string' ? { clanTag } : { clanTag: clanTag.clanTag, round: clanTag.round };
|
|
119
|
-
const state = (args.round && Constants_1.
|
|
112
|
+
const state = (args.round && Constants_1.CWLRounds[args.round]) ?? 'inWar'; // eslint-disable-line
|
|
120
113
|
const data = await this.getClanWarLeagueGroup(args.clanTag, options);
|
|
121
114
|
const rounds = data.rounds.filter((round) => !round.warTags.includes('#0'));
|
|
122
115
|
if (!rounds.length)
|
|
@@ -128,10 +121,12 @@ class Client extends events_1.EventEmitter {
|
|
|
128
121
|
.flat()
|
|
129
122
|
.reverse();
|
|
130
123
|
const wars = await this.util.allSettled(warTags.map((warTag) => this.getClanWarLeagueRound({ warTag, clanTag: args.clanTag }, { ...options, ignoreRateLimit: true })));
|
|
131
|
-
if (args.round && args.round in Constants_1.
|
|
124
|
+
if (args.round && args.round in Constants_1.CWLRounds) {
|
|
132
125
|
return wars.find((war) => war.clan.tag === args.clanTag && war.state === state) ?? null;
|
|
133
126
|
}
|
|
134
|
-
return wars.find((war) => war.clan.tag === args.clanTag) ??
|
|
127
|
+
return (wars.find((war) => war.clan.tag === args.clanTag && war.state === state) ??
|
|
128
|
+
wars.find((war) => war.clan.tag === args.clanTag) ??
|
|
129
|
+
null);
|
|
135
130
|
}
|
|
136
131
|
/** Returns active wars (last 2) of the CWL group. */
|
|
137
132
|
async getLeagueWars(clanTag, options) {
|
|
@@ -194,12 +189,12 @@ class Client extends events_1.EventEmitter {
|
|
|
194
189
|
}
|
|
195
190
|
/** Get Legend League season Ids. */
|
|
196
191
|
async getLeagueSeasons(options) {
|
|
197
|
-
const { data } = await this.rest.getLeagueSeasons(Constants_1.
|
|
192
|
+
const { data } = await this.rest.getLeagueSeasons(Constants_1.LegendLeagueId, options);
|
|
198
193
|
return data.items.map((league) => league.id);
|
|
199
194
|
}
|
|
200
195
|
/** Get Legend League season rankings by season Id. */
|
|
201
196
|
async getSeasonRankings(seasonId, options) {
|
|
202
|
-
const { data } = await this.rest.getSeasonRankings(Constants_1.
|
|
197
|
+
const { data } = await this.rest.getSeasonRankings(Constants_1.LegendLeagueId, seasonId, options);
|
|
203
198
|
return data.items.map((entry) => new struct_1.SeasonRankedPlayer(this, entry));
|
|
204
199
|
}
|
|
205
200
|
/** Get list of Clan War Leagues. */
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
import { Clan, ClanWar, Player } from '../struct';
|
|
2
|
-
import {
|
|
3
|
-
/** Represents
|
|
4
|
-
export declare class
|
|
5
|
-
private readonly
|
|
2
|
+
import { PollingClient } from './PollingClient';
|
|
3
|
+
/** Represents PollingEvent Manager of the {@link PollingClient}. */
|
|
4
|
+
export declare class PollingEventManager {
|
|
5
|
+
private readonly pollingClient;
|
|
6
6
|
private readonly _clanTags;
|
|
7
7
|
private readonly _playerTags;
|
|
8
8
|
private readonly _warTags;
|
|
9
9
|
private readonly _clans;
|
|
10
10
|
private readonly _players;
|
|
11
11
|
private readonly _wars;
|
|
12
|
-
private readonly
|
|
12
|
+
private readonly _pollingEvents;
|
|
13
13
|
private _inMaintenance;
|
|
14
14
|
private _maintenanceStartTime;
|
|
15
|
-
constructor(
|
|
16
|
-
/** Initialize the
|
|
15
|
+
constructor(pollingClient: PollingClient);
|
|
16
|
+
/** Initialize the PollingEvent Manager to start pulling the data by polling api. */
|
|
17
17
|
init(): Promise<string[]>;
|
|
18
|
-
/** Add clan tags to clan events. */
|
|
18
|
+
/** Add clan tags to clan polling events. */
|
|
19
19
|
addClans(tags: string[] | string): this;
|
|
20
|
-
/** Delete clan tags from clan events. */
|
|
20
|
+
/** Delete clan tags from clan polling events. */
|
|
21
21
|
deleteClans(tags: string[] | string): this;
|
|
22
|
-
/** Add player tags for player events. */
|
|
22
|
+
/** Add player tags for player polling events. */
|
|
23
23
|
addPlayers(tags: string[] | string): this;
|
|
24
|
-
/** Delete player tags from player events. */
|
|
24
|
+
/** Delete player tags from player polling events. */
|
|
25
25
|
deletePlayers(tags: string[] | string): this;
|
|
26
|
-
/** Add clan tags for war events. */
|
|
26
|
+
/** Add clan tags for war polling events. */
|
|
27
27
|
addWars(tags: string[] | string): this;
|
|
28
|
-
/** Delete clan tags from war events. */
|
|
28
|
+
/** Delete clan tags from war polling events. */
|
|
29
29
|
deleteWars(tags: string[] | string): this;
|
|
30
30
|
/**
|
|
31
|
-
* Set your own custom clan event.
|
|
31
|
+
* Set your own custom clan polling event.
|
|
32
32
|
*
|
|
33
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
33
|
+
* In order to emit the custom polling event, you must have this filter function that returns a boolean.
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```js
|
|
37
|
-
* client.
|
|
37
|
+
* client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
|
|
38
38
|
*
|
|
39
|
-
* client.
|
|
39
|
+
* client.pollingEvents.setClanEvent({
|
|
40
40
|
* name: 'clanMemberUpdate',
|
|
41
41
|
* filter: (oldClan, newClan) => {
|
|
42
42
|
* return oldClan.memberCount !== newClan.memberCount;
|
|
@@ -48,7 +48,7 @@ export declare class EventManager {
|
|
|
48
48
|
* });
|
|
49
49
|
*
|
|
50
50
|
* (async function () {
|
|
51
|
-
* await client.
|
|
51
|
+
* await client.pollingEvents.init();
|
|
52
52
|
* })();
|
|
53
53
|
* ```
|
|
54
54
|
* @returns
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PollingEventManager = void 0;
|
|
4
4
|
const HTTPError_1 = require("../rest/HTTPError");
|
|
5
5
|
const Constants_1 = require("../util/Constants");
|
|
6
6
|
const Util_1 = require("../util/Util");
|
|
7
|
-
/** Represents
|
|
8
|
-
class
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
7
|
+
/** Represents PollingEvent Manager of the {@link PollingClient}. */
|
|
8
|
+
class PollingEventManager {
|
|
9
|
+
constructor(pollingClient) {
|
|
10
|
+
this.pollingClient = pollingClient;
|
|
11
11
|
this._clanTags = new Set();
|
|
12
12
|
this._playerTags = new Set();
|
|
13
13
|
this._warTags = new Set();
|
|
14
14
|
this._clans = new Map();
|
|
15
15
|
this._players = new Map();
|
|
16
16
|
this._wars = new Map();
|
|
17
|
-
this.
|
|
17
|
+
this._pollingEvents = {
|
|
18
18
|
clans: [],
|
|
19
19
|
wars: [],
|
|
20
20
|
players: []
|
|
@@ -22,58 +22,58 @@ class EventManager {
|
|
|
22
22
|
this._inMaintenance = Boolean(false);
|
|
23
23
|
this._maintenanceStartTime = null;
|
|
24
24
|
}
|
|
25
|
-
/** Initialize the
|
|
25
|
+
/** Initialize the PollingEvent Manager to start pulling the data by polling api. */
|
|
26
26
|
async init() {
|
|
27
27
|
this.seasonEndHandler();
|
|
28
28
|
this.maintenanceHandler();
|
|
29
29
|
this.clanUpdateHandler();
|
|
30
30
|
this.playerUpdateHandler();
|
|
31
31
|
this.warUpdateHandler();
|
|
32
|
-
return Promise.resolve(this.
|
|
32
|
+
return Promise.resolve(this.pollingClient.eventNames());
|
|
33
33
|
}
|
|
34
|
-
/** Add clan tags to clan events. */
|
|
34
|
+
/** Add clan tags to clan polling events. */
|
|
35
35
|
addClans(tags) {
|
|
36
36
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
37
|
-
this._clanTags.add(this.
|
|
37
|
+
this._clanTags.add(this.pollingClient.util.formatTag(tag));
|
|
38
38
|
}
|
|
39
39
|
return this;
|
|
40
40
|
}
|
|
41
|
-
/** Delete clan tags from clan events. */
|
|
41
|
+
/** Delete clan tags from clan polling events. */
|
|
42
42
|
deleteClans(tags) {
|
|
43
43
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
44
|
-
const key = this.
|
|
44
|
+
const key = this.pollingClient.util.formatTag(tag);
|
|
45
45
|
this._clans.delete(key);
|
|
46
46
|
this._clanTags.delete(key);
|
|
47
47
|
}
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
|
-
/** Add player tags for player events. */
|
|
50
|
+
/** Add player tags for player polling events. */
|
|
51
51
|
addPlayers(tags) {
|
|
52
52
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
53
|
-
this._playerTags.add(this.
|
|
53
|
+
this._playerTags.add(this.pollingClient.util.formatTag(tag));
|
|
54
54
|
}
|
|
55
55
|
return this;
|
|
56
56
|
}
|
|
57
|
-
/** Delete player tags from player events. */
|
|
57
|
+
/** Delete player tags from player polling events. */
|
|
58
58
|
deletePlayers(tags) {
|
|
59
59
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
60
|
-
const key = this.
|
|
60
|
+
const key = this.pollingClient.util.formatTag(tag);
|
|
61
61
|
this._players.delete(key);
|
|
62
62
|
this._playerTags.delete(key);
|
|
63
63
|
}
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
|
-
/** Add clan tags for war events. */
|
|
66
|
+
/** Add clan tags for war polling events. */
|
|
67
67
|
addWars(tags) {
|
|
68
68
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
69
|
-
this._warTags.add(this.
|
|
69
|
+
this._warTags.add(this.pollingClient.util.formatTag(tag));
|
|
70
70
|
}
|
|
71
71
|
return this;
|
|
72
72
|
}
|
|
73
|
-
/** Delete clan tags from war events. */
|
|
73
|
+
/** Delete clan tags from war polling events. */
|
|
74
74
|
deleteWars(tags) {
|
|
75
75
|
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
76
|
-
const key = this.
|
|
76
|
+
const key = this.pollingClient.util.formatTag(tag);
|
|
77
77
|
this._wars.delete(`${key}:${1}`);
|
|
78
78
|
this._wars.delete(`${key}:${2}`);
|
|
79
79
|
this._warTags.delete(key);
|
|
@@ -81,15 +81,15 @@ class EventManager {
|
|
|
81
81
|
return this;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Set your own custom clan event.
|
|
84
|
+
* Set your own custom clan polling event.
|
|
85
85
|
*
|
|
86
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
86
|
+
* In order to emit the custom polling event, you must have this filter function that returns a boolean.
|
|
87
87
|
*
|
|
88
88
|
* @example
|
|
89
89
|
* ```js
|
|
90
|
-
* client.
|
|
90
|
+
* client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
|
|
91
91
|
*
|
|
92
|
-
* client.
|
|
92
|
+
* client.pollingEvents.setClanEvent({
|
|
93
93
|
* name: 'clanMemberUpdate',
|
|
94
94
|
* filter: (oldClan, newClan) => {
|
|
95
95
|
* return oldClan.memberCount !== newClan.memberCount;
|
|
@@ -101,7 +101,7 @@ class EventManager {
|
|
|
101
101
|
* });
|
|
102
102
|
*
|
|
103
103
|
* (async function () {
|
|
104
|
-
* await client.
|
|
104
|
+
* await client.pollingEvents.init();
|
|
105
105
|
* })();
|
|
106
106
|
* ```
|
|
107
107
|
* @returns
|
|
@@ -111,7 +111,7 @@ class EventManager {
|
|
|
111
111
|
throw new Error('Event name is required.');
|
|
112
112
|
if (typeof event.filter !== 'function')
|
|
113
113
|
throw new Error('Filter function is required.');
|
|
114
|
-
this.
|
|
114
|
+
this._pollingEvents.clans.push(event);
|
|
115
115
|
return this;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -124,7 +124,7 @@ class EventManager {
|
|
|
124
124
|
throw new Error('Event name is required.');
|
|
125
125
|
if (typeof event.filter !== 'function')
|
|
126
126
|
throw new Error('Filter function is required.');
|
|
127
|
-
this.
|
|
127
|
+
this._pollingEvents.wars.push(event);
|
|
128
128
|
return this;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
@@ -137,25 +137,25 @@ class EventManager {
|
|
|
137
137
|
throw new Error('Event name is required.');
|
|
138
138
|
if (typeof event.filter !== 'function')
|
|
139
139
|
throw new Error('Filter function is required.');
|
|
140
|
-
this.
|
|
140
|
+
this._pollingEvents.players.push(event);
|
|
141
141
|
return this;
|
|
142
142
|
}
|
|
143
143
|
async maintenanceHandler() {
|
|
144
144
|
setTimeout(this.maintenanceHandler.bind(this), 10000).unref();
|
|
145
145
|
try {
|
|
146
|
-
const res = await this.
|
|
146
|
+
const res = await this.pollingClient.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
|
|
147
147
|
if (res.status === 200 && this._inMaintenance) {
|
|
148
148
|
this._inMaintenance = Boolean(false);
|
|
149
149
|
const duration = Date.now() - this._maintenanceStartTime.getTime();
|
|
150
150
|
this._maintenanceStartTime = null;
|
|
151
|
-
this.
|
|
151
|
+
this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceEnd, duration);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
catch (error) {
|
|
155
155
|
if (error instanceof HTTPError_1.HTTPError && error.status === 503 && !this._inMaintenance) {
|
|
156
156
|
this._inMaintenance = Boolean(true);
|
|
157
157
|
this._maintenanceStartTime = new Date();
|
|
158
|
-
this.
|
|
158
|
+
this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceStart);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -167,48 +167,48 @@ class EventManager {
|
|
|
167
167
|
}
|
|
168
168
|
else if (end > 0) {
|
|
169
169
|
setTimeout(() => {
|
|
170
|
-
this.
|
|
170
|
+
this.pollingClient.emit(Constants_1.PollingEvents.NewSeasonStart, Util_1.Util.getSeasonId());
|
|
171
171
|
}, end + 100).unref();
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
async clanUpdateHandler() {
|
|
175
|
-
this.
|
|
175
|
+
this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopStart);
|
|
176
176
|
for (const tag of this._clanTags)
|
|
177
177
|
await this.runClanUpdate(tag);
|
|
178
|
-
this.
|
|
178
|
+
this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopEnd);
|
|
179
179
|
setTimeout(this.clanUpdateHandler.bind(this), 10000);
|
|
180
180
|
}
|
|
181
181
|
async playerUpdateHandler() {
|
|
182
|
-
this.
|
|
182
|
+
this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopStart);
|
|
183
183
|
for (const tag of this._playerTags)
|
|
184
184
|
await this.runPlayerUpdate(tag);
|
|
185
|
-
this.
|
|
185
|
+
this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopEnd);
|
|
186
186
|
setTimeout(this.playerUpdateHandler.bind(this), 10000);
|
|
187
187
|
}
|
|
188
188
|
async warUpdateHandler() {
|
|
189
|
-
this.
|
|
189
|
+
this.pollingClient.emit(Constants_1.PollingEvents.WarLoopStart);
|
|
190
190
|
for (const tag of this._warTags)
|
|
191
191
|
await this.runWarUpdate(tag);
|
|
192
|
-
this.
|
|
192
|
+
this.pollingClient.emit(Constants_1.PollingEvents.WarLoopEnd);
|
|
193
193
|
setTimeout(this.warUpdateHandler.bind(this), 10000);
|
|
194
194
|
}
|
|
195
195
|
async runClanUpdate(tag) {
|
|
196
196
|
if (this._inMaintenance)
|
|
197
197
|
return null;
|
|
198
|
-
const clan = await this.
|
|
198
|
+
const clan = await this.pollingClient.getClan(tag).catch(() => null);
|
|
199
199
|
if (!clan)
|
|
200
200
|
return null;
|
|
201
201
|
const cached = this._clans.get(clan.tag);
|
|
202
202
|
if (!cached)
|
|
203
203
|
return this._clans.set(clan.tag, clan);
|
|
204
|
-
for (const { name, filter } of this.
|
|
204
|
+
for (const { name, filter } of this._pollingEvents.clans) {
|
|
205
205
|
try {
|
|
206
206
|
if (!(await filter(cached, clan)))
|
|
207
207
|
continue;
|
|
208
|
-
this.
|
|
208
|
+
this.pollingClient.emit(name, cached, clan);
|
|
209
209
|
}
|
|
210
210
|
catch (error) {
|
|
211
|
-
this.
|
|
211
|
+
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
return this._clans.set(clan.tag, clan);
|
|
@@ -216,20 +216,20 @@ class EventManager {
|
|
|
216
216
|
async runPlayerUpdate(tag) {
|
|
217
217
|
if (this._inMaintenance)
|
|
218
218
|
return null;
|
|
219
|
-
const player = await this.
|
|
219
|
+
const player = await this.pollingClient.getPlayer(tag).catch(() => null);
|
|
220
220
|
if (!player)
|
|
221
221
|
return null;
|
|
222
222
|
const cached = this._players.get(player.tag);
|
|
223
223
|
if (!cached)
|
|
224
224
|
return this._players.set(player.tag, player);
|
|
225
|
-
for (const { name, filter } of this.
|
|
225
|
+
for (const { name, filter } of this._pollingEvents.players) {
|
|
226
226
|
try {
|
|
227
227
|
if (!(await filter(cached, player)))
|
|
228
228
|
continue;
|
|
229
|
-
this.
|
|
229
|
+
this.pollingClient.emit(name, cached, player);
|
|
230
230
|
}
|
|
231
231
|
catch (error) {
|
|
232
|
-
this.
|
|
232
|
+
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
return this._players.set(player.tag, player);
|
|
@@ -237,7 +237,7 @@ class EventManager {
|
|
|
237
237
|
async runWarUpdate(tag) {
|
|
238
238
|
if (this._inMaintenance)
|
|
239
239
|
return null;
|
|
240
|
-
const clanWars = await this.
|
|
240
|
+
const clanWars = await this.pollingClient.getWars(tag).catch(() => null);
|
|
241
241
|
if (!clanWars?.length)
|
|
242
242
|
return null;
|
|
243
243
|
clanWars.forEach(async (war, index) => {
|
|
@@ -245,28 +245,28 @@ class EventManager {
|
|
|
245
245
|
const cached = this._wars.get(key);
|
|
246
246
|
if (!cached)
|
|
247
247
|
return this._wars.set(key, war);
|
|
248
|
-
for (const { name, filter } of this.
|
|
248
|
+
for (const { name, filter } of this._pollingEvents.wars) {
|
|
249
249
|
try {
|
|
250
250
|
if (!(await filter(cached, war)))
|
|
251
251
|
continue;
|
|
252
|
-
this.
|
|
252
|
+
this.pollingClient.emit(name, cached, war);
|
|
253
253
|
}
|
|
254
254
|
catch (error) {
|
|
255
|
-
this.
|
|
255
|
+
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
// check for war end
|
|
259
259
|
if (index === 1 && cached.warTag !== war.warTag) {
|
|
260
|
-
const data = await this.
|
|
260
|
+
const data = await this.pollingClient.getLeagueWar({ clanTag: tag, round: 'PreviousRound' }).catch(() => null);
|
|
261
261
|
if (data && data.warTag === cached.warTag) {
|
|
262
|
-
for (const { name, filter } of this.
|
|
262
|
+
for (const { name, filter } of this._pollingEvents.wars) {
|
|
263
263
|
try {
|
|
264
264
|
if (!(await filter(cached, data)))
|
|
265
265
|
continue;
|
|
266
|
-
this.
|
|
266
|
+
this.pollingClient.emit(name, cached, data);
|
|
267
267
|
}
|
|
268
268
|
catch (error) {
|
|
269
|
-
this.
|
|
269
|
+
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
}
|
|
@@ -275,4 +275,4 @@ class EventManager {
|
|
|
275
275
|
});
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
exports.
|
|
278
|
+
exports.PollingEventManager = PollingEventManager;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Clan, ClanWar, Player } from '../struct';
|
|
2
|
+
import { ClientOptions } from '../types';
|
|
3
|
+
import { PollingEvents } from '../util/Constants';
|
|
4
|
+
import { Client } from './Client';
|
|
5
|
+
import { PollingEventManager } from './EventManager';
|
|
6
|
+
/**
|
|
7
|
+
* Represents Clash of Clans Polling Event Client.
|
|
8
|
+
* ```js
|
|
9
|
+
* const { PollingClient } = require('clashofclans.js');
|
|
10
|
+
* const client = new PollingClient({ keys: ['***'] });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class PollingClient extends Client {
|
|
14
|
+
/** Polling Event Manager for the client. */
|
|
15
|
+
pollingEvents: PollingEventManager;
|
|
16
|
+
constructor(options?: ClientOptions);
|
|
17
|
+
/** Whether the API is in maintenance break. */
|
|
18
|
+
get inMaintenance(): any;
|
|
19
|
+
/**
|
|
20
|
+
* Emits when a new season starts.
|
|
21
|
+
*
|
|
22
|
+
* **Parameters**
|
|
23
|
+
*
|
|
24
|
+
* | Name | Type | Description |
|
|
25
|
+
* | :--: | :------: | :-------------------: |
|
|
26
|
+
* | `id` | `string` | Id of the new season. |
|
|
27
|
+
* @public
|
|
28
|
+
* @event
|
|
29
|
+
*/
|
|
30
|
+
private static newSeasonStart;
|
|
31
|
+
/**
|
|
32
|
+
* Emits when maintenance break starts in the API.
|
|
33
|
+
* @public
|
|
34
|
+
* @event
|
|
35
|
+
*/
|
|
36
|
+
private static maintenanceStart;
|
|
37
|
+
/**
|
|
38
|
+
* Emits when maintenance break ends in the API.
|
|
39
|
+
*
|
|
40
|
+
* **Parameters**
|
|
41
|
+
*
|
|
42
|
+
* | Name | Type | Description |
|
|
43
|
+
* | :--------: | :------: | :------------------------------------------------: |
|
|
44
|
+
* | `duration` | `number` | Duration of the maintenance break in milliseconds. |
|
|
45
|
+
* @public
|
|
46
|
+
* @event
|
|
47
|
+
*/
|
|
48
|
+
private static maintenanceEnd;
|
|
49
|
+
/** @internal */
|
|
50
|
+
on<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
|
|
51
|
+
/** @internal */
|
|
52
|
+
on<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
|
|
53
|
+
/** @internal */ on<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
|
|
54
|
+
/** @internal */
|
|
55
|
+
once<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
|
|
56
|
+
/** @internal */
|
|
57
|
+
once<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
|
|
58
|
+
/** @internal */ once<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
|
|
59
|
+
/** @internal */
|
|
60
|
+
emit<K extends keyof ClientPollingEvents>(event: K, ...args: ClientPollingEvents[K]): boolean;
|
|
61
|
+
/** @internal */
|
|
62
|
+
emit<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, ...args: CustomEvents[S]): this;
|
|
63
|
+
/** @internal */ emit<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, ...args: any[]): boolean;
|
|
64
|
+
}
|
|
65
|
+
interface ClientPollingEvents {
|
|
66
|
+
[PollingEvents.NewSeasonStart]: [id: string];
|
|
67
|
+
[PollingEvents.MaintenanceStart]: [];
|
|
68
|
+
[PollingEvents.MaintenanceEnd]: [duration: number];
|
|
69
|
+
[PollingEvents.ClanLoopStart]: [];
|
|
70
|
+
[PollingEvents.ClanLoopEnd]: [];
|
|
71
|
+
[PollingEvents.PlayerLoopStart]: [];
|
|
72
|
+
[PollingEvents.PlayerLoopEnd]: [];
|
|
73
|
+
[PollingEvents.WarLoopStart]: [];
|
|
74
|
+
[PollingEvents.WarLoopEnd]: [];
|
|
75
|
+
[PollingEvents.Error]: [error: unknown];
|
|
76
|
+
[PollingEvents.Debug]: [path: string, status: string, message: string];
|
|
77
|
+
}
|
|
78
|
+
interface CustomEvents {
|
|
79
|
+
[key: `clan${string}`]: [oldClan: Clan, newClan: Clan];
|
|
80
|
+
[key: `war${string}`]: [oldWar: ClanWar, newWar: ClanWar];
|
|
81
|
+
[key: `player${string}`]: [oldPlayer: Player, newPlayer: Player];
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PollingClient = void 0;
|
|
4
|
+
const Constants_1 = require("../util/Constants");
|
|
5
|
+
const Client_1 = require("./Client");
|
|
6
|
+
const EventManager_1 = require("./EventManager");
|
|
7
|
+
/**
|
|
8
|
+
* Represents Clash of Clans Polling Event Client.
|
|
9
|
+
* ```js
|
|
10
|
+
* const { PollingClient } = require('clashofclans.js');
|
|
11
|
+
* const client = new PollingClient({ keys: ['***'] });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
class PollingClient extends Client_1.Client {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super(options);
|
|
17
|
+
this.pollingEvents = new EventManager_1.PollingEventManager(this);
|
|
18
|
+
}
|
|
19
|
+
/** Whether the API is in maintenance break. */
|
|
20
|
+
get inMaintenance() {
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
return this.events._inMaintenance;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PollingClient = PollingClient;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./client/Client"), exports);
|
|
14
|
+
__exportStar(require("./client/PollingClient"), exports);
|
|
14
15
|
__exportStar(require("./rest/RESTManager"), exports);
|
|
15
16
|
__exportStar(require("./rest/RequestHandler"), exports);
|
|
16
17
|
__exportStar(require("./rest/HTTPError"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import mod from "./index.js";
|
|
2
2
|
|
|
3
3
|
export default mod;
|
|
4
|
-
export const
|
|
4
|
+
export const APIBaseURL = mod.APIBaseURL;
|
|
5
5
|
export const Achievement = mod.Achievement;
|
|
6
|
-
export const BUILDER_TROOPS = mod.BUILDER_TROOPS;
|
|
7
6
|
export const Badge = mod.Badge;
|
|
8
7
|
export const BatchThrottler = mod.BatchThrottler;
|
|
9
|
-
export const
|
|
8
|
+
export const BuilderTroops = mod.BuilderTroops;
|
|
9
|
+
export const CWLRounds = mod.CWLRounds;
|
|
10
10
|
export const CacheStore = mod.CacheStore;
|
|
11
11
|
export const ChatLanguage = mod.ChatLanguage;
|
|
12
12
|
export const Clan = mod.Clan;
|
|
@@ -20,48 +20,49 @@ export const ClanWarLeagueRound = mod.ClanWarLeagueRound;
|
|
|
20
20
|
export const ClanWarLog = mod.ClanWarLog;
|
|
21
21
|
export const ClanWarMember = mod.ClanWarMember;
|
|
22
22
|
export const Client = mod.Client;
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
25
|
-
export const
|
|
26
|
-
export const
|
|
27
|
-
export const
|
|
28
|
-
export const
|
|
29
|
-
export const EventManager = mod.EventManager;
|
|
30
|
-
export const FRIENDLY_WAR_PREPARATION_TIMES = mod.FRIENDLY_WAR_PREPARATION_TIMES;
|
|
23
|
+
export const DarkElixirSpells = mod.DarkElixirSpells;
|
|
24
|
+
export const DarkElixirTroops = mod.DarkElixirTroops;
|
|
25
|
+
export const DevSiteAPIBaseURL = mod.DevSiteAPIBaseURL;
|
|
26
|
+
export const ElixirSpells = mod.ElixirSpells;
|
|
27
|
+
export const ElixirTroops = mod.ElixirTroops;
|
|
28
|
+
export const FriendlyWarPreparationTimes = mod.FriendlyWarPreparationTimes;
|
|
31
29
|
export const GoldPassSeason = mod.GoldPassSeason;
|
|
32
|
-
export const HEROES = mod.HEROES;
|
|
33
|
-
export const HERO_PETS = mod.HERO_PETS;
|
|
34
|
-
export const HOME_TROOPS = mod.HOME_TROOPS;
|
|
35
30
|
export const HTTPError = mod.HTTPError;
|
|
36
31
|
export const Hero = mod.Hero;
|
|
32
|
+
export const HeroPets = mod.HeroPets;
|
|
33
|
+
export const Heroes = mod.Heroes;
|
|
34
|
+
export const HomeTroops = mod.HomeTroops;
|
|
37
35
|
export const Icon = mod.Icon;
|
|
38
|
-
export const LEAGUES = mod.LEAGUES;
|
|
39
|
-
export const LEGEND_LEAGUE_ID = mod.LEGEND_LEAGUE_ID;
|
|
40
36
|
export const Label = mod.Label;
|
|
41
37
|
export const League = mod.League;
|
|
38
|
+
export const Leagues = mod.Leagues;
|
|
39
|
+
export const LegendLeagueId = mod.LegendLeagueId;
|
|
42
40
|
export const LegendStatistics = mod.LegendStatistics;
|
|
43
41
|
export const Location = mod.Location;
|
|
44
42
|
export const NotInWarError = mod.NotInWarError;
|
|
45
43
|
export const Player = mod.Player;
|
|
46
44
|
export const PlayerClan = mod.PlayerClan;
|
|
45
|
+
export const PollingClient = mod.PollingClient;
|
|
46
|
+
export const PollingEventManager = mod.PollingEventManager;
|
|
47
|
+
export const PollingEvents = mod.PollingEvents;
|
|
47
48
|
export const PrivateWarLogError = mod.PrivateWarLogError;
|
|
48
49
|
export const QueueThrottler = mod.QueueThrottler;
|
|
49
|
-
export const RAW_DATA = mod.RAW_DATA;
|
|
50
50
|
export const RESTManager = mod.RESTManager;
|
|
51
51
|
export const RankedClan = mod.RankedClan;
|
|
52
52
|
export const RankedPlayer = mod.RankedPlayer;
|
|
53
|
+
export const RawData = mod.RawData;
|
|
53
54
|
export const RequestHandler = mod.RequestHandler;
|
|
54
|
-
export const SIEGE_MACHINES = mod.SIEGE_MACHINES;
|
|
55
|
-
export const SPELLS = mod.SPELLS;
|
|
56
|
-
export const SUPER_TROOPS = mod.SUPER_TROOPS;
|
|
57
55
|
export const Season = mod.Season;
|
|
58
56
|
export const SeasonRankedPlayer = mod.SeasonRankedPlayer;
|
|
57
|
+
export const SiegeMachines = mod.SiegeMachines;
|
|
59
58
|
export const Spell = mod.Spell;
|
|
59
|
+
export const Spells = mod.Spells;
|
|
60
|
+
export const SuperTroops = mod.SuperTroops;
|
|
60
61
|
export const Troop = mod.Troop;
|
|
61
|
-
export const UNRANKED_LEAGUE_DATA = mod.UNRANKED_LEAGUE_DATA;
|
|
62
62
|
export const Unit = mod.Unit;
|
|
63
|
+
export const UnrankedLeagueData = mod.UnrankedLeagueData;
|
|
63
64
|
export const Util = mod.Util;
|
|
64
|
-
export const WAR_LEAGUES = mod.WAR_LEAGUES;
|
|
65
65
|
export const WarClan = mod.WarClan;
|
|
66
66
|
export const WarLeague = mod.WarLeague;
|
|
67
|
+
export const WarLeagues = mod.WarLeagues;
|
|
67
68
|
export const WarLogClan = mod.WarLogClan;
|
|
@@ -30,7 +30,7 @@ class RequestHandler {
|
|
|
30
30
|
this.keys = options?.keys ?? [];
|
|
31
31
|
this.retryLimit = options?.retryLimit ?? 0;
|
|
32
32
|
this.throttler = options?.throttler ?? null;
|
|
33
|
-
this.baseURL = options?.baseURL ?? Constants_1.
|
|
33
|
+
this.baseURL = options?.baseURL ?? Constants_1.APIBaseURL;
|
|
34
34
|
this.restRequestTimeout = options?.restRequestTimeout ?? 0;
|
|
35
35
|
this.rejectIfNotValid = options?.rejectIfNotValid ?? true;
|
|
36
36
|
if (typeof options?.cache === 'object')
|
|
@@ -120,7 +120,7 @@ class RequestHandler {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
async login() {
|
|
123
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
123
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/login`, {
|
|
124
124
|
method: 'POST',
|
|
125
125
|
timeout: 10000,
|
|
126
126
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -135,7 +135,7 @@ class RequestHandler {
|
|
|
135
135
|
return this.getKeys(res.headers.get('set-cookie'), ip);
|
|
136
136
|
}
|
|
137
137
|
async getKeys(cookie, ip) {
|
|
138
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
138
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/list`, {
|
|
139
139
|
method: 'POST',
|
|
140
140
|
timeout: 10000,
|
|
141
141
|
headers: { 'Content-Type': 'application/json', cookie }
|
|
@@ -177,7 +177,7 @@ class RequestHandler {
|
|
|
177
177
|
return this.keys;
|
|
178
178
|
}
|
|
179
179
|
async revokeKey(keyId, cookie) {
|
|
180
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
180
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/revoke`, {
|
|
181
181
|
method: 'POST',
|
|
182
182
|
timeout: 10000,
|
|
183
183
|
body: JSON.stringify({ id: keyId }),
|
|
@@ -186,7 +186,7 @@ class RequestHandler {
|
|
|
186
186
|
return res.ok;
|
|
187
187
|
}
|
|
188
188
|
async createKey(cookie, ip) {
|
|
189
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
189
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/create`, {
|
|
190
190
|
method: 'POST',
|
|
191
191
|
timeout: 10000,
|
|
192
192
|
headers: { 'Content-Type': 'application/json', cookie },
|
|
@@ -12,7 +12,7 @@ class ClanMember {
|
|
|
12
12
|
this.role = data.role.replace('admin', 'elder');
|
|
13
13
|
this.expLevel = data.expLevel;
|
|
14
14
|
// eslint-disable-next-line
|
|
15
|
-
this.league = new League_1.League(data.league ?? Constants_1.
|
|
15
|
+
this.league = new League_1.League(data.league ?? Constants_1.UnrankedLeagueData);
|
|
16
16
|
this.trophies = data.trophies;
|
|
17
17
|
this.versusTrophies = data.versusTrophies ?? null;
|
|
18
18
|
this.clanRank = data.clanRank;
|
package/dist/struct/ClanWar.js
CHANGED
|
@@ -201,7 +201,7 @@ class ClanWar {
|
|
|
201
201
|
/** Whether this is a friendly war. */
|
|
202
202
|
get isFriendly() {
|
|
203
203
|
const preparationTime = this.startTime.getTime() - this.preparationStartTime.getTime();
|
|
204
|
-
return Constants_1.
|
|
204
|
+
return Constants_1.FriendlyWarPreparationTimes.includes(preparationTime);
|
|
205
205
|
}
|
|
206
206
|
/** Whether this is a CWL. */
|
|
207
207
|
get isCWL() {
|
package/dist/struct/League.js
CHANGED
package/dist/struct/Player.js
CHANGED
|
@@ -33,7 +33,7 @@ class Player {
|
|
|
33
33
|
this.role = data.role?.replace('admin', 'elder') ?? null;
|
|
34
34
|
this.warOptedIn = data.warPreference ? data.warPreference === 'in' : null;
|
|
35
35
|
this.clan = data.clan ? new PlayerClan_1.PlayerClan(client, data.clan) : null;
|
|
36
|
-
this.league = new League_1.League(data.league ?? Constants_1.
|
|
36
|
+
this.league = new League_1.League(data.league ?? Constants_1.UnrankedLeagueData);
|
|
37
37
|
this.legendStatistics = data.legendStatistics ? new LegendStatistics_1.LegendStatistics(data.legendStatistics) : null;
|
|
38
38
|
this.achievements = data.achievements.map((data) => new Achievement_1.Achievement(data));
|
|
39
39
|
this.labels = data.labels.map((data) => new Label_1.Label(data));
|
|
@@ -70,32 +70,32 @@ class Player {
|
|
|
70
70
|
/** An array of the player's home base troops. */
|
|
71
71
|
get homeTroops() {
|
|
72
72
|
return this.troops
|
|
73
|
-
.filter((entry) => Constants_1.
|
|
74
|
-
.sort((a, b) => Constants_1.
|
|
73
|
+
.filter((entry) => entry.village === 'home' && Constants_1.HomeTroops.includes(entry.name))
|
|
74
|
+
.sort((a, b) => Constants_1.HomeTroops.indexOf(a.name) - Constants_1.HomeTroops.indexOf(b.name));
|
|
75
75
|
}
|
|
76
76
|
/** An array of the player's builder base troops. */
|
|
77
77
|
get builderTroops() {
|
|
78
78
|
return this.troops
|
|
79
|
-
.filter((entry) => Constants_1.
|
|
80
|
-
.sort((a, b) => Constants_1.
|
|
79
|
+
.filter((entry) => entry.village === 'builderBase' && Constants_1.BuilderTroops.includes(entry.name))
|
|
80
|
+
.sort((a, b) => Constants_1.BuilderTroops.indexOf(a.name) - Constants_1.BuilderTroops.indexOf(b.name));
|
|
81
81
|
}
|
|
82
82
|
/** An array of the player's super troops. */
|
|
83
83
|
get superTroops() {
|
|
84
84
|
return this.troops
|
|
85
|
-
.filter((entry) => Constants_1.
|
|
86
|
-
.sort((a, b) => Constants_1.
|
|
85
|
+
.filter((entry) => entry.village === 'home' && Constants_1.SuperTroops.includes(entry.name))
|
|
86
|
+
.sort((a, b) => Constants_1.SuperTroops.indexOf(a.name) - Constants_1.SuperTroops.indexOf(b.name));
|
|
87
87
|
}
|
|
88
88
|
/** An array of the player's hero pets. */
|
|
89
89
|
get heroPets() {
|
|
90
90
|
return this.troops
|
|
91
|
-
.filter((entry) => Constants_1.
|
|
92
|
-
.sort((a, b) => Constants_1.
|
|
91
|
+
.filter((entry) => entry.village === 'home' && Constants_1.HeroPets.includes(entry.name))
|
|
92
|
+
.sort((a, b) => Constants_1.HeroPets.indexOf(a.name) - Constants_1.HeroPets.indexOf(b.name));
|
|
93
93
|
}
|
|
94
94
|
/** An array of the player's siege machines. */
|
|
95
95
|
get siegeMachines() {
|
|
96
96
|
return this.troops
|
|
97
|
-
.filter((entry) => Constants_1.
|
|
98
|
-
.sort((a, b) => Constants_1.
|
|
97
|
+
.filter((entry) => entry.village === 'home' && Constants_1.SiegeMachines.includes(entry.name))
|
|
98
|
+
.sort((a, b) => Constants_1.SiegeMachines.indexOf(a.name) - Constants_1.SiegeMachines.indexOf(b.name));
|
|
99
99
|
}
|
|
100
100
|
/** Get player's formatted link to open player in-game. */
|
|
101
101
|
get shareLink() {
|
package/dist/struct/Ranking.js
CHANGED
|
@@ -46,7 +46,7 @@ class RankedPlayer {
|
|
|
46
46
|
// @ts-expect-error
|
|
47
47
|
this.clan = data.clan ? new PlayerClan_1.PlayerClan(client, data.clan) : null;
|
|
48
48
|
// @ts-expect-error
|
|
49
|
-
this.league = data.trophies ? new League_1.League(data.league ?? Constants_1.
|
|
49
|
+
this.league = data.trophies ? new League_1.League(data.league ?? Constants_1.UnrankedLeagueData) : null; // eslint-disable-line
|
|
50
50
|
}
|
|
51
51
|
/** Get player's formatted link to open player in-game. */
|
|
52
52
|
get shareLink() {
|
package/dist/struct/Unit.js
CHANGED
|
@@ -10,14 +10,14 @@ class Unit {
|
|
|
10
10
|
this.level = unit.level;
|
|
11
11
|
this.maxLevel = unit.maxLevel;
|
|
12
12
|
this.village = unit.village;
|
|
13
|
-
const rawSuperUnit = Constants_1.
|
|
14
|
-
const rawUnit = Constants_1.
|
|
13
|
+
const rawSuperUnit = Constants_1.RawData.RawSuperUnits.find((unit) => unit.name === this.name && this.isHomeBase);
|
|
14
|
+
const rawUnit = Constants_1.RawData.RawUnits.find((unit) => unit.name === this.name && unit.village === this.village);
|
|
15
15
|
if (rawSuperUnit) {
|
|
16
16
|
this.id = rawSuperUnit.id;
|
|
17
17
|
this.housingSpace = rawSuperUnit.housingSpace;
|
|
18
18
|
this.originalName = rawSuperUnit.original;
|
|
19
19
|
this.minOriginalLevel = rawSuperUnit.minOriginalLevel;
|
|
20
|
-
const original = Constants_1.
|
|
20
|
+
const original = Constants_1.RawData.RawUnits.find((unit) => unit.village === 'home' && unit.name === rawSuperUnit.original);
|
|
21
21
|
this.unlockHallLevel = original.levels.findIndex((level) => level >= rawSuperUnit.minOriginalLevel) + 1;
|
|
22
22
|
this.unlockCost = original.unlock.cost;
|
|
23
23
|
this.unlockTime = original.unlock.time;
|
|
@@ -87,7 +87,7 @@ class Troop extends Unit {
|
|
|
87
87
|
}
|
|
88
88
|
/** Whether this troop is a Super Troop. */
|
|
89
89
|
get isSuperTroop() {
|
|
90
|
-
return this.isActive || (this.isHomeBase && Constants_1.
|
|
90
|
+
return this.isActive || (this.isHomeBase && Constants_1.SuperTroops.includes(this.name));
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
exports.Troop = Troop;
|
package/dist/struct/WarLeague.js
CHANGED
package/dist/util/Constants.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
1
|
+
export declare const APIBaseURL = "https://api.clashofclans.com/v1";
|
|
2
|
+
export declare const DevSiteAPIBaseURL = "https://developer.clashofclans.com/api";
|
|
3
|
+
export declare const ElixirTroops: string[];
|
|
4
|
+
export declare const DarkElixirTroops: string[];
|
|
5
|
+
export declare const HomeTroops: string[];
|
|
6
|
+
export declare const SiegeMachines: string[];
|
|
7
|
+
export declare const SuperTroops: string[];
|
|
8
|
+
export declare const ElixirSpells: string[];
|
|
9
|
+
export declare const DarkElixirSpells: string[];
|
|
10
|
+
export declare const Spells: string[];
|
|
11
|
+
export declare const BuilderTroops: string[];
|
|
12
|
+
export declare const Heroes: string[];
|
|
13
|
+
export declare const HeroPets: string[];
|
|
14
|
+
export declare const UnrankedLeagueData: {
|
|
15
15
|
id: number;
|
|
16
16
|
name: string;
|
|
17
17
|
iconUrls: {
|
|
@@ -19,30 +19,30 @@ export declare const UNRANKED_LEAGUE_DATA: {
|
|
|
19
19
|
tiny: string;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
29
|
-
readonly
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
22
|
+
export declare const LegendLeagueId = 29000022;
|
|
23
|
+
export declare const Leagues: number[];
|
|
24
|
+
export declare const WarLeagues: number[];
|
|
25
|
+
export declare const FriendlyWarPreparationTimes: readonly [number, number, number, number, number, number, number, number, number, number, number, number];
|
|
26
|
+
export declare const PollingEvents: {
|
|
27
|
+
readonly NewSeasonStart: "newSeasonStart";
|
|
28
|
+
readonly ClanLoopStart: "clanLoopStart";
|
|
29
|
+
readonly ClanLoopEnd: "clanLoopEnd";
|
|
30
|
+
readonly PlayerLoopStart: "playerLoopStart";
|
|
31
|
+
readonly PlayerLoopEnd: "playerLoopEnd";
|
|
32
|
+
readonly WarLoopStart: "warLoopEnd";
|
|
33
|
+
readonly WarLoopEnd: "warLoopEnd";
|
|
34
|
+
readonly MaintenanceStart: "maintenanceStart";
|
|
35
|
+
readonly MaintenanceEnd: "maintenanceEnd";
|
|
36
|
+
readonly Error: "error";
|
|
37
|
+
readonly Debug: "debug";
|
|
38
38
|
};
|
|
39
|
-
export declare const
|
|
40
|
-
readonly
|
|
41
|
-
readonly
|
|
42
|
-
readonly
|
|
39
|
+
export declare const CWLRounds: {
|
|
40
|
+
readonly PreviousRound: "warEnded";
|
|
41
|
+
readonly CurrentRound: "inWar";
|
|
42
|
+
readonly NextRound: "preparation";
|
|
43
43
|
};
|
|
44
|
-
export declare const
|
|
45
|
-
|
|
44
|
+
export declare const RawData: {
|
|
45
|
+
RawUnits: {
|
|
46
46
|
id: number;
|
|
47
47
|
name: string;
|
|
48
48
|
housingSpace: number;
|
|
@@ -69,7 +69,7 @@ export declare const RAW_DATA: {
|
|
|
69
69
|
seasonal: boolean;
|
|
70
70
|
levels: number[];
|
|
71
71
|
}[];
|
|
72
|
-
|
|
72
|
+
RawSuperUnits: {
|
|
73
73
|
name: string;
|
|
74
74
|
id: number;
|
|
75
75
|
original: string;
|
package/dist/util/Constants.js
CHANGED
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.RawData = exports.CWLRounds = exports.PollingEvents = exports.FriendlyWarPreparationTimes = exports.WarLeagues = exports.Leagues = exports.LegendLeagueId = exports.UnrankedLeagueData = exports.HeroPets = exports.Heroes = exports.BuilderTroops = exports.Spells = exports.DarkElixirSpells = exports.ElixirSpells = exports.SuperTroops = exports.SiegeMachines = exports.HomeTroops = exports.DarkElixirTroops = exports.ElixirTroops = exports.DevSiteAPIBaseURL = exports.APIBaseURL = void 0;
|
|
7
7
|
const raw_json_1 = __importDefault(require("../util/raw.json"));
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
8
|
+
exports.APIBaseURL = 'https://api.clashofclans.com/v1';
|
|
9
|
+
exports.DevSiteAPIBaseURL = 'https://developer.clashofclans.com/api';
|
|
10
|
+
exports.ElixirTroops = [
|
|
11
11
|
'Barbarian',
|
|
12
12
|
'Archer',
|
|
13
13
|
'Giant',
|
|
@@ -24,10 +24,10 @@ exports.ELIXIR_TROOPS = [
|
|
|
24
24
|
'Yeti',
|
|
25
25
|
'Dragon Rider'
|
|
26
26
|
];
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
27
|
+
exports.DarkElixirTroops = ['Minion', 'Hog Rider', 'Valkyrie', 'Golem', 'Witch', 'Lava Hound', 'Bowler', 'Ice Golem', 'Headhunter'];
|
|
28
|
+
exports.HomeTroops = [...exports.ElixirTroops, ...exports.DarkElixirTroops];
|
|
29
|
+
exports.SiegeMachines = ['Wall Wrecker', 'Battle Blimp', 'Stone Slammer', 'Siege Barracks', 'Log Launcher', 'Flame Flinger'];
|
|
30
|
+
exports.SuperTroops = [
|
|
31
31
|
'Super Barbarian',
|
|
32
32
|
'Super Archer',
|
|
33
33
|
'Super Giant',
|
|
@@ -43,7 +43,7 @@ exports.SUPER_TROOPS = [
|
|
|
43
43
|
'Ice Hound',
|
|
44
44
|
'Super Bowler'
|
|
45
45
|
];
|
|
46
|
-
exports.
|
|
46
|
+
exports.ElixirSpells = [
|
|
47
47
|
'Lightning Spell',
|
|
48
48
|
'Healing Spell',
|
|
49
49
|
'Rage Spell',
|
|
@@ -52,9 +52,9 @@ exports.ELIXIR_SPELLS = [
|
|
|
52
52
|
'Clone Spell',
|
|
53
53
|
'Invisibility Spell'
|
|
54
54
|
];
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.
|
|
55
|
+
exports.DarkElixirSpells = ['Poison Spell', 'Earthquake Spell', 'Haste Spell', 'Skeleton Spell', 'Bat Spell'];
|
|
56
|
+
exports.Spells = [...exports.ElixirSpells, ...exports.DarkElixirSpells];
|
|
57
|
+
exports.BuilderTroops = [
|
|
58
58
|
'Raged Barbarian',
|
|
59
59
|
'Sneaky Archer',
|
|
60
60
|
'Boxer Giant',
|
|
@@ -67,9 +67,9 @@ exports.BUILDER_TROOPS = [
|
|
|
67
67
|
'Super P.E.K.K.A',
|
|
68
68
|
'Hog Glider'
|
|
69
69
|
];
|
|
70
|
-
exports.
|
|
71
|
-
exports.
|
|
72
|
-
exports.
|
|
70
|
+
exports.Heroes = ['Barbarian King', 'Archer Queen', 'Grand Warden', 'Royal Champion', 'Battle Machine'];
|
|
71
|
+
exports.HeroPets = ['L.A.S.S.I', 'Electro Owl', 'Mighty Yak', 'Unicorn'];
|
|
72
|
+
exports.UnrankedLeagueData = {
|
|
73
73
|
id: 29000000,
|
|
74
74
|
name: 'Unranked',
|
|
75
75
|
iconUrls: {
|
|
@@ -77,8 +77,8 @@ exports.UNRANKED_LEAGUE_DATA = {
|
|
|
77
77
|
tiny: 'https://api-assets.clashofclans.com/leagues/36/e--YMyIexEQQhE4imLoJcwhYn6Uy8KqlgyY3_kFV6t4.png'
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
exports.
|
|
81
|
-
exports.
|
|
80
|
+
exports.LegendLeagueId = 29000022;
|
|
81
|
+
exports.Leagues = [
|
|
82
82
|
29000000,
|
|
83
83
|
29000001,
|
|
84
84
|
29000002,
|
|
@@ -101,13 +101,13 @@ exports.LEAGUES = [
|
|
|
101
101
|
29000019,
|
|
102
102
|
29000020,
|
|
103
103
|
29000021,
|
|
104
|
-
exports.
|
|
104
|
+
exports.LegendLeagueId
|
|
105
105
|
];
|
|
106
|
-
exports.
|
|
106
|
+
exports.WarLeagues = [
|
|
107
107
|
48000000, 48000001, 48000002, 48000003, 48000004, 48000005, 48000006, 48000007, 48000008, 48000009, 48000010, 48000011, 48000012,
|
|
108
108
|
48000013, 48000014, 48000015, 48000016, 48000017, 48000018
|
|
109
109
|
];
|
|
110
|
-
exports.
|
|
110
|
+
exports.FriendlyWarPreparationTimes = [
|
|
111
111
|
1000 * 60 * 60 * 24,
|
|
112
112
|
1000 * 60 * 60 * 20,
|
|
113
113
|
1000 * 60 * 60 * 16,
|
|
@@ -121,25 +121,25 @@ exports.FRIENDLY_WAR_PREPARATION_TIMES = [
|
|
|
121
121
|
1000 * 60 * 15,
|
|
122
122
|
1000 * 60 * 5
|
|
123
123
|
];
|
|
124
|
-
exports.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
exports.PollingEvents = {
|
|
125
|
+
NewSeasonStart: 'newSeasonStart',
|
|
126
|
+
ClanLoopStart: 'clanLoopStart',
|
|
127
|
+
ClanLoopEnd: 'clanLoopEnd',
|
|
128
|
+
PlayerLoopStart: 'playerLoopStart',
|
|
129
|
+
PlayerLoopEnd: 'playerLoopEnd',
|
|
130
|
+
WarLoopStart: 'warLoopEnd',
|
|
131
|
+
WarLoopEnd: 'warLoopEnd',
|
|
132
|
+
MaintenanceStart: 'maintenanceStart',
|
|
133
|
+
MaintenanceEnd: 'maintenanceEnd',
|
|
134
|
+
Error: 'error',
|
|
135
|
+
Debug: 'debug'
|
|
136
136
|
};
|
|
137
|
-
exports.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
exports.CWLRounds = {
|
|
138
|
+
PreviousRound: 'warEnded',
|
|
139
|
+
CurrentRound: 'inWar',
|
|
140
|
+
NextRound: 'preparation'
|
|
141
141
|
};
|
|
142
|
-
exports.
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
exports.RawData = {
|
|
143
|
+
RawUnits: raw_json_1.default.RAW_UNITS,
|
|
144
|
+
RawSuperUnits: raw_json_1.default.RAW_SUPER_UNITS
|
|
145
145
|
};
|
package/dist/util/Util.js
CHANGED
|
@@ -132,11 +132,11 @@ class Util extends null {
|
|
|
132
132
|
}));
|
|
133
133
|
return {
|
|
134
134
|
units: units.map((unit) => {
|
|
135
|
-
const _unit = Constants_1.
|
|
135
|
+
const _unit = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'troop' && raw.id === unit.id);
|
|
136
136
|
return { name: _unit?.name ?? null, count: unit.total, id: unit.id };
|
|
137
137
|
}),
|
|
138
138
|
spells: spells.map((spell) => {
|
|
139
|
-
const _spell = Constants_1.
|
|
139
|
+
const _spell = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'spell' && raw.id === spell.id);
|
|
140
140
|
return { name: _spell?.name ?? null, count: spell.total, id: spell.id };
|
|
141
141
|
})
|
|
142
142
|
};
|