clashofclans.js 2.8.2 → 3.0.0-dev.29c3270

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.
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RAW_DATA = 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;
6
+ exports.RawData = exports.CWLRounds = exports.RestEvents = exports.ClientEvents = 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
7
  const raw_json_1 = __importDefault(require("../util/raw.json"));
8
- exports.API_BASE_URL = 'https://api.clashofclans.com/v1';
9
- exports.DEV_SITE_API_BASE_URL = 'https://developer.clashofclans.com/api';
10
- exports.ELIXIR_TROOPS = [
8
+ exports.APIBaseURL = 'https://api.clashofclans.com/v1';
9
+ exports.DevSiteAPIBaseURL = 'https://developer.clashofclans.com/api';
10
+ exports.ElixirTroops = [
11
11
  'Barbarian',
12
12
  'Archer',
13
13
  'Giant',
@@ -24,10 +24,10 @@ exports.ELIXIR_TROOPS = [
24
24
  'Yeti',
25
25
  'Dragon Rider'
26
26
  ];
27
- exports.DARK_ELIXIR_TROOPS = ['Minion', 'Hog Rider', 'Valkyrie', 'Golem', 'Witch', 'Lava Hound', 'Bowler', 'Ice Golem', 'Headhunter'];
28
- exports.HOME_TROOPS = [...exports.ELIXIR_TROOPS, ...exports.DARK_ELIXIR_TROOPS];
29
- exports.SIEGE_MACHINES = ['Wall Wrecker', 'Battle Blimp', 'Stone Slammer', 'Siege Barracks', 'Log Launcher', 'Flame Flinger'];
30
- 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 = [
31
31
  'Super Barbarian',
32
32
  'Super Archer',
33
33
  'Super Giant',
@@ -43,7 +43,7 @@ exports.SUPER_TROOPS = [
43
43
  'Ice Hound',
44
44
  'Super Bowler'
45
45
  ];
46
- exports.ELIXIR_SPELLS = [
46
+ exports.ElixirSpells = [
47
47
  'Lightning Spell',
48
48
  'Healing Spell',
49
49
  'Rage Spell',
@@ -52,9 +52,9 @@ exports.ELIXIR_SPELLS = [
52
52
  'Clone Spell',
53
53
  'Invisibility Spell'
54
54
  ];
55
- exports.DARK_ELIXIR_SPELLS = ['Poison Spell', 'Earthquake Spell', 'Haste Spell', 'Skeleton Spell', 'Bat Spell'];
56
- exports.SPELLS = [...exports.ELIXIR_SPELLS, ...exports.DARK_ELIXIR_SPELLS];
57
- 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 = [
58
58
  'Raged Barbarian',
59
59
  'Sneaky Archer',
60
60
  'Boxer Giant',
@@ -67,9 +67,9 @@ exports.BUILDER_TROOPS = [
67
67
  'Super P.E.K.K.A',
68
68
  'Hog Glider'
69
69
  ];
70
- exports.HEROES = ['Barbarian King', 'Archer Queen', 'Grand Warden', 'Royal Champion', 'Battle Machine'];
71
- exports.HERO_PETS = ['L.A.S.S.I', 'Electro Owl', 'Mighty Yak', 'Unicorn'];
72
- 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 = {
73
73
  id: 29000000,
74
74
  name: 'Unranked',
75
75
  iconUrls: {
@@ -77,8 +77,8 @@ exports.UNRANKED_LEAGUE_DATA = {
77
77
  tiny: 'https://api-assets.clashofclans.com/leagues/36/e--YMyIexEQQhE4imLoJcwhYn6Uy8KqlgyY3_kFV6t4.png'
78
78
  }
79
79
  };
80
- exports.LEGEND_LEAGUE_ID = 29000022;
81
- exports.LEAGUES = [
80
+ exports.LegendLeagueId = 29000022;
81
+ exports.Leagues = [
82
82
  29000000,
83
83
  29000001,
84
84
  29000002,
@@ -101,13 +101,13 @@ exports.LEAGUES = [
101
101
  29000019,
102
102
  29000020,
103
103
  29000021,
104
- exports.LEGEND_LEAGUE_ID
104
+ exports.LegendLeagueId
105
105
  ];
106
- exports.WAR_LEAGUES = [
106
+ exports.WarLeagues = [
107
107
  48000000, 48000001, 48000002, 48000003, 48000004, 48000005, 48000006, 48000007, 48000008, 48000009, 48000010, 48000011, 48000012,
108
108
  48000013, 48000014, 48000015, 48000016, 48000017, 48000018
109
109
  ];
110
- exports.FRIENDLY_WAR_PREPARATION_TIMES = [
110
+ exports.FriendlyWarPreparationTimes = [
111
111
  1000 * 60 * 60 * 24,
112
112
  1000 * 60 * 60 * 20,
113
113
  1000 * 60 * 60 * 16,
@@ -121,25 +121,34 @@ exports.FRIENDLY_WAR_PREPARATION_TIMES = [
121
121
  1000 * 60 * 15,
122
122
  1000 * 60 * 5
123
123
  ];
124
- exports.EVENTS = {
125
- NEW_SEASON_START: 'newSeasonStart',
126
- CLAN_LOOP_START: 'clanLoopStart',
127
- CLAN_LOOP_END: 'clanLoopEnd',
128
- PLAYER_LOOP_START: 'playerLoopStart',
129
- PLAYER_LOOP_END: 'playerLoopEnd',
130
- WAR_LOOP_START: 'warLoopEnd',
131
- WAR_LOOP_END: 'warLoopEnd',
132
- MAINTENANCE_START: 'maintenanceStart',
133
- MAINTENANCE_END: 'maintenanceEnd',
134
- ERROR: 'error',
135
- DEBUG: 'debug'
124
+ exports.PollingEvents = {
125
+ ClanLoopStart: 'clanLoopStart',
126
+ ClanLoopEnd: 'clanLoopEnd',
127
+ PlayerLoopStart: 'playerLoopStart',
128
+ PlayerLoopEnd: 'playerLoopEnd',
129
+ WarLoopStart: 'warLoopEnd',
130
+ WarLoopEnd: 'warLoopEnd',
131
+ NewSeasonStart: 'newSeasonStart',
132
+ MaintenanceStart: 'maintenanceStart',
133
+ MaintenanceEnd: 'maintenanceEnd',
134
+ Error: 'error',
135
+ Debug: 'debug'
136
136
  };
137
- exports.CWL_ROUNDS = {
138
- PREVIOUS_ROUND: 'warEnded',
139
- CURRENT_ROUND: 'inWar',
140
- NEXT_ROUND: 'preparation'
137
+ exports.ClientEvents = {
138
+ Error: 'error',
139
+ Debug: 'debug'
141
140
  };
142
- exports.RAW_DATA = {
143
- RAW_UNITS: raw_json_1.default.RAW_UNITS,
144
- RAW_SUPER_UNITS: raw_json_1.default.RAW_SUPER_UNITS
141
+ exports.RestEvents = {
142
+ Error: 'error',
143
+ Debug: 'debug',
144
+ RateLimited: 'rateLimited'
145
+ };
146
+ exports.CWLRounds = {
147
+ PreviousRound: 'warEnded',
148
+ CurrentRound: 'inWar',
149
+ NextRound: 'preparation'
150
+ };
151
+ exports.RawData = {
152
+ RawUnits: raw_json_1.default.RAW_UNITS,
153
+ RawSuperUnits: raw_json_1.default.RAW_SUPER_UNITS
145
154
  };
package/dist/util/Util.js CHANGED
@@ -114,8 +114,8 @@ class Util extends null {
114
114
  }
115
115
  /** Parse in-game army link into troops and spells count with respective Id's. */
116
116
  static parseArmyLink(link) {
117
- const unitsMatches = link.match(/u(?<units>[\d+x-]+)/);
118
- const spellsMatches = link.match(/s(?<spells>[\d+x-]+)/);
117
+ const unitsMatches = /u(?<units>[\d+x-]+)/.exec(link);
118
+ const spellsMatches = /s(?<spells>[\d+x-]+)/.exec(link);
119
119
  const unitsPart = unitsMatches?.groups?.unit?.split('-') ?? [];
120
120
  const spellParts = spellsMatches?.groups?.spells?.split('-') ?? [];
121
121
  const units = unitsPart
@@ -132,11 +132,11 @@ class Util extends null {
132
132
  }));
133
133
  return {
134
134
  units: units.map((unit) => {
135
- const _unit = Constants_1.RAW_DATA.RAW_UNITS.find((raw) => raw.category === 'troop' && raw.id === unit.id);
135
+ const _unit = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'troop' && raw.id === unit.id);
136
136
  return { name: _unit?.name ?? null, count: unit.total, id: unit.id };
137
137
  }),
138
138
  spells: spells.map((spell) => {
139
- const _spell = Constants_1.RAW_DATA.RAW_UNITS.find((raw) => raw.category === 'spell' && raw.id === spell.id);
139
+ const _spell = Constants_1.RawData.RawUnits.find((raw) => raw.category === 'spell' && raw.id === spell.id);
140
140
  return { name: _spell?.name ?? null, count: spell.total, id: spell.id };
141
141
  })
142
142
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "2.8.2",
3
+ "version": "3.0.0-dev.29c3270",
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.5.2"
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 { Client } from './Client';
3
- /** Represents Event Manager of the {@link Client}. */
4
- export declare class EventManager {
5
- private readonly client;
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 _events;
13
- private _inMaintenance;
14
- private _maintenanceStartTime;
15
- constructor(client: Client);
16
- /** Initialize the Event Manager to start pulling. */
17
- init(): Promise<string[]>;
18
- /** Add clan tags to clan events. */
19
- addClans(tags: string[] | string): this;
20
- /** Delete clan tags from clan events. */
21
- deleteClans(tags: string[] | string): this;
22
- /** Add player tags for player events. */
23
- addPlayers(tags: string[] | string): this;
24
- /** Delete player tags from player events. */
25
- deletePlayers(tags: string[] | string): this;
26
- /** Add clan tags for war events. */
27
- addWars(tags: string[] | string): this;
28
- /** Delete clan tags from war events. */
29
- deleteWars(tags: string[] | string): this;
30
- /**
31
- * Set your own custom clan event.
32
- *
33
- * In order to emit the custom event, you must have this filter function that returns a boolean.
34
- *
35
- * @example
36
- * ```js
37
- * client.events.addClans(['#2PP', '#8QU8J9LP']);
38
- *
39
- * client.events.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.events.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
- }