clashofclans.js 3.0.0-dev.392ca4c → 3.0.0-dev.577f128
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 +66 -47
- package/README.md +12 -8
- package/dist/client/Client.d.ts +38 -3
- package/dist/client/Client.js +32 -19
- package/dist/client/PollingClient.d.ts +107 -34
- package/dist/client/PollingClient.js +269 -8
- package/dist/index.d.ts +0 -1
- package/dist/index.js +5 -2
- package/dist/index.mjs +5 -2
- package/dist/rest/HTTPError.d.ts +0 -4
- package/dist/rest/HTTPError.js +1 -5
- package/dist/rest/RESTManager.d.ts +46 -5
- package/dist/rest/RESTManager.js +55 -30
- package/dist/rest/RequestHandler.d.ts +30 -2
- package/dist/rest/RequestHandler.js +69 -33
- package/dist/struct/CapitalRaidSeason.d.ts +49 -0
- package/dist/struct/CapitalRaidSeason.js +40 -0
- package/dist/struct/Clan.d.ts +8 -2
- package/dist/struct/Clan.js +3 -0
- package/dist/struct/ClanCapital.js +1 -1
- package/dist/struct/ClanMember.d.ts +3 -1
- package/dist/struct/ClanMember.js +1 -0
- package/dist/struct/ClanWar.d.ts +15 -3
- package/dist/struct/ClanWar.js +26 -15
- package/dist/struct/Player.d.ts +4 -2
- package/dist/struct/Player.js +1 -0
- 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.d.ts +2 -0
- package/dist/struct/index.js +7 -1
- package/dist/types/api.d.ts +93 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clashofclans.js",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.577f128",
|
|
4
4
|
"description": "JavaScript library for interacting with the Clash of Clans API",
|
|
5
5
|
"author": "SUVAJIT <suvajit.me@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,61 +34,6 @@
|
|
|
34
34
|
"url": "https://github.com/clashperk/clashofclans.js/issues"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://clashofclans.js.org",
|
|
37
|
-
"eslintConfig": {
|
|
38
|
-
"extends": [
|
|
39
|
-
"marine/prettier/node",
|
|
40
|
-
"plugin:prettier/recommended"
|
|
41
|
-
],
|
|
42
|
-
"plugins": [
|
|
43
|
-
"prettier"
|
|
44
|
-
],
|
|
45
|
-
"ignorePatterns": [
|
|
46
|
-
"dist/*",
|
|
47
|
-
"docs/*"
|
|
48
|
-
],
|
|
49
|
-
"parser": "@typescript-eslint/parser",
|
|
50
|
-
"rules": {
|
|
51
|
-
"no-process-env": 0,
|
|
52
|
-
"no-inline-comments": 0,
|
|
53
|
-
"no-warning-comments": 0,
|
|
54
|
-
"comma-dangle": [
|
|
55
|
-
"error",
|
|
56
|
-
"never"
|
|
57
|
-
],
|
|
58
|
-
"@typescript-eslint/naming-convention": 0,
|
|
59
|
-
"@typescript-eslint/no-floating-promises": 0,
|
|
60
|
-
"@typescript-eslint/no-misused-promises": 0
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"prettier": {
|
|
64
|
-
"semi": true,
|
|
65
|
-
"tabWidth": 4,
|
|
66
|
-
"printWidth": 140,
|
|
67
|
-
"singleQuote": true,
|
|
68
|
-
"quoteProps": "consistent",
|
|
69
|
-
"bracketSpacing": true,
|
|
70
|
-
"trailingComma": "none",
|
|
71
|
-
"overrides": [
|
|
72
|
-
{
|
|
73
|
-
"files": [
|
|
74
|
-
"*.md"
|
|
75
|
-
],
|
|
76
|
-
"options": {
|
|
77
|
-
"useTabs": false,
|
|
78
|
-
"tabWidth": 4
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"files": [
|
|
83
|
-
"*.yml"
|
|
84
|
-
],
|
|
85
|
-
"options": {
|
|
86
|
-
"useTabs": false,
|
|
87
|
-
"tabWidth": 2
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
},
|
|
92
37
|
"standard-version": {
|
|
93
38
|
"skip": {
|
|
94
39
|
"changelog": false,
|
|
@@ -100,18 +45,20 @@
|
|
|
100
45
|
"node-fetch": "^2.6.7"
|
|
101
46
|
},
|
|
102
47
|
"devDependencies": {
|
|
103
|
-
"@types/node": "^16.10.3",
|
|
104
48
|
"@types/node-fetch": "^2.5.12",
|
|
49
|
+
"gen-esm-wrapper": "^1.1.3",
|
|
50
|
+
"@types/node": "^18.6.4",
|
|
105
51
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
106
52
|
"@typescript-eslint/parser": "^5.4.0",
|
|
53
|
+
"dotenv": "^16.0.2",
|
|
107
54
|
"eslint": "^8.3.0",
|
|
108
55
|
"eslint-config-marine": "^9.0.6",
|
|
109
56
|
"eslint-config-prettier": "^8.3.0",
|
|
57
|
+
"eslint-plugin-import": "^2.26.0",
|
|
110
58
|
"eslint-plugin-prettier": "^4.0.0",
|
|
111
|
-
"gen-esm-wrapper": "^1.1.3",
|
|
112
59
|
"prettier": "^2.4.1",
|
|
113
60
|
"rimraf": "^3.0.2",
|
|
114
|
-
"typescript": "^4.
|
|
61
|
+
"typescript": "^4.7.4"
|
|
115
62
|
},
|
|
116
63
|
"engines": {
|
|
117
64
|
"node": ">=14.x"
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Clan, ClanWar, Player } from '../struct';
|
|
2
|
-
import { PollingClient } from './PollingClient';
|
|
3
|
-
/** Represents PollingEvent Manager of the {@link PollingClient}. */
|
|
4
|
-
export declare class PollingEventManager {
|
|
5
|
-
private readonly pollingClient;
|
|
6
|
-
private readonly _clanTags;
|
|
7
|
-
private readonly _playerTags;
|
|
8
|
-
private readonly _warTags;
|
|
9
|
-
private readonly _clans;
|
|
10
|
-
private readonly _players;
|
|
11
|
-
private readonly _wars;
|
|
12
|
-
private readonly _pollingEvents;
|
|
13
|
-
private _inMaintenance;
|
|
14
|
-
private _maintenanceStartTime;
|
|
15
|
-
constructor(pollingClient: PollingClient);
|
|
16
|
-
/** Initialize the PollingEvent Manager to start pulling the data by polling api. */
|
|
17
|
-
init(): Promise<string[]>;
|
|
18
|
-
/** Add clan tags to clan polling events. */
|
|
19
|
-
addClans(tags: string[] | string): this;
|
|
20
|
-
/** Delete clan tags from clan polling events. */
|
|
21
|
-
deleteClans(tags: string[] | string): this;
|
|
22
|
-
/** Add player tags for player polling events. */
|
|
23
|
-
addPlayers(tags: string[] | string): this;
|
|
24
|
-
/** Delete player tags from player polling events. */
|
|
25
|
-
deletePlayers(tags: string[] | string): this;
|
|
26
|
-
/** Add clan tags for war polling events. */
|
|
27
|
-
addWars(tags: string[] | string): this;
|
|
28
|
-
/** Delete clan tags from war polling events. */
|
|
29
|
-
deleteWars(tags: string[] | string): this;
|
|
30
|
-
/**
|
|
31
|
-
* Set your own custom clan polling event.
|
|
32
|
-
*
|
|
33
|
-
* In order to emit the custom polling event, you must have this filter function that returns a boolean.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```js
|
|
37
|
-
* client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
|
|
38
|
-
*
|
|
39
|
-
* client.pollingEvents.setClanEvent({
|
|
40
|
-
* name: 'clanMemberUpdate',
|
|
41
|
-
* filter: (oldClan, newClan) => {
|
|
42
|
-
* return oldClan.memberCount !== newClan.memberCount;
|
|
43
|
-
* }
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* client.on('clanMemberUpdate', (oldClan, newClan) => {
|
|
47
|
-
* console.log(oldClan.memberCount, newClan.memberCount);
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* (async function () {
|
|
51
|
-
* await client.pollingEvents.init();
|
|
52
|
-
* })();
|
|
53
|
-
* ```
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
setClanEvent(event: {
|
|
57
|
-
name: string;
|
|
58
|
-
filter: (oldClan: Clan, newClan: Clan) => boolean;
|
|
59
|
-
}): this;
|
|
60
|
-
/**
|
|
61
|
-
* Set your own custom war event.
|
|
62
|
-
*
|
|
63
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
64
|
-
*/
|
|
65
|
-
setWarEvent(event: {
|
|
66
|
-
name: string;
|
|
67
|
-
filter: (oldWar: ClanWar, newWar: ClanWar) => boolean;
|
|
68
|
-
}): this;
|
|
69
|
-
/**
|
|
70
|
-
* Set your own custom player event.
|
|
71
|
-
*
|
|
72
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
73
|
-
*/
|
|
74
|
-
setPlayerEvent(event: {
|
|
75
|
-
name: string;
|
|
76
|
-
filter: (oldPlayer: Player, newPlayer: Player) => boolean;
|
|
77
|
-
}): this;
|
|
78
|
-
private maintenanceHandler;
|
|
79
|
-
private seasonEndHandler;
|
|
80
|
-
private clanUpdateHandler;
|
|
81
|
-
private playerUpdateHandler;
|
|
82
|
-
private warUpdateHandler;
|
|
83
|
-
private runClanUpdate;
|
|
84
|
-
private runPlayerUpdate;
|
|
85
|
-
private runWarUpdate;
|
|
86
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PollingEventManager = void 0;
|
|
4
|
-
const HTTPError_1 = require("../rest/HTTPError");
|
|
5
|
-
const Constants_1 = require("../util/Constants");
|
|
6
|
-
const Util_1 = require("../util/Util");
|
|
7
|
-
/** Represents PollingEvent Manager of the {@link PollingClient}. */
|
|
8
|
-
class PollingEventManager {
|
|
9
|
-
constructor(pollingClient) {
|
|
10
|
-
this.pollingClient = pollingClient;
|
|
11
|
-
this._clanTags = new Set();
|
|
12
|
-
this._playerTags = new Set();
|
|
13
|
-
this._warTags = new Set();
|
|
14
|
-
this._clans = new Map();
|
|
15
|
-
this._players = new Map();
|
|
16
|
-
this._wars = new Map();
|
|
17
|
-
this._pollingEvents = {
|
|
18
|
-
clans: [],
|
|
19
|
-
wars: [],
|
|
20
|
-
players: []
|
|
21
|
-
};
|
|
22
|
-
this._inMaintenance = Boolean(false);
|
|
23
|
-
this._maintenanceStartTime = null;
|
|
24
|
-
}
|
|
25
|
-
/** Initialize the PollingEvent Manager to start pulling the data by polling api. */
|
|
26
|
-
async init() {
|
|
27
|
-
this.seasonEndHandler();
|
|
28
|
-
this.maintenanceHandler();
|
|
29
|
-
this.clanUpdateHandler();
|
|
30
|
-
this.playerUpdateHandler();
|
|
31
|
-
this.warUpdateHandler();
|
|
32
|
-
return Promise.resolve(this.pollingClient.eventNames());
|
|
33
|
-
}
|
|
34
|
-
/** Add clan tags to clan polling events. */
|
|
35
|
-
addClans(tags) {
|
|
36
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
37
|
-
this._clanTags.add(this.pollingClient.util.formatTag(tag));
|
|
38
|
-
}
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
/** Delete clan tags from clan polling events. */
|
|
42
|
-
deleteClans(tags) {
|
|
43
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
44
|
-
const key = this.pollingClient.util.formatTag(tag);
|
|
45
|
-
this._clans.delete(key);
|
|
46
|
-
this._clanTags.delete(key);
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
/** Add player tags for player polling events. */
|
|
51
|
-
addPlayers(tags) {
|
|
52
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
53
|
-
this._playerTags.add(this.pollingClient.util.formatTag(tag));
|
|
54
|
-
}
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/** Delete player tags from player polling events. */
|
|
58
|
-
deletePlayers(tags) {
|
|
59
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
60
|
-
const key = this.pollingClient.util.formatTag(tag);
|
|
61
|
-
this._players.delete(key);
|
|
62
|
-
this._playerTags.delete(key);
|
|
63
|
-
}
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
/** Add clan tags for war polling events. */
|
|
67
|
-
addWars(tags) {
|
|
68
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
69
|
-
this._warTags.add(this.pollingClient.util.formatTag(tag));
|
|
70
|
-
}
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/** Delete clan tags from war polling events. */
|
|
74
|
-
deleteWars(tags) {
|
|
75
|
-
for (const tag of Array.isArray(tags) ? tags : [tags]) {
|
|
76
|
-
const key = this.pollingClient.util.formatTag(tag);
|
|
77
|
-
this._wars.delete(`${key}:${1}`);
|
|
78
|
-
this._wars.delete(`${key}:${2}`);
|
|
79
|
-
this._warTags.delete(key);
|
|
80
|
-
}
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Set your own custom clan polling event.
|
|
85
|
-
*
|
|
86
|
-
* In order to emit the custom polling event, you must have this filter function that returns a boolean.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```js
|
|
90
|
-
* client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
|
|
91
|
-
*
|
|
92
|
-
* client.pollingEvents.setClanEvent({
|
|
93
|
-
* name: 'clanMemberUpdate',
|
|
94
|
-
* filter: (oldClan, newClan) => {
|
|
95
|
-
* return oldClan.memberCount !== newClan.memberCount;
|
|
96
|
-
* }
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* client.on('clanMemberUpdate', (oldClan, newClan) => {
|
|
100
|
-
* console.log(oldClan.memberCount, newClan.memberCount);
|
|
101
|
-
* });
|
|
102
|
-
*
|
|
103
|
-
* (async function () {
|
|
104
|
-
* await client.pollingEvents.init();
|
|
105
|
-
* })();
|
|
106
|
-
* ```
|
|
107
|
-
* @returns
|
|
108
|
-
*/
|
|
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.');
|
|
114
|
-
this._pollingEvents.clans.push(event);
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Set your own custom war event.
|
|
119
|
-
*
|
|
120
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
121
|
-
*/
|
|
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.');
|
|
127
|
-
this._pollingEvents.wars.push(event);
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Set your own custom player event.
|
|
132
|
-
*
|
|
133
|
-
* In order to emit the custom event, you must have this filter function that returns a boolean.
|
|
134
|
-
*/
|
|
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.');
|
|
140
|
-
this._pollingEvents.players.push(event);
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
async maintenanceHandler() {
|
|
144
|
-
setTimeout(this.maintenanceHandler.bind(this), 10000).unref();
|
|
145
|
-
try {
|
|
146
|
-
const res = await this.pollingClient.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
|
|
147
|
-
if (res.status === 200 && this._inMaintenance) {
|
|
148
|
-
this._inMaintenance = Boolean(false);
|
|
149
|
-
const duration = Date.now() - this._maintenanceStartTime.getTime();
|
|
150
|
-
this._maintenanceStartTime = null;
|
|
151
|
-
this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceEnd, duration);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
if (error instanceof HTTPError_1.HTTPError && error.status === 503 && !this._inMaintenance) {
|
|
156
|
-
this._inMaintenance = Boolean(true);
|
|
157
|
-
this._maintenanceStartTime = new Date();
|
|
158
|
-
this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceStart);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
seasonEndHandler() {
|
|
163
|
-
const end = Util_1.Util.getSeasonEndTime().getTime() - Date.now();
|
|
164
|
-
// Why this? setTimeout can be up to 24.8 days or 2147483647ms [(2^31 - 1) Max 32bit Integer]
|
|
165
|
-
if (end > 24 * 60 * 60 * 1000) {
|
|
166
|
-
setTimeout(this.seasonEndHandler.bind(this), 60 * 60 * 1000);
|
|
167
|
-
}
|
|
168
|
-
else if (end > 0) {
|
|
169
|
-
setTimeout(() => {
|
|
170
|
-
this.pollingClient.emit(Constants_1.PollingEvents.NewSeasonStart, Util_1.Util.getSeasonId());
|
|
171
|
-
}, end + 100).unref();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async clanUpdateHandler() {
|
|
175
|
-
this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopStart);
|
|
176
|
-
for (const tag of this._clanTags)
|
|
177
|
-
await this.runClanUpdate(tag);
|
|
178
|
-
this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopEnd);
|
|
179
|
-
setTimeout(this.clanUpdateHandler.bind(this), 10000);
|
|
180
|
-
}
|
|
181
|
-
async playerUpdateHandler() {
|
|
182
|
-
this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopStart);
|
|
183
|
-
for (const tag of this._playerTags)
|
|
184
|
-
await this.runPlayerUpdate(tag);
|
|
185
|
-
this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopEnd);
|
|
186
|
-
setTimeout(this.playerUpdateHandler.bind(this), 10000);
|
|
187
|
-
}
|
|
188
|
-
async warUpdateHandler() {
|
|
189
|
-
this.pollingClient.emit(Constants_1.PollingEvents.WarLoopStart);
|
|
190
|
-
for (const tag of this._warTags)
|
|
191
|
-
await this.runWarUpdate(tag);
|
|
192
|
-
this.pollingClient.emit(Constants_1.PollingEvents.WarLoopEnd);
|
|
193
|
-
setTimeout(this.warUpdateHandler.bind(this), 10000);
|
|
194
|
-
}
|
|
195
|
-
async runClanUpdate(tag) {
|
|
196
|
-
if (this._inMaintenance)
|
|
197
|
-
return null;
|
|
198
|
-
const clan = await this.pollingClient.getClan(tag).catch(() => null);
|
|
199
|
-
if (!clan)
|
|
200
|
-
return null;
|
|
201
|
-
const cached = this._clans.get(clan.tag);
|
|
202
|
-
if (!cached)
|
|
203
|
-
return this._clans.set(clan.tag, clan);
|
|
204
|
-
for (const { name, filter } of this._pollingEvents.clans) {
|
|
205
|
-
try {
|
|
206
|
-
if (!(await filter(cached, clan)))
|
|
207
|
-
continue;
|
|
208
|
-
this.pollingClient.emit(name, cached, clan);
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return this._clans.set(clan.tag, clan);
|
|
215
|
-
}
|
|
216
|
-
async runPlayerUpdate(tag) {
|
|
217
|
-
if (this._inMaintenance)
|
|
218
|
-
return null;
|
|
219
|
-
const player = await this.pollingClient.getPlayer(tag).catch(() => null);
|
|
220
|
-
if (!player)
|
|
221
|
-
return null;
|
|
222
|
-
const cached = this._players.get(player.tag);
|
|
223
|
-
if (!cached)
|
|
224
|
-
return this._players.set(player.tag, player);
|
|
225
|
-
for (const { name, filter } of this._pollingEvents.players) {
|
|
226
|
-
try {
|
|
227
|
-
if (!(await filter(cached, player)))
|
|
228
|
-
continue;
|
|
229
|
-
this.pollingClient.emit(name, cached, player);
|
|
230
|
-
}
|
|
231
|
-
catch (error) {
|
|
232
|
-
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return this._players.set(player.tag, player);
|
|
236
|
-
}
|
|
237
|
-
async runWarUpdate(tag) {
|
|
238
|
-
if (this._inMaintenance)
|
|
239
|
-
return null;
|
|
240
|
-
const clanWars = await this.pollingClient.getWars(tag).catch(() => null);
|
|
241
|
-
if (!clanWars?.length)
|
|
242
|
-
return null;
|
|
243
|
-
clanWars.forEach(async (war, index) => {
|
|
244
|
-
const key = `${tag}:${index}`;
|
|
245
|
-
const cached = this._wars.get(key);
|
|
246
|
-
if (!cached)
|
|
247
|
-
return this._wars.set(key, war);
|
|
248
|
-
for (const { name, filter } of this._pollingEvents.wars) {
|
|
249
|
-
try {
|
|
250
|
-
if (!(await filter(cached, war)))
|
|
251
|
-
continue;
|
|
252
|
-
this.pollingClient.emit(name, cached, war);
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
// check for war end
|
|
259
|
-
if (index === 1 && cached.warTag !== war.warTag) {
|
|
260
|
-
const data = await this.pollingClient.getLeagueWar({ clanTag: tag, round: 'PreviousRound' }).catch(() => null);
|
|
261
|
-
if (data && data.warTag === cached.warTag) {
|
|
262
|
-
for (const { name, filter } of this._pollingEvents.wars) {
|
|
263
|
-
try {
|
|
264
|
-
if (!(await filter(cached, data)))
|
|
265
|
-
continue;
|
|
266
|
-
this.pollingClient.emit(name, cached, data);
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return this._wars.set(key, war);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
exports.PollingEventManager = PollingEventManager;
|