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 CHANGED
@@ -2,11 +2,19 @@
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.8.0 (2022-07-22)
6
+
7
+ ### Features
8
+
9
+ - Better Throttler with JS generator function. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
10
+ - Updated raw data from game files. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
11
+ - New method Util#parseArmyLink has been added. ([#110](https://github.com/clashperk/clashofclans.js/pull/110))
12
+
5
13
  ## 2.7.0 (2022-05-22)
6
14
 
7
15
  ### Features
8
16
 
9
- - Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
17
+ - Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
10
18
 
11
19
  ## 2.6.1 (2022-02-03)
12
20
 
@@ -1,8 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
3
- import { EVENTS, CWL_ROUNDS } from '../util/Constants';
3
+ import { CWLRounds } from '../util/Constants';
4
4
  import { RESTManager } from '../rest/RESTManager';
5
- import { EventManager } from './EventManager';
6
5
  import { EventEmitter } from 'events';
7
6
  import { Util } from '../util/Util';
8
7
  import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, SeasonRankedPlayer, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
@@ -14,15 +13,11 @@ import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLea
14
13
  * ```
15
14
  */
16
15
  export declare class Client extends EventEmitter {
17
- /** Event Manager for the client. */
18
- readonly events: EventManager;
19
16
  /** REST Handler of the client. */
20
- readonly rest: RESTManager;
17
+ rest: RESTManager;
21
18
  constructor(options?: ClientOptions);
22
19
  /** Contains various general-purpose utility methods. */
23
20
  get util(): typeof Util;
24
- /** Whether the API is in maintenance break. */
25
- get inMaintenance(): boolean;
26
21
  /**
27
22
  * Initialize the client to create keys.
28
23
  * @example
@@ -57,7 +52,7 @@ export declare class Client extends EventEmitter {
57
52
  */
58
53
  getCurrentWar(clanTag: string | {
59
54
  clanTag: string;
60
- round?: keyof typeof CWL_ROUNDS;
55
+ round?: keyof typeof CWLRounds;
61
56
  }, options?: OverrideOptions): Promise<ClanWar | null>;
62
57
  /**
63
58
  * Get info about currently running CWL round.
@@ -72,10 +67,12 @@ export declare class Client extends EventEmitter {
72
67
  */
73
68
  getLeagueWar(clanTag: string | {
74
69
  clanTag: string;
75
- round?: keyof typeof CWL_ROUNDS;
70
+ round?: keyof typeof CWLRounds;
76
71
  }, options?: OverrideOptions): Promise<ClanWar | null>;
77
- private _getCurrentLeagueWars;
78
- private _getClanWars;
72
+ /** Returns active wars (last 2) of the CWL group. */
73
+ getLeagueWars(clanTag: string, options?: OverrideOptions): Promise<ClanWar[]>;
74
+ /** Returns active wars (last 2 for CWL) of the clan. */
75
+ getWars(clanTag: string, options?: OverrideOptions): Promise<ClanWar[]>;
79
76
  /** Get info about clan war league. */
80
77
  getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<ClanWarLeagueGroup>;
81
78
  /** Get info about a CWL round by WarTag. */
@@ -129,67 +126,4 @@ export declare class Client extends EventEmitter {
129
126
  getPlayerLabels(options?: SearchOptions): Promise<Label[]>;
130
127
  /** Get info about gold pass season. */
131
128
  getGoldPassSeason(options?: OverrideOptions): Promise<GoldPassSeason>;
132
- /**
133
- * Emits when a new season starts.
134
- *
135
- * **Parameters**
136
- *
137
- * | Name | Type | Description |
138
- * | :--: | :------: | :-------------------: |
139
- * | `id` | `string` | Id of the new season. |
140
- * @public
141
- * @event
142
- */
143
- private static newSeasonStart;
144
- /**
145
- * Emits when maintenance break starts in the API.
146
- * @public
147
- * @event
148
- */
149
- private static maintenanceStart;
150
- /**
151
- * Emits when maintenance break ends in the API.
152
- *
153
- * **Parameters**
154
- *
155
- * | Name | Type | Description |
156
- * | :--------: | :------: | :------------------------------------------------: |
157
- * | `duration` | `number` | Duration of the maintenance break in milliseconds. |
158
- * @public
159
- * @event
160
- */
161
- private static maintenanceEnd;
162
- /** @internal */
163
- on<K extends keyof ClientEvents>(event: K, listeners: (...args: ClientEvents[K]) => void): this;
164
- /** @internal */
165
- on<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: CustomEvents[S]) => void): this;
166
- /** @internal */ on<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: any[]) => void): this;
167
- /** @internal */
168
- once<K extends keyof ClientEvents>(event: K, listeners: (...args: ClientEvents[K]) => void): this;
169
- /** @internal */
170
- once<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: CustomEvents[S]) => void): this;
171
- /** @internal */ once<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, listeners: (...args: any[]) => void): this;
172
- /** @internal */
173
- emit<K extends keyof ClientEvents>(event: K, ...args: ClientEvents[K]): boolean;
174
- /** @internal */
175
- emit<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientEvents>, ...args: CustomEvents[S]): this;
176
- /** @internal */ emit<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, ...args: any[]): boolean;
177
- }
178
- interface ClientEvents {
179
- [EVENTS.NEW_SEASON_START]: [id: string];
180
- [EVENTS.MAINTENANCE_START]: [];
181
- [EVENTS.MAINTENANCE_END]: [duration: number];
182
- [EVENTS.CLAN_LOOP_START]: [];
183
- [EVENTS.CLAN_LOOP_END]: [];
184
- [EVENTS.PLAYER_LOOP_START]: [];
185
- [EVENTS.PLAYER_LOOP_END]: [];
186
- [EVENTS.WAR_LOOP_START]: [];
187
- [EVENTS.WAR_LOOP_END]: [];
188
- [EVENTS.ERROR]: [error: unknown];
189
- }
190
- interface CustomEvents {
191
- [key: `clan${string}`]: [oldClan: Clan, newClan: Clan];
192
- [key: `war${string}`]: [oldWar: ClanWar, newWar: ClanWar];
193
- [key: `player${string}`]: [oldPlayer: Player, newPlayer: Player];
194
129
  }
195
- export {};
@@ -4,7 +4,6 @@ exports.Client = void 0;
4
4
  const Constants_1 = require("../util/Constants");
5
5
  const HTTPError_1 = require("../rest/HTTPError");
6
6
  const RESTManager_1 = require("../rest/RESTManager");
7
- const EventManager_1 = require("./EventManager");
8
7
  const events_1 = require("events");
9
8
  const Util_1 = require("../util/Util");
10
9
  const struct_1 = require("../struct");
@@ -19,17 +18,11 @@ class Client extends events_1.EventEmitter {
19
18
  constructor(options) {
20
19
  super();
21
20
  this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true });
22
- this.events = new EventManager_1.EventManager(this);
23
21
  }
24
22
  /** Contains various general-purpose utility methods. */
25
23
  get util() {
26
24
  return Util_1.Util;
27
25
  }
28
- /** Whether the API is in maintenance break. */
29
- get inMaintenance() {
30
- // @ts-expect-error
31
- return this.events._inMaintenance;
32
- }
33
26
  /**
34
27
  * Initialize the client to create keys.
35
28
  * @example
@@ -116,7 +109,7 @@ class Client extends events_1.EventEmitter {
116
109
  */
117
110
  async getLeagueWar(clanTag, options) {
118
111
  const args = typeof clanTag === 'string' ? { clanTag } : { clanTag: clanTag.clanTag, round: clanTag.round };
119
- const state = (args.round && Constants_1.CWL_ROUNDS[args.round]) ?? 'inWar'; // eslint-disable-line
112
+ const state = (args.round && Constants_1.CWLRounds[args.round]) ?? 'inWar'; // eslint-disable-line
120
113
  const data = await this.getClanWarLeagueGroup(args.clanTag, options);
121
114
  const rounds = data.rounds.filter((round) => !round.warTags.includes('#0'));
122
115
  if (!rounds.length)
@@ -128,23 +121,26 @@ class Client extends events_1.EventEmitter {
128
121
  .flat()
129
122
  .reverse();
130
123
  const wars = await this.util.allSettled(warTags.map((warTag) => this.getClanWarLeagueRound({ warTag, clanTag: args.clanTag }, { ...options, ignoreRateLimit: true })));
131
- if (args.round && args.round in Constants_1.CWL_ROUNDS) {
132
- return wars.find((war) => war.state === state) ?? null;
124
+ if (args.round && args.round in Constants_1.CWLRounds) {
125
+ return wars.find((war) => war.clan.tag === args.clanTag && war.state === state) ?? null;
133
126
  }
134
- return wars.find((war) => war.state === state) ?? wars.at(0) ?? null;
127
+ return (wars.find((war) => war.clan.tag === args.clanTag && war.state === state) ??
128
+ wars.find((war) => war.clan.tag === args.clanTag) ??
129
+ null);
135
130
  }
136
- async _getCurrentLeagueWars(clanTag, options) {
131
+ /** Returns active wars (last 2) of the CWL group. */
132
+ async getLeagueWars(clanTag, options) {
137
133
  const data = await this.getClanWarLeagueGroup(clanTag, options);
138
- // @ts-expect-error
139
- return data._getCurrentWars(clanTag, options);
134
+ return data.getCurrentWars(clanTag, options);
140
135
  }
141
- async _getClanWars(clanTag, options) {
136
+ /** Returns active wars (last 2 for CWL) of the clan. */
137
+ async getWars(clanTag, options) {
142
138
  const date = new Date().getUTCDate();
143
139
  if (!(date >= 1 && date <= 10)) {
144
140
  return [await this.getClanWar(clanTag, options)];
145
141
  }
146
142
  try {
147
- return this._getCurrentLeagueWars(clanTag, options);
143
+ return this.getLeagueWars(clanTag, options);
148
144
  }
149
145
  catch (e) {
150
146
  if (e instanceof HTTPError_1.HTTPError && [404].includes(e.status)) {
@@ -193,12 +189,12 @@ class Client extends events_1.EventEmitter {
193
189
  }
194
190
  /** Get Legend League season Ids. */
195
191
  async getLeagueSeasons(options) {
196
- const { data } = await this.rest.getLeagueSeasons(Constants_1.LEGEND_LEAGUE_ID, options);
192
+ const { data } = await this.rest.getLeagueSeasons(Constants_1.LegendLeagueId, options);
197
193
  return data.items.map((league) => league.id);
198
194
  }
199
195
  /** Get Legend League season rankings by season Id. */
200
196
  async getSeasonRankings(seasonId, options) {
201
- const { data } = await this.rest.getSeasonRankings(Constants_1.LEGEND_LEAGUE_ID, seasonId, options);
197
+ const { data } = await this.rest.getSeasonRankings(Constants_1.LegendLeagueId, seasonId, options);
202
198
  return data.items.map((entry) => new struct_1.SeasonRankedPlayer(this, entry));
203
199
  }
204
200
  /** Get list of Clan War Leagues. */
@@ -1,42 +1,42 @@
1
1
  import { Clan, ClanWar, Player } from '../struct';
2
- import { Client } from './Client';
3
- /** Represents Event Manager of the {@link Client}. */
4
- export declare class EventManager {
5
- private readonly client;
2
+ import { PollingClient } from './PollingClient';
3
+ /** Represents PollingEvent Manager of the {@link PollingClient}. */
4
+ export declare class PollingEventManager {
5
+ private readonly pollingClient;
6
6
  private readonly _clanTags;
7
7
  private readonly _playerTags;
8
8
  private readonly _warTags;
9
9
  private readonly _clans;
10
10
  private readonly _players;
11
11
  private readonly _wars;
12
- private readonly _events;
12
+ private readonly _pollingEvents;
13
13
  private _inMaintenance;
14
14
  private _maintenanceStartTime;
15
- constructor(client: Client);
16
- /** Initialize the Event Manager to start pulling. */
15
+ constructor(pollingClient: PollingClient);
16
+ /** Initialize the PollingEvent Manager to start pulling the data by polling api. */
17
17
  init(): Promise<string[]>;
18
- /** Add clan tags to clan events. */
18
+ /** Add clan tags to clan polling events. */
19
19
  addClans(tags: string[] | string): this;
20
- /** Delete clan tags from clan events. */
20
+ /** Delete clan tags from clan polling events. */
21
21
  deleteClans(tags: string[] | string): this;
22
- /** Add player tags for player events. */
22
+ /** Add player tags for player polling events. */
23
23
  addPlayers(tags: string[] | string): this;
24
- /** Delete player tags from player events. */
24
+ /** Delete player tags from player polling events. */
25
25
  deletePlayers(tags: string[] | string): this;
26
- /** Add clan tags for war events. */
26
+ /** Add clan tags for war polling events. */
27
27
  addWars(tags: string[] | string): this;
28
- /** Delete clan tags from war events. */
28
+ /** Delete clan tags from war polling events. */
29
29
  deleteWars(tags: string[] | string): this;
30
30
  /**
31
- * Set your own custom clan event.
31
+ * Set your own custom clan polling event.
32
32
  *
33
- * In order to emit the custom event, you must have this filter function that returns a boolean.
33
+ * In order to emit the custom polling event, you must have this filter function that returns a boolean.
34
34
  *
35
35
  * @example
36
36
  * ```js
