clashofclans.js 3.0.0-dev.392ca4c → 3.0.0-dev.5d2e14a
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 +64 -47
- package/README.md +12 -8
- package/dist/client/Client.d.ts +29 -2
- package/dist/client/Client.js +14 -6
- package/dist/client/PollingClient.d.ts +106 -33
- package/dist/client/PollingClient.js +266 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.js +5 -2
- package/dist/index.mjs +2 -1
- package/dist/rest/RESTManager.d.ts +39 -4
- package/dist/rest/RESTManager.js +40 -29
- package/dist/rest/RequestHandler.d.ts +30 -2
- package/dist/rest/RequestHandler.js +12 -6
- package/dist/struct/CapitalRaidSeason.d.ts +29 -0
- package/dist/struct/CapitalRaidSeason.js +22 -0
- package/dist/struct/Clan.d.ts +1 -1
- package/dist/struct/ClanCapital.js +1 -1
- package/dist/struct/Player.d.ts +1 -1
- package/dist/struct/Ranking.d.ts +1 -1
- package/dist/struct/Unit.d.ts +0 -2
- package/dist/struct/Unit.js +0 -2
- package/dist/struct/index.js +5 -1
- package/dist/types/api.d.ts +58 -0
- package/dist/types/index.js +5 -1
- package/dist/types/lib.d.ts +4 -4
- package/dist/util/Constants.d.ts +38 -3
- package/dist/util/Constants.js +25 -6
- package/dist/util/Util.js +2 -2
- package/dist/util/raw.json +1 -1
- package/package.json +6 -59
- package/dist/client/EventManager.d.ts +0 -86
- package/dist/client/EventManager.js +0 -278
package/CHANGELOG.md
CHANGED
|
@@ -2,121 +2,138 @@
|
|
|
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
|
+
## 3.0.0 (15-10-222)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- Conflict with the same name of builder base and home base troops. (#123)
|
|
10
|
+
- Fix the issue with the `Client#getLeagueWar()` method.
|
|
11
|
+
- Typings and documentation for clan capital.
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- Support for clan capital raid seasons `Client#getCapitalRaidSeasons()`
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
- Using PascalCase instead of SCREAMING_SNAKE_CASE ([#115](https://github.com/clashperk/clashofclans.js/pull/115))
|
|
20
|
+
- `Client#events` and `EventManager` have been removed in favor of `PollingClient` ([#117](https://github.com/clashperk/clashofclans.js/pull/117), [#127](https://github.com/clashperk/clashofclans.js/pull/127))
|
|
21
|
+
|
|
5
22
|
## 2.8.0 (2022-07-22)
|
|
6
23
|
|
|
7
24
|
### Features
|
|
8
25
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
26
|
+
- Better Throttler with JS generator function. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
|
|
27
|
+
- Updated raw data from game files. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
|
|
28
|
+
- New method Util#parseArmyLink has been added. ([#110](https://github.com/clashperk/clashofclans.js/pull/110))
|
|
12
29
|
|
|
13
30
|
## 2.7.0 (2022-05-22)
|
|
14
31
|
|
|
15
32
|
### Features
|
|
16
33
|
|
|
17
|
-
-
|
|
34
|
+
- Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
|
|
18
35
|
|
|
19
36
|
## 2.6.1 (2022-02-03)
|
|
20
37
|
|
|
21
38
|
### Bug Fixes
|
|
22
39
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
40
|
+
- New value and typings `notInWar` added for `ClanWarLeagueGroup#state` ([#101](https://github.com/clashperk/clashofclans.js/pull/101))
|
|
41
|
+
- Throw error if `Util.formatTag` / `Util.parseTag` is called with invalid argument ([#102](https://github.com/clashperk/clashofclans.js/pull/101))
|
|
25
42
|
|
|
26
43
|
## 2.6.0 (2022-01-29)
|
|
27
44
|
|
|
28
45
|
## Features
|
|
29
46
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
47
|
+
- Replaced Keyv with customizable cache store ([#99](https://github.com/clashperk/clashofclans.js/pull/99))
|
|
48
|
+
- Guide for [Internal Caching](https://clashofclans.js.org/guide/internal-caching)
|
|
32
49
|
|
|
33
50
|
## 2.5.2 (2022-01-23)
|
|
34
51
|
|
|
35
52
|
### Bug Fixes
|
|
36
53
|
|
|
37
|
-
-
|
|
38
|
-
-
|
|
54
|
+
- Fix `ClanWar#attacksPerMembers` property ([#97](https://github.com/clashperk/clashofclans.js/pull/97))
|
|
55
|
+
- Bump `node-fetch` from 2.6.6 to 2.6.7 ([#96](https://github.com/clashperk/clashofclans.js/pull/96))
|
|
39
56
|
|
|
40
57
|
## 2.5.1 (2022-01-11)
|
|
41
58
|
|
|
42
59
|
### Bug Fixes
|
|
43
60
|
|
|
44
|
-
-
|
|
61
|
+
- Typings for `ClanWarLeagueGroup#state` property. ([#94](https://github.com/clashperk/clashofclans.js/pull/94))
|
|
45
62
|
|
|
46
63
|
## 2.5.0 (2021-12-30)
|
|
47
64
|
|
|
48
65
|
### Bug Fixes
|
|
49
66
|
|
|
50
|
-
-
|
|
51
|
-
-
|
|
67
|
+
- Fix caching issue with unnecessary/invalid query params. ([#91](https://github.com/clashperk/clashofclans.js/pull/91))
|
|
68
|
+
- Added necessary methods to `RESTManager` class. ([#92](https://github.com/clashperk/clashofclans.js/pull/92))
|
|
52
69
|
|
|
53
70
|
## 2.4.0 (2021-12-28)
|
|
54
71
|
|
|
55
72
|
### Features
|
|
56
73
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
74
|
+
- `ClanWar#getClanWarLeagueGroup`, `ClanWar#isCWL` and `ClanWar#isFriendly` are now available. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
75
|
+
- `RESTOptions#rejectIfNotValid` added to perform `res.ok` operations over `RESTManager` methods. [Know more?](https://clashofclans.js.org/guide/access-raw-data#easy-access) ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
76
|
+
- `Icon#fileName` and `Icon#sizes` are now available in `Icon` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
77
|
+
- `Badge#fileName` and `Badge#sizes` are now available in `Badge` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
61
78
|
|
|
62
79
|
### Deprecations
|
|
63
80
|
|
|
64
|
-
-
|
|
81
|
+
- `ClanWarMember#previousBestOpponentAttack` has been deprecated. Use `ClanWarAttack#previousBestAttack` instead. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
65
82
|
|
|
66
83
|
## 2.3.0 (2021-12-17)
|
|
67
84
|
|
|
68
85
|
### Features
|
|
69
86
|
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
-
|
|
87
|
+
- BigInt literals issue fixed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
|
|
88
|
+
- Some Utility methods renamed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
|
|
89
|
+
- `Util.encodeTag()` to `Util.encodeURI()`
|
|
90
|
+
- `Util.encodeTagToId()` to `Util.encodeTag()`
|
|
91
|
+
- `Util.decodeIdToTag()` to `Util.decodeTag()`
|
|
92
|
+
- Added `dps`, `resourceType`, `trainingTime` and `regenerationTime` to the `Unit` class. ([#85](https://github.com/clashperk/clashofclans.js/pull/85))
|
|
76
93
|
|
|
77
94
|
## 2.2.0 (2021-12-16)
|
|
78
95
|
|
|
79
96
|
### Bug Fixes
|
|
80
97
|
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
98
|
+
- Show units as per in-game orders. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
|
|
99
|
+
- Season end time utility method. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
|
|
100
|
+
- Updated raw files for new Troops. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
|
|
84
101
|
|
|
85
102
|
### Features
|
|
86
103
|
|
|
87
|
-
-
|
|
104
|
+
- Added `seasonal`, `boostable` and `isLoaded` property to `Unit` class. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
|
|
88
105
|
|
|
89
106
|
## 2.1.0 (2021-12-06)
|
|
90
107
|
|
|
91
108
|
### Bug Fixes
|
|
92
109
|
|
|
93
|
-
-
|
|
110
|
+
- Consistency of `ClanWar.attacksPerMember` property. ([#75](https://github.com/clashperk/clashofclans.js/pull/75)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/6e23d2fe0373f56268ffa55d5ac2807c9a2dc2fc))
|
|
94
111
|
|
|
95
112
|
### Features
|
|
96
113
|
|
|
97
|
-
-
|
|
114
|
+
- More utility methods added to `Util` class. ([#76](https://github.com/clashperk/clashofclans.js/pull/76)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/ff4111530d6293ef1fc54aa916436130fc30a09c))
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
- `Util.formatTag(tag: string): string`
|
|
117
|
+
- `Util.formatDate(date: string): Date`
|
|
118
|
+
- `Util.isValidTag(tag: string): boolean`
|
|
119
|
+
- `Util.encodeTagToId(tag: string): string` (Removed on 2.3.0)
|
|
120
|
+
- `Util.decodeIdToTag(id: string): string` (Removed on 2.3.0)
|
|
104
121
|
|
|
105
|
-
-
|
|
122
|
+
- Support of async/await for custom events ([#79](https://github.com/clashperk/clashofclans.js/pull/79)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/a23db3786bcca44b8547c70f27773bdb1216f990))
|
|
106
123
|
|
|
107
124
|
## 2.0.2 (2021-11-30)
|
|
108
125
|
|
|
109
126
|
### Bug Fixes
|
|
110
127
|
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
128
|
+
- Return `null` for `RankedPlayer.clan` if they are not in the clan. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
|
|
129
|
+
- `OverrideOptions` added for `Client#getClans` and `RESTManager#getClans` ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
|
|
130
|
+
- `SeasonRankedPlayer` class for legend league ranking. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
|
|
114
131
|
|
|
115
132
|
## 2.0.1 (2021-11-27)
|
|
116
133
|
|
|
117
134
|
### Bug Fixes
|
|
118
135
|
|
|
119
|
-
-
|
|
136
|
+
- IP retrieval method and Event Loop ([#70](https://github.com/clashperk/clashofclans.js/issues/70)) ([82b84ba](https://github.com/clashperk/clashofclans.js/commit/82b84ba5d96505c43b75e53aa07f547ef0b77778))
|
|
120
137
|
|
|
121
138
|
## 2.0.0 (2021-11-26)
|
|
122
139
|
|
|
@@ -124,10 +141,10 @@ This new version is a complete TypeScript rewrite to convert everything from pla
|
|
|
124
141
|
|
|
125
142
|
### Features
|
|
126
143
|
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
144
|
+
- HTTP Request Request Retries ([#26](https://github.com/clashperk/clashofclans.js/issues/26)) ([94585f3](https://github.com/clashperk/clashofclans.js/commit/94585f3a84a7175b2d07872f9eb9e42372b95e12))
|
|
145
|
+
- Event Manager and Custom Events ([#37](https://github.com/clashperk/clashofclans.js/issues/37)) ([5027ae6](https://github.com/clashperk/clashofclans.js/commit/5027ae663a8e07175e17384c7e5706f4a1a7afb4))
|
|
146
|
+
- Email Password Login ([#31](https://github.com/clashperk/clashofclans.js/issues/31)) ([4153cd3](https://github.com/clashperk/clashofclans.js/commit/4153cd37ea0e1c71550b9e892105b84d5a407e23))
|
|
147
|
+
- Queue Throttler and Batch Throttler ([#34](https://github.com/clashperk/clashofclans.js/issues/34)) ([3a8f051](https://github.com/clashperk/clashofclans.js/commit/3a8f051552e93b98f89bc7d524acdecddf242718))
|
|
148
|
+
- Override Request Options ([#36](https://github.com/clashperk/clashofclans.js/issues/36)) ([42d7fdd](https://github.com/clashperk/clashofclans.js/commit/42d7fdd36262cc46f23b731f8cffb9daea19d3b0))
|
|
149
|
+
- Internal Caching Options ([#53](https://github.com/clashperk/clashofclans.js/issues/53)) ([984451d](https://github.com/clashperk/clashofclans.js/commit/30ea3240c11866008d0dae514468c0fdbb34ffd0))
|
|
150
|
+
- Additional Properties for Player Units ([#65](https://github.com/clashperk/clashofclans.js/pull/65)) ([aa1696](https://github.com/clashperk/clashofclans.js/commit/aa1696243d96d4fed0250b4282c60522a6482343))
|
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
```js
|
|
26
26
|
const { Client } = require('clashofclans.js');
|
|
27
27
|
const client = new Client();
|
|
28
|
+
// const client = new Client({ keys: [], cache: true, retryLimit: 2, restRequestTimeout: 5000 });
|
|
28
29
|
|
|
29
30
|
(async function () {
|
|
30
31
|
await client.login({ email: 'developer@email.com', password: '***' });
|
|
@@ -34,32 +35,35 @@ const client = new Client();
|
|
|
34
35
|
})();
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
### Custom Event
|
|
38
|
+
### Custom Polling Event
|
|
39
|
+
|
|
40
|
+
> **Warning** <br>
|
|
41
|
+
> Events are neither real-time nor supported by the API. They are polled frequently and compared with the cached data. If there is a difference, the event is emitted.
|
|
38
42
|
|
|
39
43
|
```js
|
|
40
|
-
const {
|
|
41
|
-
const
|
|
44
|
+
const { PollingClient, BatchThrottler } = require('clashofclans.js');
|
|
45
|
+
const pollingClient = new PollingClient({
|
|
42
46
|
cache: true,
|
|
43
47
|
retryLimit: 1,
|
|
44
48
|
restRequestTimeout: 5000,
|
|
45
49
|
throttler: new BatchThrottler(20)
|
|
46
50
|
});
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
pollingClient.addClans(['#8QU8J9LP', '#8P2QG08P']);
|
|
53
|
+
pollingClient.setClanEvent({
|
|
50
54
|
name: 'clanDescriptionChange',
|
|
51
55
|
filter: (oldClan, newClan) => {
|
|
52
56
|
return oldClan.description !== newClan.description;
|
|
53
57
|
}
|
|
54
58
|
});
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
pollingClient.on('clanDescriptionChange', (oldClan, newClan) => {
|
|
57
61
|
console.log(oldClan.description, newClan.description);
|
|
58
62
|
});
|
|
59
63
|
|
|
60
64
|
(async function () {
|
|
61
|
-
await
|
|
62
|
-
await
|
|
65
|
+
await pollingClient.login({ email: 'developer@email.com', password: '***' });
|
|
66
|
+
await pollingClient.init();
|
|
63
67
|
})();
|
|
64
68
|
```
|
|
65
69
|
|
package/dist/client/Client.d.ts
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
2
3
|
import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
|
|
3
|
-
import { CWLRounds } from '../util/Constants';
|
|
4
|
+
import { CWLRounds, ClientEvents } from '../util/Constants';
|
|
4
5
|
import { RESTManager } from '../rest/RESTManager';
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
6
6
|
import { Util } from '../util/Util';
|
|
7
7
|
import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, SeasonRankedPlayer, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
|
|
8
|
+
import { CapitalRaidSeason } from '../struct/CapitalRaidSeason';
|
|
9
|
+
interface IClientEvents {
|
|
10
|
+
[ClientEvents.Error]: [error: unknown];
|
|
11
|
+
[ClientEvents.Debug]: [path: string, status: string, message: string];
|
|
12
|
+
}
|
|
13
|
+
export interface Client {
|
|
14
|
+
emit: (<K extends keyof IClientEvents>(event: K, ...args: IClientEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, ...args: any[]) => boolean);
|
|
15
|
+
off: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
|
|
16
|
+
on: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
|
|
17
|
+
once: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
|
|
18
|
+
removeAllListeners: (<K extends keyof IClientEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IClientEvents>) => this);
|
|
19
|
+
/**
|
|
20
|
+
* Emitted for general debugging information.
|
|
21
|
+
* @public
|
|
22
|
+
* @event
|
|
23
|
+
*/
|
|
24
|
+
debug: string;
|
|
25
|
+
/**
|
|
26
|
+
* Emitted when the client encounters an error.
|
|
27
|
+
* @public
|
|
28
|
+
* @event
|
|
29
|
+
*/
|
|
30
|
+
error: string;
|
|
31
|
+
}
|
|
8
32
|
/**
|
|
9
33
|
* Represents Clash of Clans API Client.
|
|
10
34
|
* ```js
|
|
@@ -35,6 +59,8 @@ export declare class Client extends EventEmitter {
|
|
|
35
59
|
getClan(clanTag: string, options?: OverrideOptions): Promise<Clan>;
|
|
36
60
|
/** Get list of clan members. */
|
|
37
61
|
getClanMembers(clanTag: string, options?: SearchOptions): Promise<ClanMember[]>;
|
|
62
|
+
/** Get capital raid seasons. */
|
|
63
|
+
getCapitalRaidSeasons(tag: string, options?: SearchOptions): Promise<CapitalRaidSeason[]>;
|
|
38
64
|
/** Get clan war log. */
|
|
39
65
|
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<ClanWarLog[]>;
|
|
40
66
|
/** Get info about currently running war (normal or friendly) in the clan. */
|
|
@@ -127,3 +153,4 @@ export declare class Client extends EventEmitter {
|
|
|
127
153
|
/** Get info about gold pass season. */
|
|
128
154
|
getGoldPassSeason(options?: OverrideOptions): Promise<GoldPassSeason>;
|
|
129
155
|
}
|
|
156
|
+
export {};
|
package/dist/client/Client.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Client = void 0;
|
|
4
|
+
const node_events_1 = require("node:events");
|
|
4
5
|
const Constants_1 = require("../util/Constants");
|
|
5
6
|
const HTTPError_1 = require("../rest/HTTPError");
|
|
6
7
|
const RESTManager_1 = require("../rest/RESTManager");
|
|
7
|
-
const events_1 = require("events");
|
|
8
8
|
const Util_1 = require("../util/Util");
|
|
9
9
|
const struct_1 = require("../struct");
|
|
10
|
+
const CapitalRaidSeason_1 = require("../struct/CapitalRaidSeason");
|
|
10
11
|
/**
|
|
11
12
|
* Represents Clash of Clans API Client.
|
|
12
13
|
* ```js
|
|
@@ -14,10 +15,12 @@ const struct_1 = require("../struct");
|
|
|
14
15
|
* const client = new Client({ keys: ['***'] });
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
|
-
class Client extends
|
|
18
|
+
class Client extends node_events_1.EventEmitter {
|
|
18
19
|
constructor(options) {
|
|
19
20
|
super();
|
|
20
|
-
this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true })
|
|
21
|
+
this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true })
|
|
22
|
+
.on(Constants_1.RestEvents.Debug, this.emit.bind(this, Constants_1.RestEvents.Debug))
|
|
23
|
+
.on(Constants_1.RestEvents.Error, this.emit.bind(this, Constants_1.RestEvents.Error));
|
|
21
24
|
}
|
|
22
25
|
/** Contains various general-purpose utility methods. */
|
|
23
26
|
get util() {
|
|
@@ -32,11 +35,11 @@ class Client extends events_1.EventEmitter {
|
|
|
32
35
|
* ```
|
|
33
36
|
*/
|
|
34
37
|
login(options) {
|
|
35
|
-
return this.rest.
|
|
38
|
+
return this.rest.requestHandler.init(options);
|
|
36
39
|
}
|
|
37
40
|
/** Set Clash of Clans API keys. */
|
|
38
41
|
setKeys(keys) {
|
|
39
|
-
this.rest.
|
|
42
|
+
this.rest.requestHandler.setKeys(keys);
|
|
40
43
|
return this;
|
|
41
44
|
}
|
|
42
45
|
/** Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel). */
|
|
@@ -60,6 +63,11 @@ class Client extends events_1.EventEmitter {
|
|
|
60
63
|
const { data } = await this.rest.getClanMembers(clanTag, options);
|
|
61
64
|
return data.items.map((entry) => new struct_1.ClanMember(this, entry));
|
|
62
65
|
}
|
|
66
|
+
/** Get capital raid seasons. */
|
|
67
|
+
async getCapitalRaidSeasons(tag, options) {
|
|
68
|
+
const { data } = await this.rest.getCapitalRaidSeasons(tag, options);
|
|
69
|
+
return data.items.map((entry) => new CapitalRaidSeason_1.CapitalRaidSeason(entry));
|
|
70
|
+
}
|
|
63
71
|
/** Get clan war log. */
|
|
64
72
|
async getClanWarLog(clanTag, options) {
|
|
65
73
|
const { data } = await this.rest.getClanWarLog(clanTag, options);
|
|
@@ -140,7 +148,7 @@ class Client extends events_1.EventEmitter {
|
|
|
140
148
|
return [await this.getClanWar(clanTag, options)];
|
|
141
149
|
}
|
|
142
150
|
try {
|
|
143
|
-
return this.getLeagueWars(clanTag, options);
|
|
151
|
+
return await this.getLeagueWars(clanTag, options);
|
|
144
152
|
}
|
|
145
153
|
catch (e) {
|
|
146
154
|
if (e instanceof HTTPError_1.HTTPError && [404].includes(e.status)) {
|
|
@@ -2,20 +2,101 @@ import { Clan, ClanWar, Player } from '../struct';
|
|
|
2
2
|
import { ClientOptions } from '../types';
|
|
3
3
|
import { PollingEvents } from '../util/Constants';
|
|
4
4
|
import { Client } from './Client';
|
|
5
|
-
import { PollingEventManager } from './EventManager';
|
|
6
5
|
/**
|
|
7
6
|
* Represents Clash of Clans Polling Event Client.
|
|
8
7
|
* ```js
|
|
9
8
|
* const { PollingClient } = require('clashofclans.js');
|
|
10
|
-
* const
|
|
9
|
+
* const pollingClient = new PollingClient({ keys: ['***'] });
|
|
11
10
|
* ```
|
|
12
11
|
*/
|
|
13
12
|
export declare class PollingClient extends Client {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
private readonly _clanTags;
|
|
14
|
+
private readonly _playerTags;
|
|
15
|
+
private readonly _warTags;
|
|
16
|
+
private readonly _clans;
|
|
17
|
+
private readonly _players;
|
|
18
|
+
private readonly _wars;
|
|
19
|
+
private readonly _pollingEvents;
|
|
20
|
+
inMaintenance: boolean;
|
|
21
|
+
private _maintenanceStartTime;
|
|
16
22
|
constructor(options?: ClientOptions);
|
|
17
|
-
/**
|
|
18
|
-
|
|
23
|
+
/** Initialize the PollingEvent Manager to start pulling the data by polling api. */
|
|
24
|
+
init(): Promise<string[]>;
|
|
25
|
+
/** Add clan tags to clan polling events. */
|
|
26
|
+
addClans(tags: string[] | string): this;
|
|
27
|
+
/** Delete clan tags from clan polling events. */
|
|
28
|
+
deleteClans(tags: string[] | string): this;
|
|
29
|
+
/** Add player tags for player polling events. */
|
|
30
|
+
addPlayers(tags: string[] | string): this;
|
|
31
|
+
/** Delete player tags from player polling events. */
|
|
32
|
+
deletePlayers(tags: string[] | string): this;
|
|
33
|
+
/** Add clan tags for war polling events. */
|
|
34
|
+
addWars(tags: string[] | string): this;
|
|
35
|
+
/** Delete clan tags from war polling events. */
|
|
36
|
+
deleteWars(tags: string[] | string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Set your own custom clan polling event.
|
|
39
|
+
*
|
|
40
|
+
* In order to emit the custom polling event, you must have this filter function that returns a boolean.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```js
|
|
44
|
+
* client.addClans(['#2PP', '#8QU8J9LP']);
|
|
45
|
+
*
|
|
46
|
+
* client.setClanEvent({
|
|
47
|
+
* name: 'clanMemberUpdate',
|
|
48
|
+
* filter: (oldClan, newClan) => {
|
|
49
|
+
* return oldClan.memberCount !== newClan.memberCount;
|
|
50
|
+
* }
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* client.on('clanMemberUpdate', (oldClan, newClan) => {
|
|
54
|
+
* console.log(oldClan.memberCount, newClan.memberCount);
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* (async function () {
|
|
58
|
+
* await client.init();
|
|
59
|
+
* })();
|
|
60
|
+
* ```
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
setClanEvent(event: {
|
|
64
|
+
name: string;
|
|
65
|
+
filter: (oldClan: Clan, newClan: Clan) => boolean;
|
|
66
|
+
}): this;
|
|
67
|
+
/**
|
|
68
|
+
* Set your own custom war event.
|
|
69
|
+
*
|
|
70
|
+
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
71
|
+
*/
|
|
72
|
+
setWarEvent(event: {
|
|
73
|
+
name: string;
|
|
74
|
+
filter: (oldWar: ClanWar, newWar: ClanWar) => boolean;
|
|
75
|
+
}): this;
|
|
76
|
+
/**
|
|
77
|
+
* Set your own custom player event.
|
|
78
|
+
*
|
|
79
|
+
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
80
|
+
*/
|
|
81
|
+
setPlayerEvent(event: {
|
|
82
|
+
name: string;
|
|
83
|
+
filter: (oldPlayer: Player, newPlayer: Player) => boolean;
|
|
84
|
+
}): this;
|
|
85
|
+
private maintenanceHandler;
|
|
86
|
+
private seasonEndHandler;
|
|
87
|
+
private clanUpdateHandler;
|
|
88
|
+
private playerUpdateHandler;
|
|
89
|
+
private warUpdateHandler;
|
|
90
|
+
private runClanUpdate;
|
|
91
|
+
private runPlayerUpdate;
|
|
92
|
+
private runWarUpdate;
|
|
93
|
+
}
|
|
94
|
+
export interface PollingClient {
|
|
95
|
+
emit: (<K extends keyof IPollingEvents>(event: K, ...args: IPollingEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, ...args: any[]) => boolean);
|
|
96
|
+
off: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
|
|
97
|
+
on: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
|
|
98
|
+
once: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
|
|
99
|
+
removeAllListeners: (<K extends keyof IPollingEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IPollingEvents>) => this);
|
|
19
100
|
/**
|
|
20
101
|
* Emits when a new season starts.
|
|
21
102
|
*
|
|
@@ -27,13 +108,13 @@ export declare class PollingClient extends Client {
|
|
|
27
108
|
* @public
|
|
28
109
|
* @event
|
|
29
110
|
*/
|
|
30
|
-
|
|
111
|
+
newSeasonStart: string;
|
|
31
112
|
/**
|
|
32
113
|
* Emits when maintenance break starts in the API.
|
|
33
114
|
* @public
|
|
34
115
|
* @event
|
|
35
116
|
*/
|
|
36
|
-
|
|
117
|
+
maintenanceStart: string;
|
|
37
118
|
/**
|
|
38
119
|
* Emits when maintenance break ends in the API.
|
|
39
120
|
*
|
|
@@ -45,39 +126,31 @@ export declare class PollingClient extends Client {
|
|
|
45
126
|
* @public
|
|
46
127
|
* @event
|
|
47
128
|
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
129
|
+
maintenanceEnd: string;
|
|
130
|
+
/**
|
|
131
|
+
* Emitted for general debugging information.
|
|
132
|
+
* @public
|
|
133
|
+
* @event
|
|
134
|
+
*/
|
|
135
|
+
debug: string;
|
|
136
|
+
/**
|
|
137
|
+
* Emitted when the client encounters an error.
|
|
138
|
+
* @public
|
|
139
|
+
* @event
|
|
140
|
+
*/
|
|
141
|
+
error: string;
|
|
64
142
|
}
|
|
65
|
-
interface
|
|
66
|
-
[PollingEvents.NewSeasonStart]: [id: string];
|
|
67
|
-
[PollingEvents.MaintenanceStart]: [];
|
|
68
|
-
[PollingEvents.MaintenanceEnd]: [duration: number];
|
|
143
|
+
interface IPollingEvents {
|
|
69
144
|
[PollingEvents.ClanLoopStart]: [];
|
|
70
145
|
[PollingEvents.ClanLoopEnd]: [];
|
|
71
146
|
[PollingEvents.PlayerLoopStart]: [];
|
|
72
147
|
[PollingEvents.PlayerLoopEnd]: [];
|
|
73
148
|
[PollingEvents.WarLoopStart]: [];
|
|
74
149
|
[PollingEvents.WarLoopEnd]: [];
|
|
150
|
+
[PollingEvents.NewSeasonStart]: [id: string];
|
|
151
|
+
[PollingEvents.MaintenanceStart]: [];
|
|
152
|
+
[PollingEvents.MaintenanceEnd]: [duration: number];
|
|
75
153
|
[PollingEvents.Error]: [error: unknown];
|
|
76
154
|
[PollingEvents.Debug]: [path: string, status: string, message: string];
|
|
77
155
|
}
|
|
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
156
|
export {};
|