node-leek 1.0.2 → 1.0.3
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/README.md +57 -59
- package/dist/credentials/credentials-manager.js +2 -2
- package/dist/leek-sync/leek-sync-client.d.ts +1 -1
- package/dist/leek-sync/leek-sync-client.d.ts.map +1 -1
- package/dist/leek-sync/leekfile-source/leekwars-source.d.ts +1 -1
- package/dist/leek-sync/leekfile-source/leekwars-source.d.ts.map +1 -1
- package/dist/node-leek-client/node-leek-client.d.ts +3 -2
- package/dist/node-leek-client/node-leek-client.d.ts.map +1 -1
- package/dist/node-leek-client/node-leek-client.js +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,68 +1,82 @@
|
|
|
1
1
|
# 🥬 NodeLeek
|
|
2
|
-
Simple NodeJs client for LeekWars.
|
|
3
|
-
|
|
2
|
+
Simple NodeJs client for LeekWars. Can update scripts, buy items and start fight.
|
|
3
|
+
NodeLeek support the WebSocket connection, so it can read notification and start boss fight.
|
|
4
|
+
```typescript
|
|
5
|
+
const nodeLeek = new NodeLeekClient("Account", "Password");
|
|
6
|
+
await nodeLeek.login();
|
|
7
|
+
// Do stuff
|
|
8
|
+
await nodeLeek.close()
|
|
9
|
+
```
|
|
10
|
+
> 💚 NodeLeek connected !
|
|
11
|
+
> 🤠 PorteventRemote (5000 habs)
|
|
12
|
+
> 🥬 PorteAutomatique lvl.1 - 100 talents - ⚠️ 50 capitals to spend
|
|
13
|
+
|
|
14
|
+
Fight in garden :
|
|
15
|
+
```typescript
|
|
16
|
+
let myLeek: PublicLeek = nodeLeek.leeks[0];
|
|
17
|
+
let opponent: Opponent;
|
|
18
|
+
let fightId: number;
|
|
4
19
|
|
|
20
|
+
[opponent, fightId] = await nodeLeek.startRandomSoloFight(myLeek.id);
|
|
21
|
+
|
|
22
|
+
console.log("Fighting : ", opponent.name);
|
|
23
|
+
console.log("Fight result : ", await nodeLeek.getCompleteFight(fightId));
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Fight bosses :
|
|
5
27
|
```typescript
|
|
6
|
-
|
|
7
|
-
nodeLeek.
|
|
8
|
-
|
|
9
|
-
nodeLeek.fetchFile(nodeLeek.farmer.files['myreworkediaagainagain2bis/new/mynewia'].id, 0).then(file => console.log("My AI code is : \n" + file.code))
|
|
10
|
-
);
|
|
28
|
+
const roomId = await nodeLeek.createRoom(1); // 1 for Nasu Samurai, 2 for Fennel King, 3 for Evil Pumpkin
|
|
29
|
+
// use await nodeLeek.joinRoom(roomId); to join the room with another account
|
|
30
|
+
await nodeLeek.startRoomFight();
|
|
11
31
|
```
|
|
12
32
|
|
|
13
|
-
|
|
33
|
+
## Get started
|
|
34
|
+
Install NodeLeek from [npm](https://www.npmjs.com/package/node-leek) :
|
|
35
|
+
```shell
|
|
36
|
+
npm install node-leek
|
|
37
|
+
```
|
|
14
38
|
|
|
39
|
+
## Routes supported
|
|
40
|
+
Uses OpenAPI to autogenerate API client (specifications are handwritten as no official uptodate spec exists).
|
|
41
|
+
Check the [OpenAPI](./src/openapi/leekwars-api.json) specification.
|
|
42
|
+
So far only the most used route are supported, further support will come.
|
|
15
43
|
|
|
16
|
-
|
|
17
|
-
- /farmer
|
|
44
|
+
- /farmer
|
|
18
45
|
- /login : partially, some part of the response (such as chat message) aren't done yet
|
|
19
46
|
- /garden
|
|
20
|
-
- /start-solo-fight
|
|
21
|
-
- /get-leek-opponnents/{leekId}
|
|
22
47
|
- /get
|
|
48
|
+
- /get-leek-opponnents/{leekId}
|
|
49
|
+
- /get-farmer-opponnents/
|
|
50
|
+
- /start-solo-fight
|
|
51
|
+
- /start-farmer-fight
|
|
52
|
+
- /fight
|
|
53
|
+
- /get/{fightId}
|
|
54
|
+
- /leek
|
|
55
|
+
- /spend-capital
|
|
56
|
+
- /get/{leekId}
|
|
57
|
+
- /marker
|
|
58
|
+
- /buy-habs-quantity
|
|
23
59
|
- /ai-folder
|
|
24
60
|
- /new-name
|
|
25
61
|
- /delete
|
|
26
62
|
- /ai
|
|
27
|
-
- /save
|
|
63
|
+
- /save
|
|
28
64
|
- /new-name
|
|
29
65
|
- /delete
|
|
30
66
|
- /sync
|
|
31
67
|
|
|
32
|
-
Planning to do :
|
|
33
|
-
- ai rename
|
|
34
|
-
- ai bin clear
|
|
35
|
-
- other fight type
|
|
36
|
-
- assign IA to leek
|
|
37
|
-
|
|
38
|
-
Considering :
|
|
39
|
-
- stats assignment, equipment & chip assignment
|
|
40
|
-
- dashboard
|
|
41
|
-
|
|
42
|
-
## How to install
|
|
43
|
-
> This project works with NodeJS. You must install it beforehand.
|
|
44
|
-
|
|
45
|
-
Clone the repository and install the dependencies
|
|
46
|
-
```shell
|
|
47
|
-
git clone https://github.com/Portevent/node-leek
|
|
48
|
-
npm update
|
|
49
|
-
npm install
|
|
50
|
-
```
|
|
51
|
-
|
|
52
68
|
# 🔄 LeekSync (WIP)
|
|
53
69
|
LeekSync allows you to clone your LeekWars file on your local computer and sync them with a file watcher.
|
|
54
70
|
Open your favorite local IDE, edit some files and they get upload to LeekWars seamlessly.
|
|
55
71
|
If you happen to change your file locally while LeekSync is not running, or you edited file through LeekWars editor, LeekSync will ask you which source to use and update the other to be on the same page
|
|
56
72
|
|
|
57
73
|
### Download your leekscripts
|
|
74
|
+
We recommend using `const nodeLeek = new NodeLeekClient("Account", "Password", true);` to start NodeLeek in read only mode.
|
|
75
|
+
This will ensure no modification are done to your leekwars account. Once you downloaded your scripts and have a secured backup, you can remove this readonly flag.
|
|
58
76
|
```typescript
|
|
59
|
-
|
|
77
|
+
nodeLeek.syncWith("../my-files/", false, "leekwars")
|
|
60
78
|
```
|
|
61
79
|
|
|
62
|
-
> 💚 NodeLeek connected !
|
|
63
|
-
> 🤠 PorteventRemote (5000 habs)
|
|
64
|
-
> 🥬 PorteAutomatique lvl.1 - 100 talents - ⚠️ 50 capitals to spend
|
|
65
|
-
> LeekSync is ready !
|
|
66
80
|
|
|
67
81
|
You should see your own code in leekscripts folder. Here is an example :
|
|
68
82
|
|
|
@@ -70,40 +84,24 @@ You should see your own code in leekscripts folder. Here is an example :
|
|
|
70
84
|
├── DamageCalculation
|
|
71
85
|
│ └── NaiveDamageCalculation.leek
|
|
72
86
|
├── MyFirstIa.leek
|
|
73
|
-
└── Test.leek
|
|
87
|
+
└── Test.leek
|
|
74
88
|
|
|
75
89
|
### Upload your leekscripts
|
|
76
90
|
**We strongly recommend to save your code, copying it or upload it to a Git repository**
|
|
77
91
|
**Uploading an empty folder will result in your leekwars account being just an empty folder.
|
|
78
92
|
Use LeekSync with care, and have a backup**
|
|
79
93
|
|
|
80
|
-
First, we need to remove the `
|
|
81
|
-
You can use the
|
|
94
|
+
First, we need to remove the `readonly` option to actually edit our leekwars account.
|
|
95
|
+
You can use the `watch` option to activate the watcher. It will listen to any modification done, and will automaticly push them to Leekwars.
|
|
82
96
|
|
|
83
97
|
```typescript
|
|
84
|
-
|
|
98
|
+
nodeLeek.syncWith("../my-files/", true, "leekwars")
|
|
85
99
|
```
|
|
86
100
|
|
|
87
101
|
Edit your file and refresh Leekwars to see the updated files :
|
|
88
102
|
|
|
89
103
|