37
- * client.events.addClans(['#2PP', '#8QU8J9LP']);
37
+ * client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
38
38
  *
39
- * client.events.setClanEvent({
39
+ * client.pollingEvents.setClanEvent({
40
40
  * name: 'clanMemberUpdate',
41
41
  * filter: (oldClan, newClan) => {
42
42
  * return oldClan.memberCount !== newClan.memberCount;
@@ -48,7 +48,7 @@ export declare class EventManager {
48
48
  * });
49
49
  *
50
50
  * (async function () {
51
- * await client.events.init();
51
+ * await client.pollingEvents.init();
52
52
  * })();
53
53
  * ```
54
54
  * @returns
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventManager = void 0;
3
+ exports.PollingEventManager = void 0;
4
4
  const HTTPError_1 = require("../rest/HTTPError");
5
5
  const Constants_1 = require("../util/Constants");
6
6
  const Util_1 = require("../util/Util");
7
- /** Represents Event Manager of the {@link Client}. */
8
- class EventManager {
9
- constructor(client) {
10
- this.client = client;
7
+ /** Represents PollingEvent Manager of the {@link PollingClient}. */
8
+ class PollingEventManager {
9
+ constructor(pollingClient) {
10
+ this.pollingClient = pollingClient;
11
11
  this._clanTags = new Set();
12
12
  this._playerTags = new Set();
13
13
  this._warTags = new Set();
14
14
  this._clans = new Map();
15
15
  this._players = new Map();
16
16
  this._wars = new Map();
17
- this._events = {
17
+ this._pollingEvents = {
18
18
  clans: [],
19
19
  wars: [],
20
20
  players: []
@@ -22,58 +22,58 @@ class EventManager {
22
22
  this._inMaintenance = Boolean(false);
23
23
  this._maintenanceStartTime = null;
24
24
  }
25
- /** Initialize the Event Manager to start pulling. */
25
+ /** Initialize the PollingEvent Manager to start pulling the data by polling api. */
26
26
  async init() {
27
27
  this.seasonEndHandler();
28
28
  this.maintenanceHandler();
29
29
  this.clanUpdateHandler();
30
30
  this.playerUpdateHandler();
31
31
  this.warUpdateHandler();
32
- return Promise.resolve(this.client.eventNames());
32
+ return Promise.resolve(this.pollingClient.eventNames());
33
33
  }
34
- /** Add clan tags to clan events. */
34
+ /** Add clan tags to clan polling events. */
35
35
  addClans(tags) {
36
36
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
37
- this._clanTags.add(this.client.util.formatTag(tag));
37
+ this._clanTags.add(this.pollingClient.util.formatTag(tag));
38
38
  }
39
39
  return this;
40
40
  }
41
- /** Delete clan tags from clan events. */
41
+ /** Delete clan tags from clan polling events. */
42
42
  deleteClans(tags) {
43
43
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
44
- const key = this.client.util.formatTag(tag);
44
+ const key = this.pollingClient.util.formatTag(tag);
45
45
  this._clans.delete(key);
46
46
  this._clanTags.delete(key);
47
47
  }
48
48
  return this;
49
49
  }
50
- /** Add player tags for player events. */
50
+ /** Add player tags for player polling events. */
51
51
  addPlayers(tags) {
52
52
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
53
- this._playerTags.add(this.client.util.formatTag(tag));
53
+ this._playerTags.add(this.pollingClient.util.formatTag(tag));
54
54
  }
55
55
  return this;
56
56
  }
57
- /** Delete player tags from player events. */
57
+ /** Delete player tags from player polling events. */
58
58
  deletePlayers(tags) {
59
59
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
60
- const key = this.client.util.formatTag(tag);
60
+ const key = this.pollingClient.util.formatTag(tag);
61
61
  this._players.delete(key);
62
62
  this._playerTags.delete(key);
63
63
  }
64
64
  return this;
65
65
  }
66
- /** Add clan tags for war events. */
66
+ /** Add clan tags for war polling events. */
67
67
  addWars(tags) {
68
68
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
69
- this._warTags.add(this.client.util.formatTag(tag));
69
+ this._warTags.add(this.pollingClient.util.formatTag(tag));
70
70
  }
71
71
  return this;
72
72
  }
73
- /** Delete clan tags from war events. */
73
+ /** Delete clan tags from war polling events. */
74
74
  deleteWars(tags) {
75
75
  for (const tag of Array.isArray(tags) ? tags : [tags]) {
76
- const key = this.client.util.formatTag(tag);
76
+ const key = this.pollingClient.util.formatTag(tag);
77
77
  this._wars.delete(`${key}:${1}`);
78
78
  this._wars.delete(`${key}:${2}`);
79
79
  this._warTags.delete(key);
@@ -81,15 +81,15 @@ class EventManager {
81
81
  return this;
82
82
  }
83
83
  /**
84
- * Set your own custom clan event.
84
+ * Set your own custom clan polling event.
85
85
  *
86
- * In order to emit the custom event, you must have this filter function that returns a boolean.
86
+ * In order to emit the custom polling event, you must have this filter function that returns a boolean.
87
87
  *
88
88
  * @example
89
89
  * ```js
90
- * client.events.addClans(['#2PP', '#8QU8J9LP']);
90
+ * client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
91
91
  *
92
- * client.events.setClanEvent({
92
+ * client.pollingEvents.setClanEvent({
93
93
  * name: 'clanMemberUpdate',
94
94
  * filter: (oldClan, newClan) => {
95
95
  * return oldClan.memberCount !== newClan.memberCount;
@@ -101,7 +101,7 @@ class EventManager {
101
101
  * });
102
102
  *
103
103
  * (async function () {
104
- * await client.events.init();
104
+ * await client.pollingEvents.init();
105
105
  * })();
106
106
  * ```
107
107
  * @returns
@@ -111,7 +111,7 @@ class EventManager {
111
111
  throw new Error('Event name is required.');
112
112
  if (typeof event.filter !== 'function')
113
113
  throw new Error('Filter function is required.');
114
- this._events.clans.push(event);
114
+ this._pollingEvents.clans.push(event);
115
115
  return this;
116
116
  }
117
117
  /**
@@ -124,7 +124,7 @@ class EventManager {
124
124
  throw new Error('Event name is required.');
125
125
  if (typeof event.filter !== 'function')
126
126
  throw new Error('Filter function is required.');
127
- this._events.wars.push(event);
127
+ this._pollingEvents.wars.push(event);
128
128
  return this;
129
129
  }
130
130
  /**
@@ -137,25 +137,25 @@ class EventManager {
137
137
  throw new Error('Event name is required.');
138
138
  if (typeof event.filter !== 'function')
139
139
  throw new Error('Filter function is required.');
140
- this._events.players.push(event);
140
+ this._pollingEvents.players.push(event);
141
141
  return this;
142
142
  }
143
143
  async maintenanceHandler() {
144
144
  setTimeout(this.maintenanceHandler.bind(this), 10000).unref();
145
145
  try {
146
- const res = await this.client.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
146
+ const res = await this.pollingClient.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
147
147
  if (res.status === 200 && this._inMaintenance) {
148
148
  this._inMaintenance = Boolean(false);
149
149
  const duration = Date.now() - this._maintenanceStartTime.getTime();
150
150
  this._maintenanceStartTime = null;
151
- this.client.emit(Constants_1.EVENTS.MAINTENANCE_END, duration);
151
+ this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceEnd, duration);
152
152
  }
153
153
  }
154
154
  catch (error) {
155
155
  if (error instanceof HTTPError_1.HTTPError && error.status === 503 && !this._inMaintenance) {
156
156
  this._inMaintenance = Boolean(true);
157
157
  this._maintenanceStartTime = new Date();
158
- this.client.emit(Constants_1.EVENTS.MAINTENANCE_START);
158
+ this.pollingClient.emit(Constants_1.PollingEvents.MaintenanceStart);
159
159
  }
160
160
  }
161
161
  }
@@ -167,48 +167,48 @@ class EventManager {
167
167
  }
168
168
  else if (end > 0) {
169
169
  setTimeout(() => {
170
- this.client.emit(Constants_1.EVENTS.NEW_SEASON_START, Util_1.Util.getSeasonId());
170
+ this.pollingClient.emit(Constants_1.PollingEvents.NewSeasonStart, Util_1.Util.getSeasonId());
171
171
  }, end + 100).unref();
172
172
  }
173
173
  }
174
174
  async clanUpdateHandler() {
175
- this.client.emit(Constants_1.EVENTS.CLAN_LOOP_START);
175
+ this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopStart);
176
176
  for (const tag of this._clanTags)
177
177
  await this.runClanUpdate(tag);
178
- this.client.emit(Constants_1.EVENTS.CLAN_LOOP_END);
178
+ this.pollingClient.emit(Constants_1.PollingEvents.ClanLoopEnd);
179
179
  setTimeout(this.clanUpdateHandler.bind(this), 10000);
180
180
  }
181
181
  async playerUpdateHandler() {
182
- this.client.emit(Constants_1.EVENTS.PLAYER_LOOP_START);
182
+ this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopStart);
183
183
  for (const tag of this._playerTags)
184
184
  await this.runPlayerUpdate(tag);
185
- this.client.emit(Constants_1.EVENTS.PLAYER_LOOP_END);
185
+ this.pollingClient.emit(Constants_1.PollingEvents.PlayerLoopEnd);
186
186
  setTimeout(this.playerUpdateHandler.bind(this), 10000);
187
187
  }
188
188
  async warUpdateHandler() {
189
- this.client.emit(Constants_1.EVENTS.WAR_LOOP_START);
189
+ this.pollingClient.emit(Constants_1.PollingEvents.WarLoopStart);
190
190
  for (const tag of this._warTags)
191
191
  await this.runWarUpdate(tag);
192
- this.client.emit(Constants_1.EVENTS.WAR_LOOP_END);
192
+ this.pollingClient.emit(Constants_1.PollingEvents.WarLoopEnd);
193
193
  setTimeout(this.warUpdateHandler.bind(this), 10000);
194
194
  }
195
195
  async runClanUpdate(tag) {
196
196
  if (this._inMaintenance)
197
197
  return null;
198
- const clan = await this.client.getClan(tag).catch(() => null);
198
+ const clan = await this.pollingClient.getClan(tag).catch(() => null);
199
199
  if (!clan)
200
200
  return null;
201
201
  const cached = this._clans.get(clan.tag);
202
202
  if (!cached)
203
203
  return this._clans.set(clan.tag, clan);
204
- for (const { name, filter } of this._events.clans) {
204
+ for (const { name, filter } of this._pollingEvents.clans) {
205
205
  try {
206
206
  if (!(await filter(cached, clan)))
207
207
  continue;
208
- this.client.emit(name, cached, clan);
208
+ this.pollingClient.emit(name, cached, clan);
209
209
  }
210
210
  catch (error) {
211
- this.client.emit(Constants_1.EVENTS.ERROR, error);
211
+ this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
212
212
  }
213
213
  }
214
214
  return this._clans.set(clan.tag, clan);
@@ -216,20 +216,20 @@ class EventManager {
216
216
  async runPlayerUpdate(tag) {
217
217
  if (this._inMaintenance)
218
218
  return null;
219
- const player = await this.client.getPlayer(tag).catch(() => null);
219
+ const player = await this.pollingClient.getPlayer(tag).catch(() => null);
220
220
  if (!player)
221
221
  return null;
222
222
  const cached = this._players.get(player.tag);
223
223
  if (!cached)
224
224
  return this._players.set(player.tag, player);
225
- for (const { name, filter } of this._events.players) {
225
+ for (const { name, filter } of this._pollingEvents.players) {
226
226
  try {
227
227
  if (!(await filter(cached, player)))
228
228
  continue;
229
- this.client.emit(name, cached, player);
229
+ this.pollingClient.emit(name, cached, player);
230
230
  }
231
231
  catch (error) {
232
- this.client.emit(Constants_1.EVENTS.ERROR, error);
232
+ this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
233
233
  }
234
234
  }
235
235
  return this._players.set(player.tag, player);
@@ -237,8 +237,7 @@ class EventManager {
237
237
  async runWarUpdate(tag) {
238
238
  if (this._inMaintenance)
239
239
  return null;
240
- // @ts-expect-error
241
- const clanWars = await this.client._getClanWars(tag).catch(() => null);
240
+ const clanWars = await this.pollingClient.getWars(tag).catch(() => null);
242
241
  if (!clanWars?.length)
243
242
  return null;
244
243
  clanWars.forEach(async (war, index) => {
@@ -246,28 +245,28 @@ class EventManager {
246
245
  const cached = this._wars.get(key);
247
246
  if (!cached)
248
247
  return this._wars.set(key, war);
249
- for (const { name, filter } of this._events.wars) {
248
+ for (const { name, filter } of this._pollingEvents.wars) {
250
249
  try {
251
250
  if (!(await filter(cached, war)))
252
251
  continue;
253
- this.client.emit(name, cached, war);
252
+ this.pollingClient.emit(name, cached, war);
254
253
  }
255
254
  catch (error) {
256
- this.client.emit(Constants_1.EVENTS.ERROR, error);
255
+ this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
257
256
  }
258
257
  }
259
258
  // check for war end
260
259
  if (index === 1 && cached.warTag !== war.warTag) {
261
- const data = await this.client.getLeagueWar({ clanTag: tag, round: 'PREVIOUS_ROUND' }).catch(() => null);
260
+ const data = await this.pollingClient.getLeagueWar({ clanTag: tag, round: 'PreviousRound' }).catch(() => null);
262
261
  if (data && data.warTag === cached.warTag) {
263
- for (const { name, filter } of this._events.wars) {
262
+ for (const { name, filter } of this._pollingEvents.wars) {
264
263
  try {
265
264
  if (!(await filter(cached, data)))
266
265
  continue;
267
- this.client.emit(name, cached, data);
266
+ this.pollingClient.emit(name, cached, data);
268
267
  }
269
268
  catch (error) {
270
- this.client.emit(Constants_1.EVENTS.ERROR, error);
269
+ this.pollingClient.emit(Constants_1.PollingEvents.Error, error);
271
270
  }
272
271
  }
273
272
  }
@@ -276,4 +275,4 @@ class EventManager {
276
275
  });
277
276
  }
278
277
  }
279
- exports.EventManager = EventManager;
278
+ exports.PollingEventManager = PollingEventManager;