clashofclans.js 1.5.4 → 2.0.0-dev.2c5b083

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +2 -1
  3. package/README.md +39 -110
  4. package/dist/client/Client.d.ts +177 -0
  5. package/dist/client/Client.js +237 -0
  6. package/dist/client/EventManager.d.ts +86 -0
  7. package/dist/client/EventManager.js +279 -0
  8. package/dist/index.d.ts +9 -0
  9. package/dist/index.js +21 -0
  10. package/dist/rest/HTTPError.d.ts +24 -0
  11. package/dist/rest/HTTPError.js +42 -0
  12. package/dist/rest/RESTManager.d.ts +56 -0
  13. package/dist/rest/RESTManager.js +123 -0
  14. package/dist/rest/RequestHandler.d.ts +162 -0
  15. package/dist/rest/RequestHandler.js +198 -0
  16. package/dist/rest/Throttler.d.ts +31 -0
  17. package/dist/rest/Throttler.js +86 -0
  18. package/dist/struct/Achievement.d.ts +25 -0
  19. package/dist/struct/Achievement.js +28 -0
  20. package/dist/struct/Badge.d.ts +16 -0
  21. package/dist/struct/Badge.js +27 -0
  22. package/dist/struct/ChatLanguage.d.ts +11 -0
  23. package/dist/struct/ChatLanguage.js +12 -0
  24. package/dist/struct/Clan.d.ts +64 -0
  25. package/dist/struct/Clan.js +44 -0
  26. package/dist/struct/ClanMember.d.ts +32 -0
  27. package/dist/struct/ClanMember.js +28 -0
  28. package/dist/struct/ClanWar.d.ts +137 -0
  29. package/dist/struct/ClanWar.js +198 -0
  30. package/dist/struct/ClanWarLeagueGroup.d.ts +63 -0
  31. package/dist/struct/ClanWarLeagueGroup.js +85 -0
  32. package/dist/struct/ClanWarLog.d.ts +54 -0
  33. package/dist/struct/ClanWarLog.js +46 -0
  34. package/dist/struct/Icon.d.ts +16 -0
  35. package/dist/struct/Icon.js +27 -0
  36. package/dist/struct/Label.d.ts +12 -0
  37. package/dist/struct/Label.js +13 -0
  38. package/dist/struct/League.d.ts +14 -0
  39. package/dist/struct/League.js +18 -0
  40. package/dist/struct/LegendStatistics.d.ts +18 -0
  41. package/dist/struct/LegendStatistics.js +17 -0
  42. package/dist/struct/Location.d.ts +15 -0
  43. package/dist/struct/Location.js +14 -0
  44. package/dist/struct/Player.d.ts +78 -0
  45. package/dist/struct/Player.js +72 -0
  46. package/dist/struct/PlayerClan.d.ts +19 -0
  47. package/dist/struct/PlayerClan.js +19 -0
  48. package/dist/struct/Ranking.d.ts +58 -0
  49. package/dist/struct/Ranking.js +50 -0
  50. package/dist/struct/Season.d.ts +19 -0
  51. package/dist/struct/Season.js +21 -0
  52. package/dist/struct/Unit.d.ts +68 -0
  53. package/dist/struct/Unit.js +90 -0
  54. package/dist/struct/WarLeague.d.ts +11 -0
  55. package/dist/struct/WarLeague.js +16 -0
  56. package/dist/struct/index.d.ts +19 -0
  57. package/dist/struct/index.js +31 -0
  58. package/dist/types/index.d.ts +350 -0
  59. package/dist/types/index.js +2 -0
  60. package/dist/util/Constants.d.ts +41 -0
  61. package/dist/util/Constants.js +122 -0
  62. package/dist/util/Util.d.ts +18 -0
  63. package/dist/util/Util.js +53 -0
  64. package/dist/util/raw.json +1 -0
  65. package/package.json +109 -36
  66. package/src/index.d.ts +0 -811
  67. package/src/index.js +0 -5
  68. package/src/struct/Client.js +0 -481
  69. package/src/util/Extension.js +0 -130
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Clan = void 0;
4
+ const ChatLanguage_1 = require("./ChatLanguage");
5
+ const ClanMember_1 = require("./ClanMember");
6
+ const WarLeague_1 = require("./WarLeague");
7
+ const Location_1 = require("./Location");
8
+ const Label_1 = require("./Label");
9
+ const Badge_1 = require("./Badge");
10
+ /** Represents a Clan. */
11
+ class Clan {
12
+ constructor(client, data) {
13
+ this.client = client;
14
+ this.name = data.name;
15
+ this.tag = data.tag;
16
+ this.type = data.type;
17
+ this.description = data.description;
18
+ this.location = data.location ? new Location_1.Location(data.location) : null;
19
+ this.chatLanguage = data.chatLanguage ? new ChatLanguage_1.ChatLanguage(data.chatLanguage) : null;
20
+ this.badge = new Badge_1.Badge(data.badgeUrls);
21
+ this.level = data.clanLevel;
22
+ this.points = data.clanPoints;
23
+ this.versusPoints = data.clanVersusPoints;
24
+ this.requiredTrophies = data.requiredTrophies;
25
+ this.requiredTownHallLevel = data.requiredTownhallLevel ?? null;
26
+ this.warFrequency = data.warFrequency;
27
+ this.warWinStreak = data.warWinStreak;
28
+ this.warWins = data.warWins;
29
+ this.warTies = data.warTies ?? null;
30
+ this.warLosses = data.warLosses ?? null;
31
+ this.isWarLogPublic = data.isWarLogPublic;
32
+ this.warLeague = data.warLeague ? new WarLeague_1.WarLeague(data.warLeague) : null;
33
+ this.memberCount = data.members;
34
+ this.labels = data.labels.map((label) => new Label_1.Label(label));
35
+ this.members = data.memberList?.map((mem) => new ClanMember_1.ClanMember(this.client, mem)) ?? []; // eslint-disable-line
36
+ }
37
+ /** Get {@link Player} information for every Player in the clan. */
38
+ async fetchMembers(options) {
39
+ return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ...options, ignoreRateLimit: true }))))
40
+ .filter((res) => res.status === 'fulfilled')
41
+ .map((res) => res.value);
42
+ }
43
+ }
44
+ exports.Clan = Clan;
@@ -0,0 +1,32 @@
1
+ import { OverrideOptions } from '../rest/RequestHandler';
2
+ import { Client } from '../client/Client';
3
+ import { APIClanMember } from '../types';
4
+ import { League } from './League';
5
+ export declare class ClanMember {
6
+ client: Client;
7
+ /** The member's name. */
8
+ name: string;
9
+ /** The member's tag. */
10
+ tag: string;
11
+ /** The member's role in the clan. */
12
+ role: 'member' | 'elder' | 'coLeader' | 'leader';
13
+ /** The member's experience level. */
14
+ expLevel: number;
15
+ /** The member's current League. */
16
+ league: League;
17
+ /** The member's trophy count. */
18
+ trophies: number;
19
+ /** The member's versus trophy count. */
20
+ versusTrophies: number | null;
21
+ /** The member's rank in the clan. */
22
+ clanRank: number;
23
+ /** The member's rank before the last leader-board change. */
24
+ previousClanRank: number;
25
+ /** The member's donation count for this season. */
26
+ donations: number;
27
+ /** The member's donation received count for this season. */
28
+ received: number;
29
+ constructor(client: Client, data: APIClanMember);
30
+ /** Fetch detailed clan info for the member's clan. */
31
+ fetch(options?: OverrideOptions): Promise<import("./Player").Player>;
32
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClanMember = void 0;
4
+ const Constants_1 = require("../util/Constants");
5
+ const League_1 = require("./League");
6
+ class ClanMember {
7
+ constructor(client, data) {
8
+ this.client = client;
9
+ this.name = data.name;
10
+ this.tag = data.tag;
11
+ // @ts-expect-error
12
+ this.role = data.role.replace('admin', 'elder');
13
+ this.expLevel = data.expLevel;
14
+ // eslint-disable-next-line
15
+ this.league = new League_1.League(data.league ?? Constants_1.UNRANKED_LEAGUE_DATA);
16
+ this.trophies = data.trophies;
17
+ this.versusTrophies = data.versusTrophies ?? null;
18
+ this.clanRank = data.clanRank;
19
+ this.previousClanRank = data.previousClanRank;
20
+ this.donations = data.donations;
21
+ this.received = data.donationsReceived;
22
+ }
23
+ /** Fetch detailed clan info for the member's clan. */
24
+ async fetch(options) {
25
+ return this.client.getPlayer(this.tag, options);
26
+ }
27
+ }
28
+ exports.ClanMember = ClanMember;
@@ -0,0 +1,137 @@
1
+ import { APIClanWar, APIClanWarAttack, APIClanWarMember, APIWarClan } from '../types';
2
+ import { Client } from '../client/Client';
3
+ import { Badge } from './Badge';
4
+ /** Represents a Clash of Clans War Attack. */
5
+ export declare class ClanWarAttack {
6
+ /** The war this attack belongs to. */
7
+ war: ClanWar;
8
+ /** The clan this attack belongs to. */
9
+ clan: WarClan;
10
+ /** The stars achieved. */
11
+ stars: number;
12
+ /** The destruction achieved as a percentage. */
13
+ destruction: number;
14
+ /** The attack order in this war. */
15
+ order: number;
16
+ /** Duration of attack in seconds. */
17
+ duration: number;
18
+ /** The attacker tag. */
19
+ attackerTag: string;
20
+ /** The defender tag. */
21
+ defenderTag: string;
22
+ constructor(clan: WarClan, war: ClanWar, data: APIClanWarAttack);
23
+ /** Returns the defending player. */
24
+ get defender(): ClanWarMember;
25
+ /** Returns the attacking player. */
26
+ get attacker(): ClanWarMember;
27
+ /** Returns whether the attack is a fresh or first attack on the defender. */
28
+ get isFresh(): boolean;
29
+ /**
30
+ * Returns the previous best attack on this opponent village.
31
+ * This is useful for calculating the new stars or destruction for new attacks.
32
+ */
33
+ previousBestAttack(): ClanWarAttack | null;
34
+ }
35
+ /** Represents a Clash of Clans War Member. */
36
+ export declare class ClanWarMember {
37
+ private readonly _bestOpponentAttackerTag?;
38
+ /** The current war this member is in. */
39
+ war: ClanWar;
40
+ /** The member's clan. */
41
+ clan: WarClan;
42
+ /** The member's name. */
43
+ name: string;
44
+ /** The member's tag. */
45
+ tag: string;
46
+ /** The member's map position in the war. */
47
+ mapPosition: number;
48
+ /** The member's town hall level. */
49
+ townHallLevel: number;
50
+ /** The member's attacks this war. */
51
+ attacks: ClanWarAttack[];
52
+ /** The number of times this member has been attacked. */
53
+ defenseCount: number;
54
+ constructor(clan: WarClan, war: ClanWar, data: APIClanWarMember);
55
+ /** Whether the member is from the opponent clan. */
56
+ get isOpponent(): boolean;
57
+ /** The member's defenses this war. */
58
+ get defenses(): ClanWarAttack[];
59
+ /** Best opponent attack on this base. */
60
+ get bestOpponentAttack(): ClanWarAttack | null;
61
+ /**
62
+ * Returns the previous best opponent attack on this village.
63
+ * This is useful for calculating the new stars or destruction for new attacks.
64
+ */
65
+ previousBestOpponentAttack(): ClanWarAttack | null;
66
+ }
67
+ /** Represents a War Clan. */
68
+ export declare class WarClan {
69
+ private readonly war;
70
+ /** The clan's name. */
71
+ name: string;
72
+ /** The clan's tag. */
73
+ tag: string;
74
+ /** The clan's badge. */
75
+ badge: Badge;
76
+ /** The clan's level. */
77
+ level: number;
78
+ /** Number of stars achieved by this clan. */
79
+ stars: number;
80
+ /** The destruction achieved as a percentage. */
81
+ destruction: number;
82
+ /** An array of members that are in the war. */
83
+ members: ClanWarMember[];
84
+ /** Total attacks used by this clan. */
85
+ attackCount: number;
86
+ constructor(war: ClanWar, data: APIWarClan);
87
+ /** Whether the clan is the opponent clan. */
88
+ get isOpponent(): boolean;
89
+ /** Average duration of all clan member's attacks. */
90
+ get averageAttackDuration(): number;
91
+ /** Returns all clan member's attacks. */
92
+ get attacks(): ClanWarAttack[];
93
+ /** Returns all clan member's defenses. */
94
+ get defenses(): ClanWarAttack[];
95
+ /** Get a member of the clan for the given tag, or `null` if not found. */
96
+ getMember(tag: string): ClanWarMember | null;
97
+ }
98
+ /** Represents a Clan War in Clash of Clans. */
99
+ export declare class ClanWar {
100
+ client: Client;
101
+ /** The clan's current war state. */
102
+ state: 'preparation' | 'inWar' | 'warEnded';
103
+ /** The number of players on each side. */
104
+ teamSize: number;
105
+ /** The number of attacks each member has. */
106
+ attacksPerMember: number;
107
+ /** The Date that preparation day started at. */
108
+ preparationStartTime: Date;
109
+ /** The Date that battle day starts at. */
110
+ startTime: Date;
111
+ /** The Date that battle day ends at. */
112
+ endTime: Date;
113
+ /** The home clan. */
114
+ clan: WarClan;
115
+ /** The opposition clan. */
116
+ opponent: WarClan;
117
+ /** The war's unique tag. This is `null` unless this is a CWL. */
118
+ warTag: string | null;
119
+ /** Maximum number of milliseconds the results can be cached. */
120
+ maxAge: number;
121
+ constructor(client: Client, data: APIClanWar, extra: {
122
+ clanTag?: string;
123
+ warTag?: string;
124
+ maxAge: number;
125
+ });
126
+ /** Return a {@link ClanWarMember} with the tag provided. */
127
+ getMember(tag: string): ClanWarMember | null;
128
+ /** Return a list of {@link ClanWarAttack} for the attackerTag and defenderTag provided. */
129
+ getAttack(attackerTag: string, defenderTag: string): ClanWarAttack | null;
130
+ /** Return a list of {@link ClanWarAttack} for the defenderTag provided. */
131
+ getDefenses(defenderTag: string): ClanWarAttack[];
132
+ /** Returns either `friendly`, `cwl` or `normal`. */
133
+ get type(): "friendly" | "cwl" | "normal";
134
+ private get _isFriendly();
135
+ /** Returns the war status, based off the home clan. */
136
+ get status(): "win" | "lose" | "tie" | "pending";
137
+ }
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClanWar = exports.WarClan = exports.ClanWarMember = exports.ClanWarAttack = void 0;
4
+ const Constants_1 = require("../util/Constants");
5
+ const Badge_1 = require("./Badge");
6
+ /** Represents a Clash of Clans War Attack. */
7
+ class ClanWarAttack {
8
+ constructor(clan, war, data) {
9
+ Object.defineProperty(this, 'clan', { value: clan });
10
+ Object.defineProperty(this, 'war', { value: war });
11
+ this.stars = data.stars;
12
+ this.destruction = data.destructionPercentage;
13
+ this.order = data.order;
14
+ this.duration = data.duration;
15
+ this.attackerTag = data.attackerTag;
16
+ this.defenderTag = data.defenderTag;
17
+ }
18
+ /** Returns the defending player. */
19
+ get defender() {
20
+ return this.war.getMember(this.defenderTag);
21
+ }
22
+ /** Returns the attacking player. */
23
+ get attacker() {
24
+ return this.war.getMember(this.attackerTag);
25
+ }
26
+ /** Returns whether the attack is a fresh or first attack on the defender. */
27
+ get isFresh() {
28
+ if (this.defender.defenses.length === 1)
29
+ return true;
30
+ return this.order === Math.min(...this.defender.defenses.map((def) => def.order));
31
+ }
32
+ /**
33
+ * Returns the previous best attack on this opponent village.
34
+ * This is useful for calculating the new stars or destruction for new attacks.
35
+ */
36
+ previousBestAttack() {
37
+ if (this.isFresh)
38
+ return null;
39
+ return (
40
+ // Let's not change the original array
41
+ [...this.clan.attacks]
42
+ .filter((atk) => atk.defenderTag === this.defenderTag && atk.order < this.order && atk.attackerTag !== this.attackerTag)
43
+ .sort((a, b) => b.destruction ** b.stars - a.destruction ** a.stars)
44
+ .at(0) ?? null);
45
+ }
46
+ }
47
+ exports.ClanWarAttack = ClanWarAttack;
48
+ /** Represents a Clash of Clans War Member. */
49
+ class ClanWarMember {
50
+ constructor(clan, war, data) {
51
+ Object.defineProperty(this, 'clan', { value: clan });
52
+ Object.defineProperty(this, 'war', { value: war });
53
+ this.name = data.name;
54
+ this.tag = data.tag;
55
+ this.mapPosition = data.mapPosition;
56
+ this.townHallLevel = data.townhallLevel;
57
+ this.attacks = data.attacks?.map((atk) => new ClanWarAttack(clan, war, atk)) ?? [];
58
+ this.defenseCount = data.opponentAttacks;
59
+ this._bestOpponentAttackerTag = data.bestOpponentAttack?.attackerTag;
60
+ }
61
+ /** Whether the member is from the opponent clan. */
62
+ get isOpponent() {
63
+ return this.clan.tag === this.war.opponent.tag;
64
+ }
65
+ /** The member's defenses this war. */
66
+ get defenses() {
67
+ return this.war.getDefenses(this.tag);
68
+ }
69
+ /** Best opponent attack on this base. */
70
+ get bestOpponentAttack() {
71
+ if (!this._bestOpponentAttackerTag)
72
+ return null;
73
+ return this.war.getAttack(this._bestOpponentAttackerTag, this.tag);
74
+ }
75
+ /**
76
+ * Returns the previous best opponent attack on this village.
77
+ * This is useful for calculating the new stars or destruction for new attacks.
78
+ */
79
+ previousBestOpponentAttack() {
80
+ return (
81
+ // Let's not change the original array
82
+ [...this.defenses]
83
+ .filter((def) => def.defenderTag === this.tag && def.attackerTag !== this.bestOpponentAttack?.attackerTag)
84
+ .sort((a, b) => b.destruction ** b.stars - a.destruction ** a.stars)
85
+ .at(0) ?? null);
86
+ }
87
+ }
88
+ exports.ClanWarMember = ClanWarMember;
89
+ /** Represents a War Clan. */
90
+ class WarClan {
91
+ constructor(war, data) {
92
+ Object.defineProperty(this, 'war', { value: war });
93
+ this.name = data.name;
94
+ this.tag = data.tag;
95
+ this.badge = new Badge_1.Badge(data.badgeUrls);
96
+ this.level = data.clanLevel;
97
+ this.stars = data.stars;
98
+ this.attackCount = data.attacks;
99
+ this.destruction = data.destructionPercentage;
100
+ this.members = data.members.map((mem) => new ClanWarMember(this, war, mem));
101
+ }
102
+ /** Whether the clan is the opponent clan. */
103
+ get isOpponent() {
104
+ return this.tag === this.war.opponent.tag;
105
+ }
106
+ /** Average duration of all clan member's attacks. */
107
+ get averageAttackDuration() {
108
+ if (!this.attackCount)
109
+ return 0;
110
+ return this.attacks.reduce((prev, curr) => prev + curr.duration, 0) / this.attackCount;
111
+ }
112
+ /** Returns all clan member's attacks. */
113
+ get attacks() {
114
+ return this.members
115
+ .filter((m) => m.attacks.length)
116
+ .map((m) => m.attacks)
117
+ .flat()
118
+ .sort((a, b) => a.order - b.order);
119
+ }
120
+ /** Returns all clan member's defenses. */
121
+ get defenses() {
122
+ return this.isOpponent ? this.war.clan.attacks : this.war.opponent.attacks;
123
+ }
124
+ /** Get a member of the clan for the given tag, or `null` if not found. */
125
+ getMember(tag) {
126
+ return this.members.find((m) => m.tag === tag) ?? null;
127
+ }
128
+ }
129
+ exports.WarClan = WarClan;
130
+ /** Represents a Clan War in Clash of Clans. */
131
+ class ClanWar {
132
+ constructor(client, data, extra) {
133
+ Object.defineProperty(this, 'client', { value: client });
134
+ // @ts-expect-error
135
+ this.state = data.state;
136
+ this.teamSize = data.teamSize;
137
+ this.attacksPerMember = data.attacksPerMember;
138
+ this.preparationStartTime = client.util.parseDate(data.preparationStartTime);
139
+ this.startTime = client.util.parseDate(data.startTime);
140
+ this.endTime = client.util.parseDate(data.endTime);
141
+ this.warTag = extra.warTag ?? null;
142
+ let [clan, opponent] = [data.clan, data.opponent];
143
+ const clanTag = extra.clanTag && client.util.parseTag(extra.clanTag);
144
+ if (clanTag && [data.clan.tag, data.opponent.tag].includes(clanTag)) {
145
+ clan = data.clan.tag === clanTag ? data.clan : data.opponent;
146
+ opponent = data.clan.tag === clan.tag ? data.opponent : data.clan;
147
+ }
148
+ this.clan = new WarClan(this, clan);
149
+ this.opponent = new WarClan(this, opponent);
150
+ this.maxAge = extra.maxAge;
151
+ }
152
+ /** Return a {@link ClanWarMember} with the tag provided. */
153
+ getMember(tag) {
154
+ return this.clan.getMember(tag) ?? this.opponent.getMember(tag) ?? null;
155
+ }
156
+ /** Return a list of {@link ClanWarAttack} for the attackerTag and defenderTag provided. */
157
+ getAttack(attackerTag, defenderTag) {
158
+ const attacker = this.getMember(attackerTag);
159
+ if (!attacker?.attacks.length)
160
+ return null;
161
+ return attacker.attacks.find((atk) => atk.defenderTag === defenderTag) ?? null;
162
+ }
163
+ /** Return a list of {@link ClanWarAttack} for the defenderTag provided. */
164
+ getDefenses(defenderTag) {
165
+ const defender = this.getMember(defenderTag);
166
+ if (defender.isOpponent) {
167
+ return this.clan.attacks.filter((atk) => atk.defenderTag === defenderTag);
168
+ }
169
+ return this.opponent.attacks.filter((atk) => atk.defenderTag === defenderTag);
170
+ }
171
+ /** Returns either `friendly`, `cwl` or `normal`. */
172
+ get type() {
173
+ if (this._isFriendly)
174
+ return 'friendly';
175
+ if (this.warTag)
176
+ return 'cwl';
177
+ return 'normal';
178
+ }
179
+ get _isFriendly() {
180
+ const preparationTime = this.startTime.getTime() - this.preparationStartTime.getTime();
181
+ return Constants_1.FRIENDLY_WAR_PREPARATION_TIMES.includes(preparationTime);
182
+ }
183
+ /** Returns the war status, based off the home clan. */
184
+ get status() {
185
+ if (this.state === 'preparation')
186
+ return 'pending';
187
+ if (this.clan.stars > this.opponent.stars)
188
+ return 'win';
189
+ if (this.clan.stars === this.opponent.stars) {
190
+ if (this.clan.destruction > this.opponent.destruction)
191
+ return 'win';
192
+ if (this.clan.destruction === this.opponent.destruction)
193
+ return 'tie';
194
+ }
195
+ return 'lose';
196
+ }
197
+ }
198
+ exports.ClanWar = ClanWar;
@@ -0,0 +1,63 @@
1
+ import { APIClanWarLeagueClan, APIClanWarLeagueClanMember, APIClanWarLeagueGroup, APIClanWarLeagueRound } from '../types';
2
+ import { OverrideOptions } from '../rest/RequestHandler';
3
+ import { Client } from '../client/Client';
4
+ import { ClanWar } from './ClanWar';
5
+ import { Player } from './Player';
6
+ import { Badge } from './Badge';
7
+ /** Represents a Clan War League member. */
8
+ export declare class ClanWarLeagueClanMember {
9
+ /** The member's name. */
10
+ name: string;
11
+ /** The member's tag. */
12
+ tag: string;
13
+ /** The member's town hall level. */
14
+ townHallLevel: number;
15
+ constructor(data: APIClanWarLeagueClanMember);
16
+ }
17
+ /** Represents a Clan of CWL Group. */
18
+ export declare class ClanWarLeagueClan {
19
+ private readonly client;
20
+ /** The clan's name. */
21
+ name: string;
22
+ /** The clan's tag. */
23
+ tag: string;
24
+ /** The clan's level. */
25
+ level: number;
26
+ /** The clan's badge. */
27
+ badge: Badge;
28
+ /** An array of members that are in the CWL group. */
29
+ members: ClanWarLeagueClanMember[];
30
+ constructor(client: Client, data: APIClanWarLeagueClan);
31
+ /** Get {@link Player} information for every members that are in the CWL group. */
32
+ fetchMembers(options?: OverrideOptions): Promise<Player[]>;
33
+ }
34
+ /** Represents a Round of CWL Group. */
35
+ export declare class ClanWarLeagueRound {
36
+ /** War Tags for this round. */
37
+ warTags: string[];
38
+ /** The # (1-7) of this round. */
39
+ round: number;
40
+ constructor(data: APIClanWarLeagueRound, round: number);
41
+ }
42
+ /** Represents a CWL Group. */
43
+ export declare class ClanWarLeagueGroup {
44
+ private readonly client;
45
+ /** The CWL group's current war state. */
46
+ state: 'preparation' | 'inWar' | 'warEnded';
47
+ /** Season Id of this CWL group. */
48
+ season: string;
49
+ /** Returns all participating clans. */
50
+ clans: ClanWarLeagueClan[];
51
+ /** An array containing all war tags for each round. */
52
+ rounds: ClanWarLeagueRound[];
53
+ constructor(client: Client, data: APIClanWarLeagueGroup);
54
+ /**
55
+ * This returns an array of {@link ClanWar} which fetches all wars in parallel.
56
+ * @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
57
+ * @param options Override options for the request.
58
+ */
59
+ getWars(clanTag?: string, options?: OverrideOptions): Promise<ClanWar[]>;
60
+ private _getCurrentWars;
61
+ /** Returns the index of the round for this specified warTag. */
62
+ getRoundIndex(warTag: string): number | null;
63
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClanWarLeagueGroup = exports.ClanWarLeagueRound = exports.ClanWarLeagueClan = exports.ClanWarLeagueClanMember = void 0;
4
+ const Badge_1 = require("./Badge");
5
+ /** Represents a Clan War League member. */
6
+ class ClanWarLeagueClanMember {
7
+ constructor(data) {
8
+ this.name = data.name;
9
+ this.tag = data.tag;
10
+ this.townHallLevel = data.townHallLevel;
11
+ }
12
+ }
13
+ exports.ClanWarLeagueClanMember = ClanWarLeagueClanMember;
14
+ /** Represents a Clan of CWL Group. */
15
+ class ClanWarLeagueClan {
16
+ constructor(client, data) {
17
+ this.client = client;
18
+ this.name = data.name;
19
+ this.tag = data.tag;
20
+ this.level = data.clanLevel;
21
+ this.badge = new Badge_1.Badge(data.badgeUrls);
22
+ this.members = data.members.map((mem) => new ClanWarLeagueClanMember(mem));
23
+ }
24
+ /** Get {@link Player} information for every members that are in the CWL group. */
25
+ async fetchMembers(options) {
26
+ return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ...options, ignoreRateLimit: true }))))
27
+ .filter((res) => res.status === 'fulfilled')
28
+ .map((res) => res.value);
29
+ }
30
+ }
31
+ exports.ClanWarLeagueClan = ClanWarLeagueClan;
32
+ /** Represents a Round of CWL Group. */
33
+ class ClanWarLeagueRound {
34
+ constructor(data, round) {
35
+ this.warTags = data.warTags;
36
+ this.round = round + 1;
37
+ }
38
+ }
39
+ exports.ClanWarLeagueRound = ClanWarLeagueRound;
40
+ /** Represents a CWL Group. */
41
+ class ClanWarLeagueGroup {
42
+ constructor(client, data) {
43
+ this.client = client;
44
+ this.state = data.state;
45
+ this.season = data.season;
46
+ this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
47
+ this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
48
+ }
49
+ /**
50
+ * This returns an array of {@link ClanWar} which fetches all wars in parallel.
51
+ * @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
52
+ * @param options Override options for the request.
53
+ */
54
+ async getWars(clanTag, options) {
55
+ const rounds = this.rounds.filter((round) => !round.warTags.includes('#0'));
56
+ if (!rounds.length)
57
+ return [];
58
+ const warTags = rounds.map((round) => round.warTags).flat();
59
+ const wars = await Promise.allSettled(warTags.map((warTag) => this.client.getClanWarLeagueRound({ warTag, clanTag }, { ...options, ignoreRateLimit: true })));
60
+ return wars
61
+ .filter((res) => res.status === 'fulfilled')
62
+ .map((res) => res.value)
63
+ .filter((war) => (clanTag ? war.clan.tag === clanTag : true));
64
+ }
65
+ async _getCurrentWars(clanTag, options) {
66
+ const rounds = this.rounds.filter((round) => !round.warTags.includes('#0'));
67
+ if (!rounds.length)
68
+ return [];
69
+ const warTags = rounds
70
+ .slice(-2)
71
+ .map((round) => round.warTags)
72
+ .flat()
73
+ .reverse();
74
+ const wars = await Promise.allSettled(warTags.map((warTag) => this.client.getClanWarLeagueRound({ warTag, clanTag }, { ...options, ignoreRateLimit: true })));
75
+ return wars
76
+ .filter((res) => res.status === 'fulfilled')
77
+ .map((res) => res.value)
78
+ .filter((war) => war.clan.tag === clanTag);
79
+ }
80
+ /** Returns the index of the round for this specified warTag. */
81
+ getRoundIndex(warTag) {
82
+ return this.rounds.find((round) => round.warTags.includes(warTag))?.round ?? null;
83
+ }
84
+ }
85
+ exports.ClanWarLeagueGroup = ClanWarLeagueGroup;
@@ -0,0 +1,54 @@
1
+ import { APIClanWarLogEntry, APIWarLogClan } from '../types';
2
+ import { Client } from '../client/Client';
3
+ import { Badge } from './Badge';
4
+ /**
5
+ * Represents War Log Clan.
6
+ *
7
+ * :::caution
8
+ * If this is called via {@link ClanWarLog.opponent}, then {@link WarLogClan.attackCount} and {@link WarLogClan.expEarned} will be `null`.
9
+ * For CWL entries {@link WarLogClan.name} and {@link WarLogClan.tag} are `null`.
10
+ * :::
11
+ */
12
+ export declare class WarLogClan {
13
+ /** The clan's name. This property is `null` CWL entries. */
14
+ name: string | null;
15
+ /** The clan's tag. This property is `null` CWL entries. */
16
+ tag: string | null;
17
+ /** The clan's badge. */
18
+ badge: Badge;
19
+ /** The clan's level. */
20
+ level: number;
21
+ /** Number of stars achieved by this clan. */
22
+ stars: number;
23
+ /** The destruction achieved as a percentage. */
24
+ destruction: number;
25
+ /**
26
+ * Total XP earned by clan this war.
27
+ * This property is `null` for the opponent.
28
+ */
29
+ expEarned: number | null;
30
+ /**
31
+ * Total attacks used by this clan.
32
+ * This property is `null` for the opponent.
33
+ */
34
+ attackCount: number | null;
35
+ constructor(data: APIWarLogClan);
36
+ }
37
+ export declare class ClanWarLog {
38
+ client: Client;
39
+ /** The result of the war. */
40
+ result: 'win' | 'lose' | 'tie' | null;
41
+ /** The Date that battle day ends at. */
42
+ endTime: Date;
43
+ /** The number of players on each side. */
44
+ teamSize: number;
45
+ /** The number of attacks each member has. */
46
+ attacksPerMember: number | null;
47
+ /** The home clan. */
48
+ clan: WarLogClan;
49
+ /** The opposition clan. */
50
+ opponent: WarLogClan;
51
+ constructor(client: Client, data: APIClanWarLogEntry);
52
+ /** Returns either `friendly`, `cwl` or `normal`. */
53
+ get type(): "friendly" | "cwl" | "normal";
54
+ }