clashofclans.js 2.7.0 → 2.8.0-dev.11ea070

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hero = exports.Spell = exports.Troop = exports.Unit = void 0;
4
- const raw_json_1 = require("../util/raw.json");
5
4
  const Constants_1 = require("../util/Constants");
6
5
  /** Represents a Player's Unit. */
7
6
  class Unit {
@@ -11,14 +10,14 @@ class Unit {
11
10
  this.level = unit.level;
12
11
  this.maxLevel = unit.maxLevel;
13
12
  this.village = unit.village;
14
- const rawSuperUnit = raw_json_1.RAW_SUPER_UNITS.find((unit) => unit.name === this.name && this.isHomeBase);
15
- const rawUnit = raw_json_1.RAW_UNITS.find((unit) => unit.name === this.name && unit.village === this.village);
13
+ const rawSuperUnit = Constants_1.RawData.RawSuperUnits.find((unit) => unit.name === this.name && this.isHomeBase);
14
+ const rawUnit = Constants_1.RawData.RawUnits.find((unit) => unit.name === this.name && unit.village === this.village);
16
15
  if (rawSuperUnit) {
17
16
  this.id = rawSuperUnit.id;
18
17
  this.housingSpace = rawSuperUnit.housingSpace;
19
18
  this.originalName = rawSuperUnit.original;
20
19
  this.minOriginalLevel = rawSuperUnit.minOriginalLevel;
21
- const original = raw_json_1.RAW_UNITS.find((unit) => unit.village === 'home' && unit.name === rawSuperUnit.original);
20
+ const original = Constants_1.RawData.RawUnits.find((unit) => unit.village === 'home' && unit.name === rawSuperUnit.original);
22
21
  this.unlockHallLevel = original.levels.findIndex((level) => level >= rawSuperUnit.minOriginalLevel) + 1;
23
22
  this.unlockCost = original.unlock.cost;
24
23
  this.unlockTime = original.unlock.time;
@@ -88,7 +87,7 @@ class Troop extends Unit {
88
87
  }
89
88
  /** Whether this troop is a Super Troop. */
90
89
  get isSuperTroop() {
91
- return this.isActive || (this.isHomeBase && Constants_1.SUPER_TROOPS.includes(this.name));
90
+ return this.isActive || (this.isHomeBase && Constants_1.SuperTroops.includes(this.name));
92
91
  }
93
92
  }
94
93
  exports.Troop = Troop;
@@ -10,7 +10,7 @@ class WarLeague {
10
10
  }
11
11
  /** Position of this War League. Starting from 0 (Unranked) */
12
12
  get position() {
13
- return Constants_1.WAR_LEAGUES.indexOf(this.id);
13
+ return Constants_1.WarLeagues.indexOf(this.id);
14
14
  }
15
15
  }
16
16
  exports.WarLeague = WarLeague;
@@ -57,6 +57,7 @@ export interface APIClan {
57
57
  members: number;
58
58
  labels: APILabel[];
59
59
  memberList: APIClanMember[];
60
+ clanCapital: APIClanCapital;
60
61
  }
61
62
  export interface APIClanMember {
62
63
  name: string;
@@ -71,6 +72,14 @@ export interface APIClanMember {
71
72
  donations: number;
72
73
  donationsReceived: number;
73
74
  }
75
+ export interface APIClanCapital {
76
+ capitalHallLevel?: number;
77
+ districts?: {
78
+ id: number;
79
+ name: string;
80
+ districtHallLevel: number;
81
+ }[];
82
+ }
74
83
  /** /clans/{clanTag}/members */
75
84
  export interface APIClanMemberList {
76
85
  items: APIClanMember[];
@@ -179,6 +188,7 @@ export interface APIPlayer {
179
188
  versusBattleWinCount?: number;
180
189
  donations: number;
181
190
  donationsReceived: number;
191
+ clanCapitalContributions: number;
182
192
  role?: string;
183
193
  warPreference?: 'in' | 'out';
184
194
  clan?: APIPlayerClan;
@@ -5,7 +5,7 @@ export interface Store<T = any> {
5
5
  delete(key: string): boolean | Promise<boolean>;
6
6
  clear(): void | Promise<void>;
7
7
  }
8
- /** Options for a Client. */
8
+ /** Options for a {@link Client} */
9
9
  export interface ClientOptions {
10
10
  /** Keys from Clash of Clans API developer site. */
11
11
  keys?: string[];
@@ -36,13 +36,18 @@ export interface ClientOptions {
36
36
  * const client = new Client({ throttler: new BatchThrottler(30) });
37
37
  * ```
38
38
  */
39
- throttler?: QueueThrottler | BatchThrottler;
39
+ throttler?: QueueThrottler | BatchThrottler | null;
40
40
  }
41
- /** Options for a RESTManager. */
41
+ /** Options for a {@link RESTManager} */
42
42
  export interface RESTOptions extends ClientOptions {
43
43
  /** Set this `false` to use `res.ok` property. */
44
44
  rejectIfNotValid?: boolean;
45
45
  }
46
+ /** Options for a {@link RequestHandler} */
47
+ export interface RequestHandlerOptions extends ClientOptions {
48
+ /** Set this `false` to use `res.ok` property. */
49
+ rejectIfNotValid?: boolean;
50
+ }
46
51
  /** Search options for request. */
47
52
  export interface SearchOptions extends OverrideOptions {
48
53
  /** Limit the number of items returned in the response. */
@@ -1,17 +1,17 @@
1
- export declare const API_BASE_URL = "https://api.clashofclans.com/v1";
2
- export declare const DEV_SITE_API_BASE_URL = "https://developer.clashofclans.com/api";
3
- export declare const ELIXIR_TROOPS: string[];
4
- export declare const DARK_ELIXIR_TROOPS: string[];
5
- export declare const HOME_TROOPS: string[];
6
- export declare const SIEGE_MACHINES: string[];
7
- export declare const SUPER_TROOPS: string[];
8
- export declare const ELIXIR_SPELLS: string[];
9
- export declare const DARK_ELIXIR_SPELLS: string[];
10
- export declare const SPELLS: string[];
11
- export declare const BUILDER_TROOPS: string[];
12
- export declare const HEROES: string[];
13
- export declare const HERO_PETS: string[];
14
- export declare const UNRANKED_LEAGUE_DATA: {
1
+ export declare const APIBaseURL = "https://api.clashofclans.com/v1";
2
+ export declare const DevSiteAPIBaseURL = "https://developer.clashofclans.com/api";
3
+ export declare const ElixirTroops: string[];
4
+ export declare const DarkElixirTroops: string[];
5
+ export declare const HomeTroops: string[];
6
+ export declare const SiegeMachines: string[];
7
+ export declare const SuperTroops: string[];
8
+ export declare const ElixirSpells: string[];
9
+ export declare const DarkElixirSpells: string[];
10
+ export declare const Spells: string[];
11
+ export declare const BuilderTroops: string[];
12
+ export declare const Heroes: string[];
13
+ export declare const HeroPets: string[];
14
+ export declare const UnrankedLeagueData: {
15
15
  id: number;
16
16
  name: string;
17
17
  iconUrls: {
@@ -19,24 +19,66 @@ export declare const UNRANKED_LEAGUE_DATA: {
19
19
  tiny: string;
20
20
  };
21
21
  };
22
- export declare const LEGEND_LEAGUE_ID = 29000022;
23
- export declare const LEAGUES: number[];
24
- export declare const WAR_LEAGUES: number[];
25
- export declare const FRIENDLY_WAR_PREPARATION_TIMES: readonly [number, number, number, number, number, number, number, number, number, number, number, number];
26
- export declare const EVENTS: {
27
- readonly NEW_SEASON_START: "newSeasonStart";
28
- readonly CLAN_LOOP_START: "clanLoopStart";
29
- readonly CLAN_LOOP_END: "clanLoopEnd";
30
- readonly PLAYER_LOOP_START: "playerLoopStart";
31
- readonly PLAYER_LOOP_END: "playerLoopEnd";
32
- readonly WAR_LOOP_START: "warLoopEnd";
33
- readonly WAR_LOOP_END: "warLoopEnd";
34
- readonly MAINTENANCE_START: "maintenanceStart";
35
- readonly MAINTENANCE_END: "maintenanceEnd";
36
- readonly ERROR: "error";
22
+ export declare const LegendLeagueId = 29000022;
23
+ export declare const Leagues: number[];
24
+ export declare const WarLeagues: number[];
25
+ export declare const FriendlyWarPreparationTimes: readonly [number, number, number, number, number, number, number, number, number, number, number, number];
26
+ export declare const PollingEvents: {
27
+ readonly NewSeasonStart: "newSeasonStart";
28
+ readonly ClanLoopStart: "clanLoopStart";
29
+ readonly ClanLoopEnd: "clanLoopEnd";
30
+ readonly PlayerLoopStart: "playerLoopStart";
31
+ readonly PlayerLoopEnd: "playerLoopEnd";
32
+ readonly WarLoopStart: "warLoopEnd";
33
+ readonly WarLoopEnd: "warLoopEnd";
34
+ readonly MaintenanceStart: "maintenanceStart";
35
+ readonly MaintenanceEnd: "maintenanceEnd";
36
+ readonly Error: "error";
37
+ readonly Debug: "debug";
37
38
  };
38
- export declare const CWL_ROUNDS: {
39
- readonly PREVIOUS_ROUND: "warEnded";
40
- readonly CURRENT_ROUND: "inWar";
41
- readonly NEXT_ROUND: "preparation";
39
+ export declare const CWLRounds: {
40
+ readonly PreviousRound: "warEnded";
41
+ readonly CurrentRound: "inWar";
42
+ readonly NextRound: "preparation";
43
+ };
44
+ export declare const RawData: {
45
+ RawUnits: {
46
+ id: number;
47
+ name: string;
48
+ housingSpace: number;
49
+ village: string;
50
+ category: string;
51
+ subCategory: string;
52
+ unlock: {
53
+ hall: number;
54
+ cost: number;
55
+ time: number;
56
+ resource: string;
57
+ building: string;
58
+ buildingLevel: number;
59
+ };
60
+ resourceType: string;
61
+ trainingTime: number;
62
+ regenerationTimes: number[];
63
+ dps: number[];
64
+ upgrade: {
65
+ cost: number[];
66
+ time: number[];
67
+ resource: string;
68
+ };
69
+ seasonal: boolean;
70
+ levels: number[];
71
+ }[];
72
+ RawSuperUnits: {
73
+ name: string;
74
+ id: number;
75
+ original: string;
76
+ minOriginalLevel: number;
77
+ village: string;
78
+ duration: number;
79
+ cooldown: number;
80
+ resource: string;
81
+ resourceCost: number;
82
+ housingSpace: number;
83
+ }[];
42
84
  };
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CWL_ROUNDS = exports.EVENTS = exports.FRIENDLY_WAR_PREPARATION_TIMES = exports.WAR_LEAGUES = exports.LEAGUES = exports.LEGEND_LEAGUE_ID = exports.UNRANKED_LEAGUE_DATA = exports.HERO_PETS = exports.HEROES = exports.BUILDER_TROOPS = exports.SPELLS = exports.DARK_ELIXIR_SPELLS = exports.ELIXIR_SPELLS = exports.SUPER_TROOPS = exports.SIEGE_MACHINES = exports.HOME_TROOPS = exports.DARK_ELIXIR_TROOPS = exports.ELIXIR_TROOPS = exports.DEV_SITE_API_BASE_URL = exports.API_BASE_URL = void 0;
4
- exports.API_BASE_URL = 'https://api.clashofclans.com/v1';
5
- exports.DEV_SITE_API_BASE_URL = 'https://developer.clashofclans.com/api';
6
- exports.ELIXIR_TROOPS = [
6
+ exports.RawData = exports.CWLRounds = exports.PollingEvents = exports.FriendlyWarPreparationTimes = exports.WarLeagues = exports.Leagues = exports.LegendLeagueId = exports.UnrankedLeagueData = exports.HeroPets = exports.Heroes = exports.BuilderTroops = exports.Spells = exports.DarkElixirSpells = exports.ElixirSpells = exports.SuperTroops = exports.SiegeMachines = exports.HomeTroops = exports.DarkElixirTroops = exports.ElixirTroops = exports.DevSiteAPIBaseURL = exports.APIBaseURL = void 0;
7
+ const raw_json_1 = __importDefault(require("../util/raw.json"));
8
+ exports.APIBaseURL = 'https://api.clashofclans.com/v1';
9
+ exports.DevSiteAPIBaseURL = 'https://developer.clashofclans.com/api';
10
+ exports.ElixirTroops = [
7
11
  'Barbarian',
8
12
  'Archer',
9
13
  'Giant',
@@ -20,10 +24,10 @@ exports.ELIXIR_TROOPS = [
20
24
  'Yeti',
21
25
  'Dragon Rider'
22
26
  ];
23
- exports.DARK_ELIXIR_TROOPS = ['Minion', 'Hog Rider', 'Valkyrie', 'Golem', 'Witch', 'Lava Hound', 'Bowler', 'Ice Golem', 'Headhunter'];
24
- exports.HOME_TROOPS = [...exports.ELIXIR_TROOPS, ...exports.DARK_ELIXIR_TROOPS];
25
- exports.SIEGE_MACHINES = ['Wall Wrecker', 'Battle Blimp', 'Stone Slammer', 'Siege Barracks', 'Log Launcher', 'Flame Flinger'];
26
- exports.SUPER_TROOPS = [
27
+ exports.DarkElixirTroops = ['Minion', 'Hog Rider', 'Valkyrie', 'Golem', 'Witch', 'Lava Hound', 'Bowler', 'Ice Golem', 'Headhunter'];
28
+ exports.HomeTroops = [...exports.ElixirTroops, ...exports.DarkElixirTroops];
29
+ exports.SiegeMachines = ['Wall Wrecker', 'Battle Blimp', 'Stone Slammer', 'Siege Barracks', 'Log Launcher', 'Flame Flinger'];
30
+ exports.SuperTroops = [
27
31
  'Super Barbarian',
28
32
  'Super Archer',
29
33
  'Super Giant',
@@ -39,7 +43,7 @@ exports.SUPER_TROOPS = [
39
43
  'Ice Hound',
40
44
  'Super Bowler'
41
45
  ];
42
- exports.ELIXIR_SPELLS = [
46
+ exports.ElixirSpells = [
43
47
  'Lightning Spell',
44
48
  'Healing Spell',
45
49
  'Rage Spell',
@@ -48,9 +52,9 @@ exports.ELIXIR_SPELLS = [
48
52
  'Clone Spell',
49
53
  'Invisibility Spell'
50
54
  ];
51
- exports.DARK_ELIXIR_SPELLS = ['Poison Spell', 'Earthquake Spell', 'Haste Spell', 'Skeleton Spell', 'Bat Spell'];
52
- exports.SPELLS = [...exports.ELIXIR_SPELLS, ...exports.DARK_ELIXIR_SPELLS];
53
- exports.BUILDER_TROOPS = [
55
+ exports.DarkElixirSpells = ['Poison Spell', 'Earthquake Spell', 'Haste Spell', 'Skeleton Spell', 'Bat Spell'];
56
+ exports.Spells = [...exports.ElixirSpells, ...exports.DarkElixirSpells];
57
+ exports.BuilderTroops = [
54
58
  'Raged Barbarian',
55
59
  'Sneaky Archer',
56
60
  'Boxer Giant',
@@ -63,9 +67,9 @@ exports.BUILDER_TROOPS = [
63
67
  'Super P.E.K.K.A',
64
68
  'Hog Glider'
65
69
  ];
66
- exports.HEROES = ['Barbarian King', 'Archer Queen', 'Grand Warden', 'Royal Champion', 'Battle Machine'];
67
- exports.HERO_PETS = ['L.A.S.S.I', 'Electro Owl', 'Mighty Yak', 'Unicorn'];
68
- exports.UNRANKED_LEAGUE_DATA = {
70
+ exports.Heroes = ['Barbarian King', 'Archer Queen', 'Grand Warden', 'Royal Champion', 'Battle Machine'];
71
+ exports.HeroPets = ['L.A.S.S.I', 'Electro Owl', 'Mighty Yak', 'Unicorn'];
72
+ exports.UnrankedLeagueData = {
69
73
  id: 29000000,
70
74
  name: 'Unranked',
71
75
  iconUrls: {
@@ -73,8 +77,8 @@ exports.UNRANKED_LEAGUE_DATA = {
73
77
  tiny: 'https://api-assets.clashofclans.com/leagues/36/e--YMyIexEQQhE4imLoJcwhYn6Uy8KqlgyY3_kFV6t4.png'
74
78
  }
75
79
  };
76
- exports.LEGEND_LEAGUE_ID = 29000022;
77
- exports.LEAGUES = [
80
+ exports.LegendLeagueId = 29000022;
81
+ exports.Leagues = [
78
82
  29000000,
79
83
  29000001,
80
84
  29000002,
@@ -97,13 +101,13 @@ exports.LEAGUES = [
97
101
  29000019,
98
102
  29000020,
99
103
  29000021,
100
- exports.LEGEND_LEAGUE_ID
104
+ exports.LegendLeagueId
101
105
  ];
102
- exports.WAR_LEAGUES = [
106
+ exports.WarLeagues = [
103
107
  48000000, 48000001, 48000002, 48000003, 48000004, 48000005, 48000006, 48000007, 48000008, 48000009, 48000010, 48000011, 48000012,
104
108
  48000013, 48000014, 48000015, 48000016, 48000017, 48000018
105
109
  ];
106
- exports.FRIENDLY_WAR_PREPARATION_TIMES = [
110
+ exports.FriendlyWarPreparationTimes = [
107
111
  1000 * 60 * 60 * 24,
108
112
  1000 * 60 * 60 * 20,
109
113
  1000 * 60 * 60 * 16,
@@ -117,20 +121,25 @@ exports.FRIENDLY_WAR_PREPARATION_TIMES = [
117
121
  1000 * 60 * 15,
118
122
  1000 * 60 * 5
119
123
  ];
120
- exports.EVENTS = {
121
- NEW_SEASON_START: 'newSeasonStart',
122
- CLAN_LOOP_START: 'clanLoopStart',
123
- CLAN_LOOP_END: 'clanLoopEnd',
124
- PLAYER_LOOP_START: 'playerLoopStart',
125
- PLAYER_LOOP_END: 'playerLoopEnd',
126
- WAR_LOOP_START: 'warLoopEnd',
127
- WAR_LOOP_END: 'warLoopEnd',
128
- MAINTENANCE_START: 'maintenanceStart',
129
- MAINTENANCE_END: 'maintenanceEnd',
130
- ERROR: 'error'
124
+ exports.PollingEvents = {
125
+ NewSeasonStart: 'newSeasonStart',
126
+ ClanLoopStart: 'clanLoopStart',
127
+ ClanLoopEnd: 'clanLoopEnd',
128
+ PlayerLoopStart: 'playerLoopStart',
129
+ PlayerLoopEnd: 'playerLoopEnd',
130
+ WarLoopStart: 'warLoopEnd',
131
+ WarLoopEnd: 'warLoopEnd',
132
+ MaintenanceStart: 'maintenanceStart',
133
+ MaintenanceEnd: 'maintenanceEnd',
134
+ Error: 'error',
135
+ Debug: 'debug'
136
+ };
137
+ exports.CWLRounds = {
138
+ PreviousRound: 'warEnded',
139
+ CurrentRound: 'inWar',
140
+ NextRound: 'preparation'
131
141
  };
132
- exports.CWL_ROUNDS = {
133
- PREVIOUS_ROUND: 'warEnded',
134
- CURRENT_ROUND: 'inWar',
135
- NEXT_ROUND: 'preparation'
142
+ exports.RawData = {
143
+ RawUnits: raw_json_1.default.RAW_UNITS,
144
+ RawSuperUnits: raw_json_1.default.RAW_SUPER_UNITS
136
145
  };
@@ -39,4 +39,17 @@ export declare class Util extends null {
39
39
  static getSeasonEndTime(timestamp?: Date): Date;
40
40
  static allSettled<T>(values: Promise<T>[]): Promise<T[]>;
41
41
  static delay(ms: number): Promise<unknown>;
42
+ /** Parse in-game army link into troops and spells count with respective Id's. */
43
+ static parseArmyLink(link: string): {
44
+ units: {
45
+ name: string | null;
46
+ count: number;
47
+ id: number;
48
+ }[];
49
+ spells: {
50
+ name: string | null;
51
+ count: number;
52
+ id: number;
53
+ }[];
54
+ };
42
55
  }
package/dist/util/Util.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Util = void 0;
4
+ const Constants_1 = require("../util/Constants");
4
5
  const TAG_CHARACTERS = '0289PYLQGRJCUV';
5
6
  const params = [
6
7
  'name',
@@ -111,5 +112,34 @@ class Util extends null {
111
112
  static async delay(ms) {
112
113
  return new Promise((res) => setTimeout(res, ms));
113
114
  }
115
+ /** Parse in-game army link into troops and spells count with respective Id's. */
116
+ static parseArmyLink(link) {
117
+ const unitsMatches = link.match(/u(?<units>[\d+x-]+)/);
118
+ const spellsMatches = link.match(/s(?<spells>[\d+x-]+)/);
119
+ const unitsPart = unitsMatches?.groups?.unit?.split('-') ?? [];
120
+ const spellParts = spellsMatches?.groups?.spells?.split('-') ?? [];
121
+ const units = unitsPart
122
+ .map((parts) => parts.split(/x/))
123
+ .map((parts) => ({
124
+ id: Number(parts[1]),
125
+ total: Number(parts[0])
126
+ }));
127
+ const spells = spellParts
128
+ .map((parts) => parts.split(/x/))
129
+ .map((parts) => ({
130
+ id: Number(parts[1]),
131
+ total: Number(parts[0])
132
+ }));
133
+ return {
134
+ units: units.map((unit) => {
135
+ const _unit = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'troop' && raw.id === unit.id);
136
+ return { name: _unit?.name ?? null, count: unit.total, id: unit.id };
137
+ }),
138
+ spells: spells.map((spell) => {
139
+ const _spell = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'spell' && raw.id === spell.id);
140
+ return { name: _spell?.name ?? null, count: spell.total, id: spell.id };
141
+ })
142
+ };
143
+ }
114
144
  }
115
145
  exports.Util = Util;