clashofclans.js 2.0.0-dev.dedb83d → 2.0.1-dev.ba82327
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/CHANGELOG.md +13 -5
- package/README.md +4 -3
- package/dist/client/Client.d.ts +29 -11
- package/dist/client/Client.js +38 -18
- package/dist/client/EventManager.d.ts +12 -12
- package/dist/client/EventManager.js +45 -26
- package/dist/rest/HTTPError.d.ts +8 -5
- package/dist/rest/HTTPError.js +4 -6
- package/dist/rest/RESTManager.d.ts +49 -144
- package/dist/rest/RESTManager.js +27 -4
- package/dist/rest/RequestHandler.d.ts +14 -7
- package/dist/rest/RequestHandler.js +39 -18
- package/dist/rest/Throttler.d.ts +0 -4
- package/dist/struct/Clan.d.ts +3 -2
- package/dist/struct/Clan.js +3 -3
- package/dist/struct/ClanMember.d.ts +2 -1
- package/dist/struct/ClanMember.js +2 -2
- package/dist/struct/ClanWarLeagueGroup.d.ts +6 -4
- package/dist/struct/ClanWarLeagueGroup.js +9 -8
- package/dist/struct/Player.d.ts +2 -1
- package/dist/struct/Player.js +7 -5
- package/dist/struct/PlayerClan.d.ts +9 -4
- package/dist/struct/PlayerClan.js +4 -4
- package/dist/struct/Ranking.d.ts +25 -5
- package/dist/struct/Ranking.js +21 -5
- package/dist/struct/Unit.d.ts +37 -4
- package/dist/struct/Unit.js +49 -9
- package/dist/types/index.d.ts +4 -6
- package/dist/util/raw.json +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
## 2.0.
|
|
5
|
+
## 2.0.1 (2021-11-27)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- IP retrieval method and Event Loop ([#70](https://github.com/clashperk/clashofclans.js/issues/70)) ([82b84ba](https://github.com/clashperk/clashofclans.js/commit/82b84ba5d96505c43b75e53aa07f547ef0b77778))
|
|
10
|
+
|
|
11
|
+
## 2.0.0 (2021-11-26)
|
|
6
12
|
|
|
7
13
|
This new version is a complete TypeScript rewrite to convert everything from plain (literal JSON) objects to class (constructor) objects and support a lot more features.
|
|
8
14
|
|
|
9
15
|
### Features
|
|
10
16
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
17
|
+
- HTTP Request Request Retries ([#26](https://github.com/clashperk/clashofclans.js/issues/26)) ([94585f3](https://github.com/clashperk/clashofclans.js/commit/94585f3a84a7175b2d07872f9eb9e42372b95e12))
|
|
18
|
+
- Event Manager and Custom Events ([#37](https://github.com/clashperk/clashofclans.js/issues/37)) ([5027ae6](https://github.com/clashperk/clashofclans.js/commit/5027ae663a8e07175e17384c7e5706f4a1a7afb4))
|
|
13
19
|
- Email Password Login ([#31](https://github.com/clashperk/clashofclans.js/issues/31)) ([4153cd3](https://github.com/clashperk/clashofclans.js/commit/4153cd37ea0e1c71550b9e892105b84d5a407e23))
|
|
14
|
-
-
|
|
20
|
+
- Queue Throttler and Batch Throttler ([#34](https://github.com/clashperk/clashofclans.js/issues/34)) ([3a8f051](https://github.com/clashperk/clashofclans.js/commit/3a8f051552e93b98f89bc7d524acdecddf242718))
|
|
15
21
|
- Override Request Options ([#36](https://github.com/clashperk/clashofclans.js/issues/36)) ([42d7fdd](https://github.com/clashperk/clashofclans.js/commit/42d7fdd36262cc46f23b731f8cffb9daea19d3b0))
|
|
16
|
-
-
|
|
22
|
+
- Internal Caching Options ([#53](https://github.com/clashperk/clashofclans.js/issues/53)) ([984451d](https://github.com/clashperk/clashofclans.js/commit/30ea3240c11866008d0dae514468c0fdbb34ffd0))
|
|
23
|
+
- Additional Properties for Player Units ([#65](https://github.com/clashperk/clashofclans.js/pull/65)) ([aa1696](https://github.com/clashperk/clashofclans.js/commit/aa1696243d96d4fed0250b4282c60522a6482343))
|
|
24
|
+
|
package/README.md
CHANGED
|
@@ -39,12 +39,13 @@ const client = new Client();
|
|
|
39
39
|
```js
|
|
40
40
|
const { Client, BatchThrottler } = require('clashofclans.js');
|
|
41
41
|
const client = new Client({
|
|
42
|
+
cache: true,
|
|
42
43
|
retryLimit: 1,
|
|
43
|
-
restRequestTimeout:
|
|
44
|
-
throttler: new BatchThrottler(
|
|
44
|
+
restRequestTimeout: 5000,
|
|
45
|
+
throttler: new BatchThrottler(20)
|
|
45
46
|
});
|
|
46
47
|
|
|
47
|
-
client.events.addClans(['#8P2QG08P']);
|
|
48
|
+
client.events.addClans(['#8QU8J9LP', '#8P2QG08P']);
|
|
48
49
|
client.events.setClanEvent({
|
|
49
50
|
name: 'clanDescriptionChange',
|
|
50
51
|
filter: (oldClan, newClan) => {
|
package/dist/client/Client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { RESTManager } from '../rest/RESTManager';
|
|
|
5
5
|
import { EventManager } from './EventManager';
|
|
6
6
|
import { EventEmitter } from 'events';
|
|
7
7
|
import { Util } from '../util/Util';
|
|
8
|
-
import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
|
|
8
|
+
import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, SeasonRankedPlayer, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
|
|
9
9
|
/**
|
|
10
10
|
* Represents Clash of Clans API Client.
|
|
11
11
|
* ```js
|
|
@@ -21,6 +21,8 @@ export declare class Client extends EventEmitter {
|
|
|
21
21
|
constructor(options?: ClientOptions);
|
|
22
22
|
/** Contains various general-purpose utility methods. */
|
|
23
23
|
get util(): typeof Util;
|
|
24
|
+
/** Whether the API is in maintenance break. */
|
|
25
|
+
get inMaintenance(): boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Initialize the client to create keys.
|
|
26
28
|
* @example
|
|
@@ -33,8 +35,8 @@ export declare class Client extends EventEmitter {
|
|
|
33
35
|
/** Set Clash of Clans API keys. */
|
|
34
36
|
setKeys(keys: string[]): this;
|
|
35
37
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
36
|
-
getClans(
|
|
37
|
-
/** Get
|
|
38
|
+
getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<Clan[]>;
|
|
39
|
+
/** Get info about a clan. */
|
|
38
40
|
getClan(clanTag: string, options?: OverrideOptions): Promise<Clan>;
|
|
39
41
|
/** Get list of clan members. */
|
|
40
42
|
getClanMembers(clanTag: string, options?: SearchOptions): Promise<ClanMember[]>;
|
|
@@ -74,14 +76,14 @@ export declare class Client extends EventEmitter {
|
|
|
74
76
|
}, options?: OverrideOptions): Promise<ClanWar | null>;
|
|
75
77
|
private _getCurrentLeagueWars;
|
|
76
78
|
private _getClanWars;
|
|
77
|
-
/** Get
|
|
79
|
+
/** Get info about clan war league. */
|
|
78
80
|
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<ClanWarLeagueGroup>;
|
|
79
|
-
/** Get
|
|
81
|
+
/** Get info about a CWL round by WarTag. */
|
|
80
82
|
getClanWarLeagueRound(warTag: string | {
|
|
81
83
|
warTag: string;
|
|
82
84
|
clanTag?: string;
|
|
83
85
|
}, options?: OverrideOptions): Promise<ClanWar>;
|
|
84
|
-
/** Get
|
|
86
|
+
/** Get info about a player by tag. */
|
|
85
87
|
getPlayer(playerTag: string, options?: OverrideOptions): Promise<Player>;
|
|
86
88
|
/** Verify Player API token that can be found from the Game settings. */
|
|
87
89
|
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<boolean>;
|
|
@@ -90,18 +92,34 @@ export declare class Client extends EventEmitter {
|
|
|
90
92
|
/** Get Legend League season Ids. */
|
|
91
93
|
getLeagueSeasons(options?: SearchOptions): Promise<string[]>;
|
|
92
94
|
/** Get Legend League season rankings by season Id. */
|
|
93
|
-
getSeasonRankings(seasonId: string, options?: SearchOptions): Promise<
|
|
95
|
+
getSeasonRankings(seasonId: string, options?: SearchOptions): Promise<SeasonRankedPlayer[]>;
|
|
94
96
|
/** Get list of Clan War Leagues. */
|
|
95
97
|
getWarLeagues(options?: SearchOptions): Promise<WarLeague[]>;
|
|
96
98
|
/** Get list of Locations. */
|
|
97
99
|
getLocations(options?: SearchOptions): Promise<Location[]>;
|
|
98
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Get clan rankings for a specific location.
|
|
102
|
+
*
|
|
103
|
+
* For global ranking, use `global` as `locationId`.
|
|
104
|
+
*/
|
|
99
105
|
getClanRanks(locationId: number | 'global', options?: SearchOptions): Promise<RankedClan[]>;
|
|
100
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Get player rankings for a specific location.
|
|
108
|
+
*
|
|
109
|
+
* For global ranking, use `global` as `locationId`.
|
|
110
|
+
*/
|
|
101
111
|
getPlayerRanks(locationId: number | 'global', options?: SearchOptions): Promise<RankedPlayer[]>;
|
|
102
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Get clan versus rankings for a specific location.
|
|
114
|
+
*
|
|
115
|
+
* For global ranking, use `global` as `locationId`.
|
|
116
|
+
*/
|
|
103
117
|
getVersusClanRanks(locationId: number | 'global', options?: SearchOptions): Promise<RankedClan[]>;
|
|
104
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Get player versus rankings for a specific location.
|
|
120
|
+
*
|
|
121
|
+
* For global ranking, use `global` as `locationId`.
|
|
122
|
+
*/
|
|
105
123
|
getVersusPlayerRanks(locationId: number | 'global', options?: SearchOptions): Promise<RankedPlayer[]>;
|
|
106
124
|
/** Get list of clan labels. */
|
|
107
125
|
getClanLabels(options?: SearchOptions): Promise<Label[]>;
|
package/dist/client/Client.js
CHANGED
|
@@ -25,6 +25,11 @@ class Client extends events_1.EventEmitter {
|
|
|
25
25
|
get util() {
|
|
26
26
|
return Util_1.Util;
|
|
27
27
|
}
|
|
28
|
+
/** Whether the API is in maintenance break. */
|
|
29
|
+
get inMaintenance() {
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
return this.events._inMaintenance;
|
|
32
|
+
}
|
|
28
33
|
/**
|
|
29
34
|
* Initialize the client to create keys.
|
|
30
35
|
* @example
|
|
@@ -42,12 +47,12 @@ class Client extends events_1.EventEmitter {
|
|
|
42
47
|
return this;
|
|
43
48
|
}
|
|
44
49
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
45
|
-
async getClans(options) {
|
|
46
|
-
const { data } = await this.rest.getClans(options);
|
|
50
|
+
async getClans(query, options) {
|
|
51
|
+
const { data } = await this.rest.getClans(query, options);
|
|
47
52
|
// @ts-expect-error
|
|
48
53
|
return data.items.map((clan) => new struct_1.Clan(this, clan));
|
|
49
54
|
}
|
|
50
|
-
/** Get
|
|
55
|
+
/** Get info about a clan. */
|
|
51
56
|
async getClan(clanTag, options) {
|
|
52
57
|
const { data } = await this.rest.getClan(clanTag, options);
|
|
53
58
|
return new struct_1.Clan(this, data);
|
|
@@ -88,7 +93,7 @@ class Client extends events_1.EventEmitter {
|
|
|
88
93
|
}
|
|
89
94
|
catch (e) {
|
|
90
95
|
if (e instanceof HTTPError_1.HTTPError && [200, 403].includes(e.status)) {
|
|
91
|
-
return this.getLeagueWar({ clanTag: args.clanTag, round: args.round });
|
|
96
|
+
return this.getLeagueWar({ clanTag: args.clanTag, round: args.round }, options);
|
|
92
97
|
}
|
|
93
98
|
throw e;
|
|
94
99
|
}
|
|
@@ -117,7 +122,7 @@ class Client extends events_1.EventEmitter {
|
|
|
117
122
|
.map((round) => round.warTags)
|
|
118
123
|
.flat()
|
|
119
124
|
.reverse();
|
|
120
|
-
const wars = await this.util.allSettled(warTags.map((warTag) => this.getClanWarLeagueRound({ warTag, clanTag: args.clanTag }, { ignoreRateLimit: true })));
|
|
125
|
+
const wars = await this.util.allSettled(warTags.map((warTag) => this.getClanWarLeagueRound({ warTag, clanTag: args.clanTag }, { ...options, ignoreRateLimit: true })));
|
|
121
126
|
if (args.round && args.round in Constants_1.CWL_ROUNDS) {
|
|
122
127
|
return wars.find((war) => war.state === state) ?? null;
|
|
123
128
|
}
|
|
@@ -126,7 +131,7 @@ class Client extends events_1.EventEmitter {
|
|
|
126
131
|
async _getCurrentLeagueWars(clanTag, options) {
|
|
127
132
|
const data = await this.getClanWarLeagueGroup(clanTag, options);
|
|
128
133
|
// @ts-expect-error
|
|
129
|
-
return data._getCurrentWars(clanTag);
|
|
134
|
+
return data._getCurrentWars(clanTag, options);
|
|
130
135
|
}
|
|
131
136
|
async _getClanWars(clanTag, options) {
|
|
132
137
|
const date = new Date().getUTCDate();
|
|
@@ -134,21 +139,21 @@ class Client extends events_1.EventEmitter {
|
|
|
134
139
|
return [await this.getClanWar(clanTag, options)];
|
|
135
140
|
}
|
|
136
141
|
try {
|
|
137
|
-
return this._getCurrentLeagueWars(clanTag);
|
|
142
|
+
return this._getCurrentLeagueWars(clanTag, options);
|
|
138
143
|
}
|
|
139
144
|
catch (e) {
|
|
140
145
|
if (e instanceof HTTPError_1.HTTPError && [404].includes(e.status)) {
|
|
141
|
-
return [await this.getClanWar(clanTag)];
|
|
146
|
+
return [await this.getClanWar(clanTag, options)];
|
|
142
147
|
}
|
|
143
148
|
throw e;
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
|
-
/** Get
|
|
151
|
+
/** Get info about clan war league. */
|
|
147
152
|
async getClanWarLeagueGroup(clanTag, options) {
|
|
148
153
|
const { data } = await this.rest.getClanWarLeagueGroup(clanTag, options);
|
|
149
154
|
return new struct_1.ClanWarLeagueGroup(this, data);
|
|
150
155
|
}
|
|
151
|
-
/** Get
|
|
156
|
+
/** Get info about a CWL round by WarTag. */
|
|
152
157
|
async getClanWarLeagueRound(warTag, options) {
|
|
153
158
|
const args = typeof warTag === 'string' ? { warTag } : { warTag: warTag.warTag, clanTag: warTag.clanTag };
|
|
154
159
|
const { data, maxAge, status, path } = await this.rest.getClanWarLeagueRound(args.warTag, options);
|
|
@@ -157,14 +162,14 @@ class Client extends events_1.EventEmitter {
|
|
|
157
162
|
}
|
|
158
163
|
return new struct_1.ClanWar(this, data, { warTag: args.warTag, clanTag: args.clanTag, maxAge });
|
|
159
164
|
}
|
|
160
|
-
/** Get
|
|
165
|
+
/** Get info about a player by tag. */
|
|
161
166
|
async getPlayer(playerTag, options) {
|
|
162
167
|
const { data } = await this.rest.getPlayer(playerTag, options);
|
|
163
168
|
return new struct_1.Player(this, data);
|
|
164
169
|
}
|
|
165
170
|
/** Verify Player API token that can be found from the Game settings. */
|
|
166
171
|
async verifyPlayerToken(playerTag, token, options) {
|
|
167
|
-
const { data } = await this.rest.
|
|
172
|
+
const { data } = await this.rest.verifyPlayerToken(playerTag, token, options);
|
|
168
173
|
return data.status === 'ok';
|
|
169
174
|
}
|
|
170
175
|
/** Get list of Leagues. */
|
|
@@ -180,8 +185,7 @@ class Client extends events_1.EventEmitter {
|
|
|
180
185
|
/** Get Legend League season rankings by season Id. */
|
|
181
186
|
async getSeasonRankings(seasonId, options) {
|
|
182
187
|
const { data } = await this.rest.getSeasonRankings(Constants_1.LEGEND_LEAGUE_ID, seasonId, options);
|
|
183
|
-
|
|
184
|
-
return data.items.map((entry) => new struct_1.RankedPlayer(entry));
|
|
188
|
+
return data.items.map((entry) => new struct_1.SeasonRankedPlayer(this, entry));
|
|
185
189
|
}
|
|
186
190
|
/** Get list of Clan War Leagues. */
|
|
187
191
|
async getWarLeagues(options) {
|
|
@@ -193,22 +197,38 @@ class Client extends events_1.EventEmitter {
|
|
|
193
197
|
const { data } = await this.rest.getLocations(options);
|
|
194
198
|
return data.items.map((entry) => new struct_1.Location(entry));
|
|
195
199
|
}
|
|
196
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Get clan rankings for a specific location.
|
|
202
|
+
*
|
|
203
|
+
* For global ranking, use `global` as `locationId`.
|
|
204
|
+
*/
|
|
197
205
|
async getClanRanks(locationId, options) {
|
|
198
206
|
const { data } = await this.rest.getClanRanks(locationId, options);
|
|
199
207
|
return data.items.map((entry) => new struct_1.RankedClan(entry));
|
|
200
208
|
}
|
|
201
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Get player rankings for a specific location.
|
|
211
|
+
*
|
|
212
|
+
* For global ranking, use `global` as `locationId`.
|
|
213
|
+
*/
|
|
202
214
|
async getPlayerRanks(locationId, options) {
|
|
203
215
|
const { data } = await this.rest.getPlayerRanks(locationId, options);
|
|
204
216
|
return data.items.map((entry) => new struct_1.RankedPlayer(this, entry));
|
|
205
217
|
}
|
|
206
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Get clan versus rankings for a specific location.
|
|
220
|
+
*
|
|
221
|
+
* For global ranking, use `global` as `locationId`.
|
|
222
|
+
*/
|
|
207
223
|
async getVersusClanRanks(locationId, options) {
|
|
208
224
|
const { data } = await this.rest.getVersusClanRanks(locationId, options);
|
|
209
225
|
return data.items.map((entry) => new struct_1.RankedClan(entry));
|
|
210
226
|
}
|
|
211
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Get player versus rankings for a specific location.
|
|
229
|
+
*
|
|
230
|
+
* For global ranking, use `global` as `locationId`.
|
|
231
|
+
*/
|
|
212
232
|
async getVersusPlayerRanks(locationId, options) {
|
|
213
233
|
const { data } = await this.rest.getVersusPlayerRanks(locationId, options);
|
|
214
234
|
return data.items.map((entry) => new struct_1.RankedPlayer(this, entry));
|
|
@@ -15,18 +15,18 @@ export declare class EventManager {
|
|
|
15
15
|
constructor(client: Client);
|
|
16
16
|
/** Initialize the Event Manager to start pulling. */
|
|
17
17
|
init(): Promise<string[]>;
|
|
18
|
-
/** Add
|
|
19
|
-
addClans(
|
|
20
|
-
/** Delete
|
|
21
|
-
deleteClans(
|
|
22
|
-
/** Add
|
|
23
|
-
addPlayers(
|
|
24
|
-
/** Delete
|
|
25
|
-
deletePlayers(
|
|
26
|
-
/** Add
|
|
27
|
-
addWars(
|
|
28
|
-
/** Delete
|
|
29
|
-
deleteWars(
|
|
18
|
+
/** Add clan tags to clan events. */
|
|
19
|
+
addClans(tags: string[] | string): this;
|
|
20
|
+
/** Delete clan tags from clan events. */
|
|
21
|
+
deleteClans(tags: string[] | string): this;
|
|
22
|
+
/** Add player tags for player events. */
|
|
23
|
+
addPlayers(tags: string[] | string): this;
|
|
24
|
+
/** Delete player tags from player events. */
|
|
25
|
+
deletePlayers(tags: string[] | string): this;
|
|
26
|
+
/** Add clan tags for war events. */
|
|
27
|
+
addWars(tags: string[] | string): this;
|
|
28
|
+
/** Delete clan tags from war events. */
|
|
29
|
+
deleteWars(tags: string[] | string): this;
|
|
30
30
|
/**
|
|
31
31
|
* Set your own custom clan event.
|
|
32
32
|
*
|
|
@@ -31,45 +31,52 @@ class EventManager {
|
|
|
31
31
|
this.warUpdateHandler();
|
|
32
32
|
return Promise.resolve(this.client.eventNames());
|
|
33
33
|
}
|
|
34
|
-
/** Add
|
|
35
|
-
addClans(
|
|
36
|
-
for (const tag of tags) {
|
|
34
|
+
/** Add clan tags to clan events. */
|
|
35
|
+
addClans(tags) {
|
|
36
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
37
37
|
this._clanTags.add(this.client.util.parseTag(tag));
|
|
38
38
|
}
|
|
39
39
|
return this;
|
|
40
40
|
}
|
|
41
|
-
/** Delete
|
|
42
|
-
deleteClans(
|
|
43
|
-
for (const tag of tags) {
|
|
44
|
-
this.
|
|
41
|
+
/** Delete clan tags from clan events. */
|
|
42
|
+
deleteClans(tags) {
|
|
43
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
44
|
+
const key = this.client.util.parseTag(tag);
|
|
45
|
+
this._clans.delete(key);
|
|
46
|
+
this._clanTags.delete(key);
|
|
45
47
|
}
|
|
46
48
|
return this;
|
|
47
49
|
}
|
|
48
|
-
/** Add
|
|
49
|
-
addPlayers(
|
|
50
|
-
for (const tag of tags) {
|
|
50
|
+
/** Add player tags for player events. */
|
|
51
|
+
addPlayers(tags) {
|
|
52
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
51
53
|
this._playerTags.add(this.client.util.parseTag(tag));
|
|
52
54
|
}
|
|
53
55
|
return this;
|
|
54
56
|
}
|
|
55
|
-
/** Delete
|
|
56
|
-
deletePlayers(
|
|
57
|
-
for (const tag of tags) {
|
|
58
|
-
this.
|
|
57
|
+
/** Delete player tags from player events. */
|
|
58
|
+
deletePlayers(tags) {
|
|
59
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
60
|
+
const key = this.client.util.parseTag(tag);
|
|
61
|
+
this._players.delete(key);
|
|
62
|
+
this._playerTags.delete(key);
|
|
59
63
|
}
|
|
60
64
|
return this;
|
|
61
65
|
}
|
|
62
|
-
/** Add
|
|
63
|
-
addWars(
|
|
64
|
-
for (const tag of tags) {
|
|
66
|
+
/** Add clan tags for war events. */
|
|
67
|
+
addWars(tags) {
|
|
68
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
65
69
|
this._warTags.add(this.client.util.parseTag(tag));
|
|
66
70
|
}
|
|
67
71
|
return this;
|
|
68
72
|
}
|
|
69
|
-
/** Delete
|
|
70
|
-
deleteWars(
|
|
71
|
-
for (const tag of tags) {
|
|
72
|
-
this.
|
|
73
|
+
/** Delete clan tags from war events. */
|
|
74
|
+
deleteWars(tags) {
|
|
75
|
+
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
76
|
+
const key = this.client.util.parseTag(tag);
|
|
77
|
+
this._wars.delete(`${key}:${1}`);
|
|
78
|
+
this._wars.delete(`${key}:${2}`);
|
|
79
|
+
this._warTags.delete(key);
|
|
73
80
|
}
|
|
74
81
|
return this;
|
|
75
82
|
}
|
|
@@ -100,6 +107,10 @@ class EventManager {
|
|
|
100
107
|
* @returns
|
|
101
108
|
*/
|
|
102
109
|
setClanEvent(event) {
|
|
110
|
+
if (!event.name)
|
|
111
|
+
throw new Error('Event name is required.');
|
|
112
|
+
if (typeof event.filter !== 'function')
|
|
113
|
+
throw new Error('Filter function is required.');
|
|
103
114
|
this._events.clans.push(event);
|
|
104
115
|
return this;
|
|
105
116
|
}
|
|
@@ -109,6 +120,10 @@ class EventManager {
|
|
|
109
120
|
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
110
121
|
*/
|
|
111
122
|
setWarEvent(event) {
|
|
123
|
+
if (!event.name)
|
|
124
|
+
throw new Error('Event name is required.');
|
|
125
|
+
if (typeof event.filter !== 'function')
|
|
126
|
+
throw new Error('Filter function is required.');
|
|
112
127
|
this._events.wars.push(event);
|
|
113
128
|
return this;
|
|
114
129
|
}
|
|
@@ -118,6 +133,10 @@ class EventManager {
|
|
|
118
133
|
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
119
134
|
*/
|
|
120
135
|
setPlayerEvent(event) {
|
|
136
|
+
if (!event.name)
|
|
137
|
+
throw new Error('Event name is required.');
|
|
138
|
+
if (typeof event.filter !== 'function')
|
|
139
|
+
throw new Error('Filter function is required.');
|
|
121
140
|
this._events.players.push(event);
|
|
122
141
|
return this;
|
|
123
142
|
}
|
|
@@ -127,7 +146,7 @@ class EventManager {
|
|
|
127
146
|
const res = await this.client.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
|
|
128
147
|
if (res.status === 200 && this._inMaintenance) {
|
|
129
148
|
this._inMaintenance = Boolean(false);
|
|
130
|
-
const duration =
|
|
149
|
+
const duration = Date.now() - this._maintenanceStartTime.getTime();
|
|
131
150
|
this._maintenanceStartTime = null;
|
|
132
151
|
this.client.emit(Constants_1.EVENTS.MAINTENANCE_END, duration);
|
|
133
152
|
}
|
|
@@ -144,7 +163,7 @@ class EventManager {
|
|
|
144
163
|
const end = Util_1.Util.getSeasonEndTime().getTime() - Date.now();
|
|
145
164
|
// Why this? setTimeout can be up to 24.8 days or 2147483647ms [(2^31 - 1) Max 32bit Integer]
|
|
146
165
|
if (end > 24 * 60 * 60 * 1000) {
|
|
147
|
-
setTimeout(this.seasonEndHandler.bind(this), 60 * 60 * 1000)
|
|
166
|
+
setTimeout(this.seasonEndHandler.bind(this), 60 * 60 * 1000);
|
|
148
167
|
}
|
|
149
168
|
else if (end > 0) {
|
|
150
169
|
setTimeout(() => {
|
|
@@ -222,8 +241,8 @@ class EventManager {
|
|
|
222
241
|
const clanWars = await this.client._getClanWars(tag).catch(() => null);
|
|
223
242
|
if (!clanWars?.length)
|
|
224
243
|
return null;
|
|
225
|
-
clanWars.forEach(async (war,
|
|
226
|
-
const key = `${tag}:${
|
|
244
|
+
clanWars.forEach(async (war, index) => {
|
|
245
|
+
const key = `${tag}:${index}`;
|
|
227
246
|
const cached = this._wars.get(key);
|
|
228
247
|
if (!cached)
|
|
229
248
|
return this._wars.set(key, war);
|
|
@@ -238,7 +257,7 @@ class EventManager {
|
|
|
238
257
|
}
|
|
239
258
|
}
|
|
240
259
|
// check for war end
|
|
241
|
-
if (
|
|
260
|
+
if (index === 1 && cached.warTag !== war.warTag) {
|
|
242
261
|
const data = await this.client.getLeagueWar({ clanTag: tag, round: 'PREVIOUS_ROUND' }).catch(() => null);
|
|
243
262
|
if (data && data.warTag === cached.warTag) {
|
|
244
263
|
for (const { name, filter } of this._events.wars) {
|
package/dist/rest/HTTPError.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents an HTTP Error.
|
|
3
|
-
*/
|
|
1
|
+
/** Represents an HTTP Error. */
|
|
4
2
|
export declare class HTTPError extends Error {
|
|
5
|
-
/** The message of this
|
|
3
|
+
/** The message of this errored request. */
|
|
6
4
|
message: string;
|
|
7
5
|
/** The HTTP method of this request. */
|
|
8
6
|
method: string;
|
|
9
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The reason of this errored request.
|
|
9
|
+
*
|
|
10
|
+
* Expected values are `notFound`, `notInWar`, `accessDenied`, `accessDenied.invalidIp`, `privateWarLog`,
|
|
11
|
+
* `badRequest`, `requestThrottled`, `serviceUnavailable`, `requestAborted` and `unknownException`.
|
|
12
|
+
*/
|
|
10
13
|
reason: string;
|
|
11
14
|
/** The HTTP status code of this request. */
|
|
12
15
|
status: number;
|
package/dist/rest/HTTPError.js
CHANGED
|
@@ -12,16 +12,14 @@ const messages = {
|
|
|
12
12
|
};
|
|
13
13
|
const reasons = {
|
|
14
14
|
503: 'serviceUnavailable',
|
|
15
|
-
429: '
|
|
15
|
+
429: 'requestThrottled',
|
|
16
16
|
400: 'badRequest',
|
|
17
|
-
403: '
|
|
18
|
-
500: '
|
|
17
|
+
403: 'accessDenied',
|
|
18
|
+
500: 'unknownException',
|
|
19
19
|
404: 'notFound',
|
|
20
20
|
504: 'requestAborted'
|
|
21
21
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Represents an HTTP Error.
|
|
24
|
-
*/
|
|
22
|
+
/** Represents an HTTP Error. */
|
|
25
23
|
class HTTPError extends Error {
|
|
26
24
|
constructor(error, status, path, maxAge, method) {
|
|
27
25
|
super();
|