fnlb 0.0.2 → 0.0.4
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 +19 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -1
- package/package.json +20 -20
package/README.md
CHANGED
|
@@ -72,18 +72,34 @@ await fnlb.start({
|
|
|
72
72
|
|
|
73
73
|
## Stop your bot
|
|
74
74
|
|
|
75
|
-
The FNLB.
|
|
75
|
+
The FNLB.stop() method will kill all the shards.
|
|
76
76
|
|
|
77
77
|
```ts
|
|
78
78
|
import FNLB from 'fnlb';
|
|
79
79
|
|
|
80
80
|
const fnlb = new FNLB();
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
await fnlb.start({
|
|
83
83
|
apiToken: 'abc',
|
|
84
84
|
numberOfShards: 2,
|
|
85
85
|
botsPerShard: 10
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
// do something
|
|
89
|
+
|
|
90
|
+
await fnlb.stop()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Set a cluster name
|
|
94
|
+
|
|
95
|
+
You can use the clusterName option to set your cluster name.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import FNLB from 'fnlb';
|
|
99
|
+
|
|
100
|
+
const fnlb = new FNLB({ clusterName: 'MyCluster' });
|
|
101
|
+
|
|
102
|
+
await fnlb.start({
|
|
103
|
+
apiToken: 'abc'
|
|
104
|
+
});
|
|
89
105
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface FNLBConfig {
|
|
|
5
5
|
disableErrorLogs?: boolean;
|
|
6
6
|
disableSubProcessLogs?: boolean;
|
|
7
7
|
disableSubProcessErrorLogs?: boolean;
|
|
8
|
+
clusterName?: string;
|
|
8
9
|
}
|
|
9
10
|
export interface StartConfig {
|
|
10
11
|
apiToken: string;
|
|
@@ -13,17 +14,21 @@ export interface StartConfig {
|
|
|
13
14
|
botsPerShard?: number;
|
|
14
15
|
hideUsernames?: boolean;
|
|
15
16
|
hideEmails?: boolean;
|
|
16
|
-
|
|
17
|
+
logLevel?: "INFO" | "DEBUG";
|
|
17
18
|
}
|
|
18
19
|
declare class FNLB {
|
|
19
20
|
private isLoaded;
|
|
20
|
-
private config?;
|
|
21
|
+
private readonly config?;
|
|
22
|
+
private readonly activeProcesses;
|
|
23
|
+
private shouldRestart;
|
|
21
24
|
constructor(config?: FNLBConfig);
|
|
22
25
|
private log;
|
|
26
|
+
private success;
|
|
23
27
|
private warn;
|
|
24
28
|
private error;
|
|
25
29
|
update(): Promise<void>;
|
|
26
|
-
start(config: StartConfig): Promise<
|
|
30
|
+
start(config: StartConfig): Promise<void>;
|
|
31
|
+
stop(): Promise<void>;
|
|
27
32
|
startShard(config: StartConfig, id: string): Promise<import("child_process").ChildProcess>;
|
|
28
33
|
}
|
|
29
34
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fork as
|
|
1
|
+
import{fork as c}from"node:child_process";import{createHash as p}from"node:crypto";import{readFile as g,writeFile as u}from"node:fs/promises";import f from"node:path";class h{static wait(t){return new Promise((e)=>setTimeout(e,t))}}class i{isLoaded=!1;config;activeProcesses=new Map;shouldRestart=!0;constructor(t){this.config=t}log(...t){if(!this.config?.disableLogs)console.log("[FNLB ShardingManager]",...t)}success(...t){if(!this.config?.disableLogs)console.log("[FNLB ShardingManager] [OK]",...t)}warn(...t){if(!this.config?.disableErrorLogs)console.warn("[FNLB ShardingManager] [WRN]",...t)}error(...t){if(!this.config?.disableErrorLogs)console.error("[FNLB ShardingManager] [ERR]",...t)}async update(){if(this.isLoaded)return;let t=f.join("zenith.js"),e=await g(t,"utf-8").catch(()=>null);this.log(e?"Checking for updates...":"Downloading FNLB...");let s=await fetch("https://dist.fnlb.net/packages/zenith/release");if(!s.ok)throw new Error(`[FNLB ShardingManager] Failed to check for updates, status code: ${s.status}`);let r=await s.json();if(e){let l=p("sha256");if(l.update(e),l.digest().toString("hex")===r.hash){this.success(`FNLB v${r.version} is up to date`),this.isLoaded=!0,this.success(`Finished loading FNLB v${r.version}`);return}this.log(`Downloading update for FNLB v${r.version}`)}let a=r.url,n=await fetch(a);if(!n.ok)throw new Error(`[FNLB ShardingManager] Failed to download update, status code: ${n.status}`);this.log(`Downloaded FNLB v${r.version}`);let d=await n.text();await u(t,d),this.isLoaded=!0,this.success(`Finished loading FNLB v${r.version}`)}async start(t){if(await this.stop(),this.shouldRestart=!0,!t?.apiToken)throw new Error("[FNLB ShardingManager] Please provide a FNLB API token.");await this.update();let e=t.numberOfShards??1;for(let o=0;o<e;o++){let s=new Date,r=`${o.toString().padStart(2,"0")}/${s.getDay()}${s.getHours()}${s.getMinutes()}${s.getSeconds()}`,a=await this.startShard(t,r);this.activeProcesses.set(r,a)}}async stop(){this.log("Stopping all active processes..."),this.shouldRestart=!1;for(let[t,e]of this.activeProcesses)this.log(`Stopping process with id: ${t}`),e.kill();this.activeProcesses.clear(),this.log("All processes stopped.")}async startShard(t,e){if(await this.update(),!t?.apiToken)throw new Error("[FNLB ShardingManager] Please provide a FNLB API token.");this.log("Starting shard with id:",e);let o=c("zenith.js",[],{env:{...process.env,FORCE_COLOR:"1",SHARD_ID:e,API_TOKEN:t.apiToken,CATEGORIES:t.categories?.join(","),BOTS_PER_SHARD:(t.botsPerShard??1).toString(),HIDE_USERNAMES:t.hideUsernames?"true":"false",HIDE_EMAILS:t.hideEmails?"true":"false",LOG_LEVEL:t.logLevel,CLUSTER_ID:this.config?.clusterName?.trim().replace(/ +(?= )/g,"").toLowerCase().replaceAll(" ","-")??"unknown",CLUSTER_NAME:this.config?.clusterName?.trim()}});if(!this.config?.disableSubProcessLogs)o.stdout?.on("data",(s)=>{process.stdout.write(s.toString("utf8"))});if(!this.config?.disableSubProcessErrorLogs)o.stderr?.on("data",(s)=>{process.stderr.write(s.toString("utf8"))});return o.on("close",async(s)=>{if(this.activeProcesses.delete(e),this.shouldRestart){if(s===0)this.warn("Child process exited with code:",s?.toString()??"none");else this.error("Child process exited with code:",s?.toString()??"none");await h.wait(1e4);let r=await this.startShard(t,e);this.activeProcesses.set(e,r)}else this.log(`Child process ${e} stopped.`)}),o}}var P=i;export{P as default};
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnlb",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"author": "FNLB-Project",
|
|
6
5
|
"main": "dist/index.js",
|
|
7
|
-
"
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@biomejs/biome": "^1.9.4",
|
|
8
|
+
"@types/bun": "^1.1.17",
|
|
9
|
+
"bun-plugin-dts": "^0.3.0",
|
|
10
|
+
"@typescript-eslint/eslint-plugin": "^8.20.0",
|
|
11
|
+
"@typescript-eslint/parser": "^8.20.0",
|
|
12
|
+
"eslint": "^9.18.0"
|
|
13
|
+
},
|
|
14
|
+
"description": "Self-Host your own Fortnite LobbyBot with FNLB's system.",
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"packageManager": "bun@1.1.17",
|
|
8
19
|
"scripts": {
|
|
9
20
|
"build": "bun run src/build.ts",
|
|
10
|
-
"prepublishOnly": "bun run lint && bun run build",
|
|
21
|
+
"prepublishOnly": "bun run lint && bun run build --env=disable",
|
|
11
22
|
"test": "bun run test/index.ts",
|
|
23
|
+
"test:node": "bun run build && node test/node.js",
|
|
12
24
|
"lint": "bun run lint:biome && bun run lint:tsc",
|
|
13
25
|
"lint:biome": "bunx --bun @biomejs/biome check --write .",
|
|
14
26
|
"lint:tsc": "bun tsc --noEmit"
|
|
15
27
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"license": "ISC",
|
|
20
|
-
"dependencies": {},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@biomejs/biome": "^1.8.3",
|
|
23
|
-
"@types/bun": "^1.1.6",
|
|
24
|
-
"bun-plugin-dts": "^0.2.1",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
26
|
-
"@typescript-eslint/parser": "^7.14.1",
|
|
27
|
-
"eslint": "^9.6.0"
|
|
28
|
-
},
|
|
29
|
-
"packageManager": "bun@1.1.17",
|
|
30
|
-
"trustedDependencies": ["@biomejs/biome"]
|
|
28
|
+
"trustedDependencies": ["@biomejs/biome"],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"types": "dist/index.d.ts"
|
|
31
31
|
}
|