|
|
90
104
|
|
|
91
|
-
Additional information :
|
|
92
|
-
- The first `--` are mandatory to use option, and tell `npm` the options coming next are not npm options but leeksync options
|
|
93
|
-
- You can use `--path my_folder` to specify your code folder
|
|
94
|
-
- You can use `-w` as a shorthand of `--watch`, and ` -r` for `--watch`
|
|
95
|
-
- You can use `--choice <something>` to automaticly choose how to resolve out of sync situation (for instance `-c local` to always keep local file and push missing modification to leekwars)
|
|
96
|
-
- LeekSync store your LeekWars timestamp and local timestamp in cache file, so that the next time you launch Leeksync, it won't reimport every files.
|
|
97
|
-
|
|
98
|
-
### Supported operation
|
|
99
|
-
Watcher :
|
|
100
|
-
- LeekWars : not watching edit and don't plan to yet. Edit made on LeekWars while LeekSync is up won't be recorded
|
|
101
|
-
- Local files : will watch for new file, file change, and file or folder deletion.
|
|
102
|
-
- Planning to add rename support
|
|
103
|
-
|
|
104
105
|
|
|
105
|
-
##
|
|
106
|
-
Next feature will be adding auto fighter, and auto logger.
|
|
107
|
-
I have other ideas but I want to focus on these two points first.
|
|
108
|
-
I want to clean up a bit the codebase, so I might rework a lot of stuff after finishing the auto logger.
|
|
106
|
+
## Help needed
|
|
109
107
|
> ❗ Uses outdated package https://www.npmjs.com/package/request because I couldn't make other OpenAPI codegen variants work with cookie authentification. This issue must be resolved to ensure a cleaner code
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CredentialsManager = exports.LeekwarsCredentials = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const
|
|
8
|
+
const node_leek_client_1 = require("../node-leek-client/node-leek-client");
|
|
9
9
|
class LeekwarsCredentials {
|
|
10
10
|
username = "";
|
|
11
11
|
password = "";
|
|
@@ -33,7 +33,7 @@ class CredentialsManager {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
if (this.clients[index] == null) {
|
|
36
|
-
this.clients[index] = new
|
|
36
|
+
this.clients[index] = new node_leek_client_1.NodeLeekClient(this.credentials[index].username, this.credentials[index].password, readonly);
|
|
37
37
|
await this.clients[index]?.login();
|
|
38
38
|
}
|
|
39
39
|
return this.clients[index];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leek-sync-client.d.ts","sourceRoot":"","sources":["../../src/leek-sync/leek-sync-client.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"leek-sync-client.d.ts","sourceRoot":"","sources":["../../src/leek-sync/leek-sync-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,yCAAyC,CAAC;AAKvE,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAa9C,qBAAa,cAAc;IAEvB,gBAAgB,EAAE,QAAQ,CAAA;IAC1B,aAAa,EAAE,QAAQ,CAAA;IAEvB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,WAAW,CAAiB;gBAGxB,cAAc,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM;IAQ3C,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;YAiCnC,cAAc;IA4B5B,OAAO,CAAC,aAAa;CAQxB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import LeekFile from "../filelist/leekfile.js";
|
|
2
2
|
import LeekfileSource from "./leekfile-source.js";
|
|
3
|
-
import NodeLeekClient from "../../node-leek-client/node-leek-client.js";
|
|
4
3
|
import Filelist from "../filelist/filelist.js";
|
|
4
|
+
import { NodeLeekClient } from "../../node-leek-client/node-leek-client";
|
|
5
5
|
declare class LeekwarsSource extends LeekfileSource {
|
|
6
6
|
private nodeLeekClient;
|
|
7
7
|
constructor(nodeLeekClient: NodeLeekClient, filelist: Filelist);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leekwars-source.d.ts","sourceRoot":"","sources":["../../../src/leek-sync/leekfile-source/leekwars-source.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"leekwars-source.d.ts","sourceRoot":"","sources":["../../../src/leek-sync/leekfile-source/leekwars-source.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,yCAAyC,CAAC;AAEvE,cAAM,cAAe,SAAQ,cAAc;IACvC,OAAO,CAAC,cAAc,CAAiB;gBAE3B,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ;IAKxD,IAAI;YAuBI,UAAU;IAoBxB,OAAO,CAAC,QAAQ;IAID,UAAU,CAAC,IAAI,EAAE,QAAQ;IAWzB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;YAI1C,4BAA4B;YAO5B,oBAAoB;YASpB,oBAAoB;YAUpB,sBAAsB;YAItB,mBAAmB;IAcjC,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,aAAa;CAIxB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { Opponent } from "../codegen/model/opponent.js";
|
|
|
3
3
|
import { FightResult } from "../codegen/model/fightResult.js";
|
|
4
4
|
import { LeekWarsClient } from "./leek-wars-client.js";
|
|
5
5
|
import { PublicLeek } from "../codegen/model/publicLeek.js";
|
|
6
|
-
declare class NodeLeekClient extends LeekWarsClient {
|
|
6
|
+
export declare class NodeLeekClient extends LeekWarsClient {
|
|
7
7
|
farmer: Farmer;
|
|
8
8
|
leeks: PublicLeek[];
|
|
9
9
|
private foldersById;
|
|
@@ -25,6 +25,8 @@ declare class NodeLeekClient extends LeekWarsClient {
|
|
|
25
25
|
getFiles(): {
|
|
26
26
|
[name: string]: number;
|
|
27
27
|
};
|
|
28
|
+
private getLocalLeekName;
|
|
29
|
+
getLeekName(id: number): Promise<string>;
|
|
28
30
|
startRandomSoloFight(leek_id: number): Promise<[Opponent, number]>;
|
|
29
31
|
startRandomFarmerFight(): Promise<[Opponent, number]>;
|
|
30
32
|
startRandomTeamFight(leek_id: number): Promise<[Opponent, number]>;
|
|
@@ -33,5 +35,4 @@ declare class NodeLeekClient extends LeekWarsClient {
|
|
|
33
35
|
createRoom(bossId: number, locked?: boolean): Promise<string>;
|
|
34
36
|
joinRoom(roomId: string): Promise<string>;
|
|
35
37
|
}
|
|
36
|
-
export { NodeLeekClient as default };
|
|
37
38
|
//# sourceMappingURL=node-leek-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-leek-client.d.ts","sourceRoot":"","sources":["../../src/node-leek-client/node-leek-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAGlD,OAAO,EAAC,QAAQ,EAAC,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,gCAAgC,CAAC;AAO1D,
|
|
1
|
+
{"version":3,"file":"node-leek-client.d.ts","sourceRoot":"","sources":["../../src/node-leek-client/node-leek-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAGlD,OAAO,EAAC,QAAQ,EAAC,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,gCAAgC,CAAC;AAO1D,qBAAa,cAAe,SAAQ,cAAc;IAEvC,MAAM,EAAE,MAAM,CAAgB;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAM;IAChC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,cAAc,CAA+B;WAEjC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAK1E,KAAK;YAaJ,UAAU;IAWjB,cAAc;IAKrB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,gBAAgB;YAQV,eAAe;IAO7B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,eAAe;IAavB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,UAAU;IAMX,QAAQ,IAAI;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAI7C,OAAO,CAAC,gBAAgB;IAIX,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAI,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAcnE,sBAAsB,IAAK,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IActD,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAI,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAcnE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAWhE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW;IAK1D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe,GAAI,OAAO,CAAC,MAAM,CAAC;IAUrE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;CAO1D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NodeLeekClient = void 0;
|
|
4
4
|
const farmer_js_1 = require("../codegen/model/farmer.js");
|
|
5
5
|
const leek_sync_client_js_1 = require("../leek-sync/leek-sync-client.js");
|
|
6
6
|
const leek_wars_client_js_1 = require("./leek-wars-client.js");
|
|
@@ -131,11 +131,17 @@ class NodeLeekClient extends leek_wars_client_js_1.LeekWarsClient {
|
|
|
131
131
|
getFiles() {
|
|
132
132
|
return this.filesByName;
|
|
133
133
|
}
|
|
134
|
+
getLocalLeekName(id) {
|
|
135
|
+
return this.farmer.leeks[id]?.name;
|
|
136
|
+
}
|
|
137
|
+
async getLeekName(id) {
|
|
138
|
+
return this.getLocalLeekName(id) ?? (await this.getLeek(id))?.name ?? "Unknown";
|
|
139
|
+
}
|
|
134
140
|
async startRandomSoloFight(leek_id) {
|
|
135
141
|
return this.getSoloOpponents(leek_id)
|
|
136
142
|
.then((opponents) => {
|
|
137
143
|
if (opponents.length == 0) {
|
|
138
|
-
console.error("Can't find opponent for " + leek_id);
|
|
144
|
+
console.error("Can't find opponent for " + this.getLocalLeekName(leek_id));
|
|
139
145
|
return [null, -1];
|
|
140
146
|
}
|
|
141
147
|
const opponent = randomIn(opponents);
|
|
@@ -200,4 +206,4 @@ class NodeLeekClient extends leek_wars_client_js_1.LeekWarsClient {
|
|
|
200
206
|
return this.currentRoom;
|
|
201
207
|
}
|
|
202
208
|
}
|
|
203
|
-
exports.
|
|
209
|
+
exports.NodeLeekClient = NodeLeekClient;
|