clashofclans.js 2.7.0 → 2.8.0-dev.41c401c
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 +9 -1
- package/dist/client/Client.d.ts +8 -74
- package/dist/client/Client.js +14 -18
- package/dist/client/EventManager.d.ts +18 -18
- package/dist/client/EventManager.js +55 -56
- 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 -21
- package/dist/rest/RESTManager.d.ts +1 -1
- package/dist/rest/RequestHandler.d.ts +2 -2
- package/dist/rest/RequestHandler.js +7 -12
- package/dist/rest/Throttler.d.ts +10 -12
- package/dist/rest/Throttler.js +27 -50
- package/dist/struct/Clan.d.ts +3 -0
- package/dist/struct/Clan.js +2 -0
- package/dist/struct/ClanCapital.d.ts +12 -0
- package/dist/struct/ClanCapital.js +10 -0
- package/dist/struct/ClanMember.js +1 -1
- package/dist/struct/ClanWar.js +1 -1
- package/dist/struct/ClanWarLeagueGroup.d.ts +2 -1
- package/dist/struct/ClanWarLeagueGroup.js +2 -1
- package/dist/struct/League.js +1 -1
- package/dist/struct/Player.d.ts +2 -0
- package/dist/struct/Player.js +12 -11
- package/dist/struct/Ranking.js +1 -1
- package/dist/struct/Unit.js +4 -5
- package/dist/struct/WarLeague.js +1 -1
- package/dist/types/api.d.ts +10 -0
- package/dist/types/lib.d.ts +8 -3
- package/dist/util/Constants.d.ts +75 -33
- package/dist/util/Constants.js +44 -35
- package/dist/util/Util.d.ts +13 -0
- package/dist/util/Util.js +30 -0
- package/dist/util/raw.json +1 -1
- package/package.json +1 -1
|
@@ -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,47 +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
50
|
export const RESTManager = mod.RESTManager;
|
|
50
51
|
export const RankedClan = mod.RankedClan;
|
|
51
52
|
export const RankedPlayer = mod.RankedPlayer;
|
|
53
|
+
export const RawData = mod.RawData;
|
|
52
54
|
export const RequestHandler = mod.RequestHandler;
|
|
53
|
-
export const SIEGE_MACHINES = mod.SIEGE_MACHINES;
|
|
54
|
-
export const SPELLS = mod.SPELLS;
|
|
55
|
-
export const SUPER_TROOPS = mod.SUPER_TROOPS;
|
|
56
55
|
export const Season = mod.Season;
|
|
57
56
|
export const SeasonRankedPlayer = mod.SeasonRankedPlayer;
|
|
57
|
+
export const SiegeMachines = mod.SiegeMachines;
|
|
58
58
|
export const Spell = mod.Spell;
|
|
59
|
+
export const Spells = mod.Spells;
|
|
60
|
+
export const SuperTroops = mod.SuperTroops;
|
|
59
61
|
export const Troop = mod.Troop;
|
|
60
|
-
export const UNRANKED_LEAGUE_DATA = mod.UNRANKED_LEAGUE_DATA;
|
|
61
62
|
export const Unit = mod.Unit;
|
|
63
|
+
export const UnrankedLeagueData = mod.UnrankedLeagueData;
|
|
62
64
|
export const Util = mod.Util;
|
|
63
|
-
export const WAR_LEAGUES = mod.WAR_LEAGUES;
|
|
64
65
|
export const WarClan = mod.WarClan;
|
|
65
66
|
export const WarLeague = mod.WarLeague;
|
|
67
|
+
export const WarLeagues = mod.WarLeagues;
|
|
66
68
|
export const WarLogClan = mod.WarLogClan;
|
|
@@ -4,7 +4,7 @@ import { APIClan, APIClanList, APIClanMemberList, APIClanRankingList, APIClanVer
|
|
|
4
4
|
/** Represents a REST Manager of the client. */
|
|
5
5
|
export declare class RESTManager {
|
|
6
6
|
/** Request Handler for the RESTManager. */
|
|
7
|
-
|
|
7
|
+
handler: RequestHandler;
|
|
8
8
|
constructor(options?: RESTOptions);
|
|
9
9
|
/** Contains various general-purpose utility methods. */
|
|
10
10
|
get util(): typeof Util;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response, RequestOptions, LoginOptions, RequestHandlerOptions } from '../types';
|
|
2
2
|
/** Represents a Request Handler. */
|
|
3
3
|
export declare class RequestHandler {
|
|
4
4
|
#private;
|
|
@@ -14,7 +14,7 @@ export declare class RequestHandler {
|
|
|
14
14
|
private readonly restRequestTimeout;
|
|
15
15
|
private readonly throttler?;
|
|
16
16
|
private readonly cached;
|
|
17
|
-
constructor(options?:
|
|
17
|
+
constructor(options?: RequestHandlerOptions);
|
|
18
18
|
private get _keys();
|
|
19
19
|
private get _key();
|
|
20
20
|
setKeys(keys: string[]): this;
|
|
@@ -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')
|
|
@@ -54,19 +54,14 @@ class RequestHandler {
|
|
|
54
54
|
return Boolean(this.email && this.password);
|
|
55
55
|
}
|
|
56
56
|
async request(path, options = {}) {
|
|
57
|
-
const cached = (await this.cached
|
|
57
|
+
const cached = this.cached ? (await this.cached.get(path)) ?? null : null;
|
|
58
58
|
if (cached && options.force !== true) {
|
|
59
59
|
return { data: cached.data, maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 };
|
|
60
60
|
}
|
|
61
61
|
if (!this.throttler || options.ignoreRateLimit)
|
|
62
62
|
return this.exec(path, options);
|
|
63
63
|
await this.throttler.wait();
|
|
64
|
-
|
|
65
|
-
return await this.exec(path, options);
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
await this.throttler.throttle();
|
|
69
|
-
}
|
|
64
|
+
return this.exec(path, options);
|
|
70
65
|
}
|
|
71
66
|
async exec(path, options = {}, retries = 0) {
|
|
72
67
|
const res = await (0, node_fetch_1.default)(`${this.baseURL}${path}`, {
|
|
@@ -125,7 +120,7 @@ class RequestHandler {
|
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
122
|
async login() {
|
|
128
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
123
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/login`, {
|
|
129
124
|
method: 'POST',
|
|
130
125
|
timeout: 10000,
|
|
131
126
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -140,7 +135,7 @@ class RequestHandler {
|
|
|
140
135
|
return this.getKeys(res.headers.get('set-cookie'), ip);
|
|
141
136
|
}
|
|
142
137
|
async getKeys(cookie, ip) {
|
|
143
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
138
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/list`, {
|
|
144
139
|
method: 'POST',
|
|
145
140
|
timeout: 10000,
|
|
146
141
|
headers: { 'Content-Type': 'application/json', cookie }
|
|
@@ -182,7 +177,7 @@ class RequestHandler {
|
|
|
182
177
|
return this.keys;
|
|
183
178
|
}
|
|
184
179
|
async revokeKey(keyId, cookie) {
|
|
185
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
180
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/revoke`, {
|
|
186
181
|
method: 'POST',
|
|
187
182
|
timeout: 10000,
|
|
188
183
|
body: JSON.stringify({ id: keyId }),
|
|
@@ -191,7 +186,7 @@ class RequestHandler {
|
|
|
191
186
|
return res.ok;
|
|
192
187
|
}
|
|
193
188
|
async createKey(cookie, ip) {
|
|
194
|
-
const res = await (0, node_fetch_1.default)(`${Constants_1.
|
|
189
|
+
const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/create`, {
|
|
195
190
|
method: 'POST',
|
|
196
191
|
timeout: 10000,
|
|
197
192
|
headers: { 'Content-Type': 'application/json', cookie },
|
package/dist/rest/Throttler.d.ts
CHANGED
|
@@ -6,26 +6,24 @@
|
|
|
6
6
|
* ```
|
|
7
7
|
*/
|
|
8
8
|
export declare class QueueThrottler {
|
|
9
|
-
private lastRun?;
|
|
10
9
|
private readonly sleepTime;
|
|
11
|
-
private readonly
|
|
10
|
+
private readonly generator;
|
|
12
11
|
constructor(sleepTime?: number);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
wait(): Promise<void>;
|
|
16
|
-
private shift;
|
|
12
|
+
private init;
|
|
13
|
+
wait(): Promise<IteratorResult<undefined, void>>;
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* Represents a throttler that allows x requests per second before sleeping until the next second.
|
|
20
17
|
* ```js
|
|
21
|
-
* const throttler = new BatchThrottler(
|
|
22
|
-
* //
|
|
18
|
+
* const throttler = new BatchThrottler(15);
|
|
19
|
+
* // 15 requests every second.
|
|
23
20
|
* ```
|
|
24
21
|
*/
|
|
25
22
|
export declare class BatchThrottler {
|
|
26
|
-
#private;
|
|
27
23
|
private readonly rateLimit;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
private readonly sleepTime;
|
|
25
|
+
private readonly generator;
|
|
26
|
+
constructor(rateLimit?: number, sleepTime?: number);
|
|
27
|
+
private init;
|
|
28
|
+
wait(): Promise<IteratorResult<undefined, void>>;
|
|
31
29
|
}
|
package/dist/rest/Throttler.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _BatchThrottler_taskLogs;
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.BatchThrottler = exports.QueueThrottler = void 0;
|
|
10
4
|
const Util_1 = require("../util/Util");
|
|
@@ -17,70 +11,53 @@ const Util_1 = require("../util/Util");
|
|
|
17
11
|
*/
|
|
18
12
|
class QueueThrottler {
|
|
19
13
|
constructor(sleepTime = 100) {
|
|
20
|
-
this.
|
|
14
|
+
this.generator = this.init();
|
|
21
15
|
this.sleepTime = sleepTime;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const difference = Date.now() - this.lastRun;
|
|
17
|
+
async *init() {
|
|
18
|
+
let lastRan = 0;
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
while (true) {
|
|
21
|
+
const difference = Date.now() - lastRan;
|
|
29
22
|
const needToSleep = this.sleepTime - difference;
|
|
30
23
|
if (needToSleep > 0)
|
|
31
24
|
await Util_1.Util.delay(needToSleep);
|
|
25
|
+
lastRan = Date.now();
|
|
26
|
+
yield;
|
|
32
27
|
}
|
|
33
|
-
this.lastRun = Date.now();
|
|
34
|
-
return this.shift();
|
|
35
|
-
}
|
|
36
|
-
wait() {
|
|
37
|
-
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
38
|
-
let resolve;
|
|
39
|
-
const promise = new Promise((res) => {
|
|
40
|
-
resolve = res;
|
|
41
|
-
});
|
|
42
|
-
this.promises.push({ resolve: resolve, promise });
|
|
43
|
-
return next;
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (typeof deferred !== 'undefined')
|
|
48
|
-
deferred.resolve();
|
|
29
|
+
async wait() {
|
|
30
|
+
return this.generator.next();
|
|
49
31
|
}
|
|
50
32
|
}
|
|
51
33
|
exports.QueueThrottler = QueueThrottler;
|
|
52
34
|
/**
|
|
53
35
|
* Represents a throttler that allows x requests per second before sleeping until the next second.
|
|
54
36
|
* ```js
|
|
55
|
-
* const throttler = new BatchThrottler(
|
|
56
|
-
* //
|
|
37
|
+
* const throttler = new BatchThrottler(15);
|
|
38
|
+
* // 15 requests every second.
|
|
57
39
|
* ```
|
|
58
40
|
*/
|
|
59
41
|
class BatchThrottler {
|
|
60
|
-
constructor(rateLimit =
|
|
61
|
-
|
|
42
|
+
constructor(rateLimit = 15, sleepTime = 1000) {
|
|
43
|
+
this.generator = this.init();
|
|
62
44
|
this.rateLimit = rateLimit;
|
|
45
|
+
this.sleepTime = sleepTime;
|
|
63
46
|
}
|
|
64
|
-
async
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
__classPrivateFieldGet(this, _BatchThrottler_taskLogs, "f").shift();
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
47
|
+
async *init() {
|
|
48
|
+
let count = 0;
|
|
49
|
+
// eslint-disable-next-line
|
|
50
|
+
while (true) {
|
|
51
|
+
if (count++ >= this.rateLimit) {
|
|
52
|
+
if (this.sleepTime > 0)
|
|
53
|
+
await Util_1.Util.delay(this.sleepTime);
|
|
54
|
+
count = 0;
|
|
77
55
|
}
|
|
78
|
-
|
|
79
|
-
break;
|
|
80
|
-
await Util_1.Util.delay(1000);
|
|
56
|
+
yield;
|
|
81
57
|
}
|
|
82
|
-
|
|
58
|
+
}
|
|
59
|
+
async wait() {
|
|
60
|
+
return this.generator.next();
|
|
83
61
|
}
|
|
84
62
|
}
|
|
85
63
|
exports.BatchThrottler = BatchThrottler;
|
|
86
|
-
_BatchThrottler_taskLogs = new WeakMap();
|
package/dist/struct/Clan.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { Player } from './Player';
|
|
|
7
7
|
import { Location } from './Location';
|
|
8
8
|
import { Label } from './Label';
|
|
9
9
|
import { Badge } from './Badge';
|
|
10
|
+
import { ClanCapital } from './ClanCapital';
|
|
10
11
|
/** Represents a Clan. */
|
|
11
12
|
export declare class Clan {
|
|
12
13
|
client: Client;
|
|
@@ -54,6 +55,8 @@ export declare class Clan {
|
|
|
54
55
|
memberCount: number;
|
|
55
56
|
/** An array of {@link Label} that the clan has. */
|
|
56
57
|
labels: Label[];
|
|
58
|
+
/** The clan's Clan Capital information */
|
|
59
|
+
clanCapital: ClanCapital | null;
|
|
57
60
|
/**
|
|
58
61
|
* List of clan members.
|
|
59
62
|
* - This property returns empty array for {@link Client.getClans} method.
|
package/dist/struct/Clan.js
CHANGED
|
@@ -7,6 +7,7 @@ const WarLeague_1 = require("./WarLeague");
|
|
|
7
7
|
const Location_1 = require("./Location");
|
|
8
8
|
const Label_1 = require("./Label");
|
|
9
9
|
const Badge_1 = require("./Badge");
|
|
10
|
+
const ClanCapital_1 = require("./ClanCapital");
|
|
10
11
|
/** Represents a Clan. */
|
|
11
12
|
class Clan {
|
|
12
13
|
constructor(client, data) {
|
|
@@ -33,6 +34,7 @@ class Clan {
|
|
|
33
34
|
this.warLeague = data.warLeague ? new WarLeague_1.WarLeague(data.warLeague) : null;
|
|
34
35
|
this.memberCount = data.members;
|
|
35
36
|
this.labels = data.labels.map((label) => new Label_1.Label(label));
|
|
37
|
+
this.clanCapital = Object.keys(data.clanCapital).length > 0 ? new ClanCapital_1.ClanCapital(data.clanCapital) : null;
|
|
36
38
|
this.members = data.memberList?.map((mem) => new ClanMember_1.ClanMember(this.client, mem)) ?? []; // eslint-disable-line
|
|
37
39
|
}
|
|
38
40
|
/** Get {@link Player} info for every Player in the clan. */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { APIClanCapital } from '../types';
|
|
2
|
+
export declare class ClanCapital {
|
|
3
|
+
/** The clan capital hall level */
|
|
4
|
+
capitalHallLevel: number | null;
|
|
5
|
+
/** The clan capital districts */
|
|
6
|
+
districts: {
|
|
7
|
+
id: number;
|
|
8
|
+
name: string;
|
|
9
|
+
districtHallLevel: number;
|
|
10
|
+
}[] | null;
|
|
11
|
+
constructor(data: APIClanCapital);
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClanCapital = void 0;
|
|
4
|
+
class ClanCapital {
|
|
5
|
+
constructor(data) {
|
|
6
|
+
this.capitalHallLevel = data.capitalHallLevel ?? null;
|
|
7
|
+
this.districts = data.districts ? data.districts : null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ClanCapital = ClanCapital;
|
|
@@ -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() {
|
|
@@ -62,7 +62,8 @@ export declare class ClanWarLeagueGroup {
|
|
|
62
62
|
* @param options Override options for the request.
|
|
63
63
|
*/
|
|
64
64
|
getWars(clanTag?: string, options?: OverrideOptions): Promise<ClanWar[]>;
|
|
65
|
-
|
|
65
|
+
/** Returns active wars (last 2) of the CWL group. */
|
|
66
|
+
getCurrentWars(clanTag: string, options?: OverrideOptions): Promise<ClanWar[]>;
|
|
66
67
|
/** Returns the index of the round for this specified warTag. */
|
|
67
68
|
getRoundIndex(warTag: string): number | null;
|
|
68
69
|
}
|
|
@@ -75,7 +75,8 @@ class ClanWarLeagueGroup {
|
|
|
75
75
|
.map((res) => res.value)
|
|
76
76
|
.filter((war) => (clanTag ? war.clan.tag === clanTag : true));
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
/** Returns active wars (last 2) of the CWL group. */
|
|
79
|
+
async getCurrentWars(clanTag, options) {
|
|
79
80
|
const rounds = this.rounds.filter((round) => !round.warTags.includes('#0'));
|
|
80
81
|
if (!rounds.length)
|
|
81
82
|
return [];
|
package/dist/struct/League.js
CHANGED
package/dist/struct/Player.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export declare class Player {
|
|
|
41
41
|
donations: number;
|
|
42
42
|
/** The player's donation received count for this season. */
|
|
43
43
|
received: number;
|
|
44
|
+
/** The player's total Clan Capital contribution */
|
|
45
|
+
clanCapitalContributions: number;
|
|
44
46
|
/** The player's role in the clan or `null` if not in a clan. */
|
|
45
47
|
role: 'member' | 'elder' | 'coLeader' | 'leader' | null;
|
|
46
48
|
/** Whether the player has selected that they are opted in. This will be `null` if the player is not in a clan. */
|
package/dist/struct/Player.js
CHANGED
|
@@ -28,11 +28,12 @@ class Player {
|
|
|
28
28
|
this.versusBattleWins = data.versusBattleWins ?? null;
|
|
29
29
|
this.donations = data.donations;
|
|
30
30
|
this.received = data.donationsReceived;
|
|
31
|
+
this.clanCapitalContributions = data.clanCapitalContributions;
|
|
31
32
|
// @ts-expect-error
|
|
32
33
|
this.role = data.role?.replace('admin', 'elder') ?? null;
|
|
33
34
|
this.warOptedIn = data.warPreference ? data.warPreference === 'in' : null;
|
|
34
35
|
this.clan = data.clan ? new PlayerClan_1.PlayerClan(client, data.clan) : null;
|
|
35
|
-
this.league = new League_1.League(data.league ?? Constants_1.
|
|
36
|
+
this.league = new League_1.League(data.league ?? Constants_1.UnrankedLeagueData);
|
|
36
37
|
this.legendStatistics = data.legendStatistics ? new LegendStatistics_1.LegendStatistics(data.legendStatistics) : null;
|
|
37
38
|
this.achievements = data.achievements.map((data) => new Achievement_1.Achievement(data));
|
|
38
39
|
this.labels = data.labels.map((data) => new Label_1.Label(data));
|
|
@@ -69,32 +70,32 @@ class Player {
|
|
|
69
70
|
/** An array of the player's home base troops. */
|
|
70
71
|
get homeTroops() {
|
|
71
72
|
return this.troops
|
|
72
|
-
.filter((entry) => Constants_1.
|
|
73
|
-
.sort((a, b) => Constants_1.
|
|
73
|
+
.filter((entry) => Constants_1.HomeTroops.includes(entry.name))
|
|
74
|
+
.sort((a, b) => Constants_1.HomeTroops.indexOf(a.name) - Constants_1.HomeTroops.indexOf(b.name));
|
|
74
75
|
}
|
|
75
76
|
/** An array of the player's builder base troops. */
|
|
76
77
|
get builderTroops() {
|
|
77
78
|
return this.troops
|
|
78
|
-
.filter((entry) => Constants_1.
|
|
79
|
-
.sort((a, b) => Constants_1.
|
|
79
|
+
.filter((entry) => Constants_1.BuilderTroops.includes(entry.name))
|
|
80
|
+
.sort((a, b) => Constants_1.BuilderTroops.indexOf(a.name) - Constants_1.BuilderTroops.indexOf(b.name));
|
|
80
81
|
}
|
|
81
82
|
/** An array of the player's super troops. */
|
|
82
83
|
get superTroops() {
|
|
83
84
|
return this.troops
|
|
84
|
-
.filter((entry) => Constants_1.
|
|
85
|
-
.sort((a, b) => Constants_1.
|
|
85
|
+
.filter((entry) => Constants_1.SuperTroops.includes(entry.name))
|
|
86
|
+
.sort((a, b) => Constants_1.SuperTroops.indexOf(a.name) - Constants_1.SuperTroops.indexOf(b.name));
|
|
86
87
|
}
|
|
87
88
|
/** An array of the player's hero pets. */
|
|
88
89
|
get heroPets() {
|
|
89
90
|
return this.troops
|
|
90
|
-
.filter((entry) => Constants_1.
|
|
91
|
-
.sort((a, b) => Constants_1.
|
|
91
|
+
.filter((entry) => Constants_1.HeroPets.includes(entry.name))
|
|
92
|
+
.sort((a, b) => Constants_1.HeroPets.indexOf(a.name) - Constants_1.HeroPets.indexOf(b.name));
|
|
92
93
|
}
|
|
93
94
|
/** An array of the player's siege machines. */
|
|
94
95
|
get siegeMachines() {
|
|
95
96
|
return this.troops
|
|
96
|
-
.filter((entry) => Constants_1.
|
|
97
|
-
.sort((a, b) => Constants_1.
|
|
97
|
+
.filter((entry) => Constants_1.SiegeMachines.includes(entry.name))
|
|
98
|
+
.sort((a, b) => Constants_1.SiegeMachines.indexOf(a.name) - Constants_1.SiegeMachines.indexOf(b.name));
|
|
98
99
|
}
|
|
99
100
|
/** Get player's formatted link to open player in-game. */
|
|
100
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() {
|