fnlb 0.0.5 → 0.0.7

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{fork as d}from"node:child_process";import{createHash as p}from"node:crypto";import{readFile as g,writeFile as f}from"node:fs/promises";import u from"node:path";class c{static wait(t){return new Promise((s)=>setTimeout(s,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);this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:0})}success(...t){if(!this.config?.disableLogs)console.log("[FNLB ShardingManager] [OK]",...t);this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:1})}warn(...t){if(!this.config?.disableErrorLogs)console.warn("[FNLB ShardingManager] [WRN]",...t);this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:3})}error(...t){if(!this.config?.disableErrorLogs)console.error("[FNLB ShardingManager] [ERR]",...t);this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:4})}async update(){if(this.isLoaded)return;let t=u.join("zenith.js"),s=await g(t,"utf-8").catch(()=>null);this.log(s?"Checking for updates...":"Downloading FNLB...");let o=await fetch("https://dist.fnlb.net/packages/zenith/release");if(!o.ok)throw new Error(`[FNLB ShardingManager] Failed to check for updates, status code: ${o.status}`);let e=await o.json();if(s){let h=p("sha256");if(h.update(s),h.digest().toString("hex")===e.hash){this.success(`FNLB v${e.version} is up to date`),this.isLoaded=!0,this.success(`Finished loading FNLB v${e.version}`);return}this.log(`Downloading update for FNLB v${e.version}`)}let a=e.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${e.version}`);let l=await n.text();await f(t,l),this.isLoaded=!0,this.success(`Finished loading FNLB v${e.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 s=t.numberOfShards??1;for(let r=0;r<s;r++){let o=new Date,e=`${r.toString().padStart(2,"0")}/${o.getDay()}${o.getHours()}${o.getMinutes()}${o.getSeconds()}`,a=await this.startShard(t,e);this.activeProcesses.set(e,a)}}async stop(){this.log("Stopping all active processes..."),this.shouldRestart=!1;for(let[t,s]of this.activeProcesses)this.log(`Stopping process with id: ${t}`),s.kill();this.activeProcesses.clear(),this.log("All processes stopped.")}async startShard(t,s){if(await this.update(),!t?.apiToken)throw new Error("[FNLB ShardingManager] Please provide a FNLB API token.");this.log("Starting shard with id:",s);let r=d("zenith.js",[],{env:{...process.env,FORCE_COLOR:"1",SHARD_ID:s,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)r.stdout?.on("data",(o)=>{let e=o.toString("utf8");process.stdout.write(e),this.config?.onLogMessage?.({timestamp:Date.now(),content:e,format:0})});if(!this.config?.disableSubProcessErrorLogs)r.stderr?.on("data",(o)=>{let e=o.toString("utf8");process.stderr.write(e),this.config?.onLogMessage?.({timestamp:Date.now(),content:e,format:4})});return r.on("close",async(o)=>{if(this.activeProcesses.delete(s),this.shouldRestart){if(o===0)this.warn("Child process exited with code:",o?.toString()??"none");else this.error("Child process exited with code:",o?.toString()??"none");await c.wait(1e4);let e=await this.startShard(t,s);this.activeProcesses.set(s,e)}else this.log(`Child process ${s} stopped.`)}),r}}var D=i;export{D as default};
1
+ import{fork as d}from"node:child_process";import{createHash as p}from"node:crypto";import{readFile as g,writeFile as f}from"node:fs/promises";import u from"node:path";class c{static wait(t){return new Promise((s)=>setTimeout(s,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),this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:0})}success(...t){if(!this.config?.disableLogs)console.log("[FNLB ShardingManager] [OK]",...t),this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:1})}warn(...t){if(!this.config?.disableErrorLogs)console.warn("[FNLB ShardingManager] [WRN]",...t),this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:3})}error(...t){if(!this.config?.disableErrorLogs)console.error("[FNLB ShardingManager] [ERR]",...t),this.config?.onLogMessage?.({timestamp:Date.now(),content:t.join(" "),format:4})}async update(){if(this.isLoaded)return;let t=u.join("zenith.js"),s=await g(t,"utf-8").catch(()=>null);this.log(s?"Checking for updates...":"Downloading FNLB...");let o=await fetch("https://dist.fnlb.net/packages/zenith/release");if(!o.ok)throw new Error(`[FNLB ShardingManager] Failed to check for updates, status code: ${o.status}`);let e=await o.json();if(s){let h=p("sha256");if(h.update(s),h.digest().toString("hex")===e.hash){this.success(`FNLB v${e.version} is up to date`),this.isLoaded=!0,this.success(`Finished loading FNLB v${e.version}`);return}this.log(`Downloading update for FNLB v${e.version}`)}let a=e.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${e.version}`);let l=await n.text();await f(t,l),this.isLoaded=!0,this.success(`Finished loading FNLB v${e.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 s=t.numberOfShards??1;for(let r=0;r<s;r++){let o=new Date,e=`${r.toString().padStart(2,"0")}/${o.getDay()}${o.getHours()}${o.getMinutes()}${o.getSeconds()}`,a=await this.startShard(t,e);this.activeProcesses.set(e,a)}}async stop(){this.log("Stopping all active processes..."),this.shouldRestart=!1;for(let[t,s]of this.activeProcesses)this.log(`Stopping process with id: ${t}`),s.kill();this.activeProcesses.clear(),this.log("All processes stopped.")}async startShard(t,s){if(await this.update(),!t?.apiToken)throw new Error("[FNLB ShardingManager] Please provide a FNLB API token.");this.log("Starting shard with id:",s);let r=d("zenith.js",[],{env:{...process.env,FORCE_COLOR:"1",SHARD_ID:s,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()},stdio:["inherit","pipe","pipe","ipc"]});if(!this.config?.disableSubProcessLogs)r.stdout?.on("data",(o)=>{let e=o.toString("utf8");process.stdout.write(e),this.config?.onSubProcessLogMessage?.({timestamp:Date.now(),content:e,format:0})});if(!this.config?.disableSubProcessErrorLogs)r.stderr?.on("data",(o)=>{let e=o.toString("utf8");process.stderr.write(e),this.config?.onSubProcessLogMessage?.({timestamp:Date.now(),content:e,format:4})});return r.on("close",async(o)=>{if(this.activeProcesses.delete(s),this.shouldRestart){if(o===0)this.warn("Child process exited with code:",o?.toString()??"none");else this.error("Child process exited with code:",o?.toString()??"none");await c.wait(1e4);let e=await this.startShard(t,s);this.activeProcesses.set(s,e)}else this.log(`Child process ${s} stopped.`)}),r}}var D=i;export{D as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnlb",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "author": "FNLB-Project",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {