@mincraft/cli 1.5.0 → 1.5.1
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/dist/index.mjs +3 -3
- package/package.json +2 -2
- package/src/cli.ts +2 -2
- package/src/index.ts +0 -2
- package/src/repl.ts +1 -1
- package/src/version.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Option as O,program as l}from"commander";function F(t){let o=[],e="",r=0;for(;r<t.length;)t[r]==="\\"&&r+1<t.length?(e+=t[r]+t[r+1],r+=2):t[r]===","?(o.push(e),e="",r++):(e+=t[r],r++);return o.push(e),o}function T(t){let o="",e=0;for(;e<t.length;)if(t[e]==="\\"&&e+1<t.length){let r=t[e+1];r===","||r==="{"||r==="}"?(o+=r,e+=2):(o+=t[e],e++)}else o+=t[e],e++;return o}function C(t){let o=[],e=F(t),r=/^\{\{(\d+(?:\.\d+)?)\}\}$/;for(let
|
|
3
|
-
`);if(e.length===1)this.logger.log(o,"chat");else{this.logger.log(e[0],"chat");for(let r=1;r<e.length;r++)this.logger.raw(` ${e[r]}`)}})}disconnect(){this.bot&&(this.proxy?this.bot._client.socket?.destroy():this.bot.quit(),this.isLoggedIn=!1)}sendMessage(o){this.bot.chat(o)}};import*as y from"readline";import h from"chalk";function U(t){return t?`/${t.split("/").map((r,
|
|
2
|
+
import{Option as O,program as l}from"commander";function F(t){let o=[],e="",r=0;for(;r<t.length;)t[r]==="\\"&&r+1<t.length?(e+=t[r]+t[r+1],r+=2):t[r]===","?(o.push(e),e="",r++):(e+=t[r],r++);return o.push(e),o}function T(t){let o="",e=0;for(;e<t.length;)if(t[e]==="\\"&&e+1<t.length){let r=t[e+1];r===","||r==="{"||r==="}"?(o+=r,e+=2):(o+=t[e],e++)}else o+=t[e],e++;return o}function C(t){let o=[],e=F(t),r=/^\{\{(\d+(?:\.\d+)?)\}\}$/;for(let s of e){let n=s.trim();if(!n)continue;let a=n.match(r);if(a){let i=parseFloat(a[1]),c=Math.round(i*1e3);o.push({command:"",delay:c})}else{let i=T(n);o.push({command:i,delay:0})}}return o}import*as E from"readline";import p from"chalk";import{createBot as A}from"mineflayer";import{SocksClient as D}from"socks";var u=class{proxy;client;server;options;logger;isLoggedIn;bot;constructor({proxy:o,client:e,server:r,options:s},n){this.proxy=o,this.client=e,this.server=r,this.options=s,this.logger=n,this.isLoggedIn=!1}async registerAndLogIn(){let o={host:this.server.host,port:this.server.port,username:this.client.account.email,auth:this.client.account.auth,version:this.client.version,hideErrors:!0};this.proxy&&(o.connect=e=>{this.connectViaProxy(e)}),this.bot=A(o),this.options.verboseLogging&&this.registerClientEvents(),this.registerBotEvents()}connectViaProxy(o){this.logger.log("connecting via proxy");let{host:e,port:r,user:s,pass:n,type:a}=this.proxy,i=this.server;D.createConnection({proxy:{host:e,port:r,type:a,userId:s,password:n},command:"connect",destination:{host:i.host,port:i.port},timeout:3e4}).then(c=>{o.setSocket(c.socket),o.emit("connect")}).catch(c=>{this.logger.error(`proxy connection failed: ${c.message}`),o.emit("error",c)})}registerClientEvents(){this.bot._client.on("connect",()=>{this.logger.log("TCP connection established")}),this.bot._client.on("login",()=>{this.logger.log("login packet received")}),this.bot._client.on("error",o=>{this.logger.error(`client error: ${o.message}`)}),this.bot._client.on("end",o=>{this.logger.warn(`client ended: ${o}`)})}registerBotEvents(){this.bot.once("spawn",()=>{let{ign:o,uuid:e}=this.client.account;this.logger.log(`logged in as ${o} (${e})`),this.isLoggedIn=!0}),this.bot.once("kicked",o=>{this.logger.warn(`kicked: ${JSON.stringify(o)}`),this.disconnect()}),this.bot.once("error",o=>{this.logger.error(`bot error: ${o.message}`),this.isLoggedIn=!1}),this.bot.once("end",o=>{this.logger.warn(`disconnected by server: ${JSON.stringify(o)}`),this.disconnect()}),this.options.logMessages&&this.bot.on("messagestr",o=>{let e=o.split(`
|
|
3
|
+
`);if(e.length===1)this.logger.log(o,"chat");else{this.logger.log(e[0],"chat");for(let r=1;r<e.length;r++)this.logger.raw(` ${e[r]}`)}})}disconnect(){this.bot&&(this.proxy?this.bot._client.socket?.destroy():this.bot.quit(),this.isLoggedIn=!1)}sendMessage(o){this.bot.chat(o)}};import*as y from"readline";import h from"chalk";function U(t){return t?`/${t.split("/").map((r,s)=>s===0?r==="err"?h.red(r):r==="warn"?h.yellow(r):h.gray(r):h.blue(r)).join("/")}`:""}function m(t,o){let e=(s,n="")=>{let a=o?n?`${o}/${n}`:o:n;return`[mc${U(a)}] ${s}`},r=s=>{t?(y.clearLine(process.stdout,0),y.cursorTo(process.stdout,0),console.log(s),t.prompt(!0)):console.log(s)};return{log:(s,n)=>r(e(s,n)),warn:(s,n="warn")=>r(e(s,n)),error:(s,n="err")=>r(e(s,n)),raw:r}}import*as f from"fs/promises";import*as d from"path";import*as $ from"esbuild";async function j(t){let e=(await $.build({entryPoints:[t],bundle:!0,write:!1,platform:"node",format:"esm",target:"es2022",loader:{". ts":"ts"},external:["mineflayer"],logLevel:"silent"})).outputFiles[0].text,r=t.replace(/\.ts$/,". macro.mjs");return await f.writeFile(r,e),r}async function B(t){try{await f.unlink(t)}catch{}}function N(t){return d.isAbsolute(t)?t:d.resolve(process.cwd(),t)}async function R(t){try{return await f.access(t),!0}catch{return!1}}function _(t){return d.basename(t).replace(/\.(ts|js|mjs)$/,"")}async function L(t,o,e){let r=N(t),s=r,n=null,a=m(e,`macro/${_(t)}`);try{if(!await R(r))return a.error(`file not found: ${r}`),!1;r.endsWith(".ts")&&(a.log("compiling macro to js"),n=await j(r),s=n);let g=await import(`file://${s}?t=${Date.now()}`);return typeof g.default!="function"?(a.error("macro file must export a default function"),!1):(a.log("running"),await g.default({bot:o,logger:a}),a.log("finished"),!0)}catch(i){return a.error(`failed: ${i.message}`),!1}finally{n&&await B(n)}}var x="v1.5.1";var P=(n=>(n.Exit=".exit",n.Logout=".lo",n.Login=".li",n.Macro=".macro",n.Help=".help",n))(P||{});function I(t){return Object.values(P).some(o=>t.startsWith(o))}function H(t,o){t(`type ${p.magenta(".li")} to log in to ${o}`),t(`type ${p.magenta(".lo")} to log out from ${o}`),t(`type ${p.magenta(".macro <filepath>")} to run a macro`),t(`type ${p.magenta(".help")} to show this REPL reference`),t(`type ${p.magenta(".exit")} to exit the REPL`),t(`type ${p.bold("any other value")} to send a message to the server`)}async function M(t,o){process.stdout.write("\x1B[2J\x1B[2;0H");let e=null,r=E.createInterface({input:process.stdin,output:process.stdout}),s=m(r),n=i=>s.raw(`>> ${i}`);r.setPrompt("> ");let a=async i=>{if(i=i.trim(),!i)return!1;if(!I(i)&&!e?.isLoggedIn)return s.error("log in using .li before sending messages"),!1;if(I(i)){let[c,...g]=i.split(" ");switch(c){case".exit":return e?.disconnect(),r.close(),!0;case".li":{e?.isLoggedIn?s.error("client is already logged in"):(e=new u(t,s),e.registerAndLogIn());break}case".lo":{e?.isLoggedIn?e?.disconnect():s.error("client isn't logged in");break}case".macro":{if(!e?.isLoggedIn){s.error("client must be logged in to run macros");break}let w=g.join(" ");if(!w){s.error("usage: .macro <filepath>");break}let v=e.bot;v&&await L(w,v,r);break}case".help":{H(n,t.server.host);break}}}else e?.sendMessage(i);return!1};if(r.on("line",async i=>{await a(i)&&process.exit(0),r.prompt()}),console.log(p.green(`mincraft REPL ${x}`)),n('type ".help" for more information.'),o&&o.length>0)for(let{command:i,delay:c}of o)c>0&&await new Promise(g=>setTimeout(g,c)),i&&(s.raw(`> ${i}`),await a(i)&&process.exit(0));r.prompt()}l.name("mincraft").description("Mineflayer CLI tool with supports for macros and proxies.").version(x.slice(1)).addHelpText("after",`
|
|
4
4
|
Examples:
|
|
5
5
|
$ mincraft mc.hypixel.net 1.21.4 --ign FuriousDestroyer --email you@example.com
|
|
6
6
|
$ mincraft mythic.gg 1.7.10 -p 58585 --ign MangoSyrup --email you@example.com --prox proxy.com:1234:mango:secret
|
|
7
7
|
$ mincraft mc.hypixel.net 1.21.4 --ign Player --email you@example.com --exec "{{1}},.li,{{2.5}},hello,{{0.5}},.lo"
|
|
8
8
|
$ mincraft mc.hypixel.net 1.21.4 --ign Player --email you@example.com --exec "{{1.5}},.li,{{5}},hello\\,world,{{0.5}},.lo"
|
|
9
|
-
`);l.argument("<host>","Server hostname").option("-p, --port <PORT>","Server port",t=>parseInt(t,10),25565);l.argument("<version>","Client version, e.g. 1.21.4");var S=["host","port","user","pass"],k=":";l.option("--prox <HOST:PORT:USER:PASS>","Connect to the server with a proxy").option("--prox-field-order <FORMAT>",'The order of the proxy credential fields, e.g. "user,pass,host,port".').option("--prox-field-sep <SEP>","The separator of the proxy credential fields").option("--prox-type <4|5>","The SOCKS proxy type",t=>parseInt(t,10),5);var G="microsoft";l.addOption(new O("--ign <IN-GAME NAME>","Player username").conflicts("uuid")).addOption(new O("--uuid <UUID>","Player UUID").conflicts("ign")).requiredOption("--email <EMAIL>","Account email").option("--auth <AUTH>","Account authentication method",G);l.option("--no-log-messages","Do not log messages your client receives").option("--verbose","Enable additional logging messages").option("--exec <COMMANDS>",'Execute REPL commands on startup with optional delays, e.g. "{{1}},.li,{{2.5}},hello,{{0.5}},.lo", where {{N}} represents a delay. You can escape curly braces and commas to include them in commands/messages.',(t,o)=>o.concat(t),[]);l.action(async(t,o,e)=>{if(!e.ign&&!e.uuid&&l.error("error: must specify either --ign or --uuid"),e.proxFieldOrder){let
|
|
9
|
+
`);l.argument("<host>","Server hostname").option("-p, --port <PORT>","Server port",t=>parseInt(t,10),25565);l.argument("<version>","Client version, e.g. 1.21.4");var S=["host","port","user","pass"],k=":";l.option("--prox <HOST:PORT:USER:PASS>","Connect to the server with a proxy").option("--prox-field-order <FORMAT>",'The order of the proxy credential fields, e.g. "user,pass,host,port".').option("--prox-field-sep <SEP>","The separator of the proxy credential fields").option("--prox-type <4|5>","The SOCKS proxy type",t=>parseInt(t,10),5);var G="microsoft";l.addOption(new O("--ign <IN-GAME NAME>","Player username").conflicts("uuid")).addOption(new O("--uuid <UUID>","Player UUID").conflicts("ign")).requiredOption("--email <EMAIL>","Account email").option("--auth <AUTH>","Account authentication method",G);l.option("--no-log-messages","Do not log messages your client receives").option("--verbose","Enable additional logging messages").option("--exec <COMMANDS>",'Execute REPL commands on startup with optional delays, e.g. "{{1}},.li,{{2.5}},hello,{{0.5}},.lo", where {{N}} represents a delay. You can escape curly braces and commas to include them in commands/messages.',(t,o)=>o.concat(t),[]);l.action(async(t,o,e)=>{if(!e.ign&&!e.uuid&&l.error("error: must specify either --ign or --uuid"),e.proxFieldOrder){let n=e.proxyFieldSep??k;e.proxFieldOrder.split(n).every(i=>S.includes(i))||l.error("error: --prox-field-order includes invalid fields")}let r=await W(l),s=[];for(let n of e.exec){let a=C(n);s.push(...a)}await M(r,s.length>0?s:void 0)});async function J(t){let e=await(await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${t}`)).json();if(!e?.name)throw new Error("Could not fetch IGN from UUID");return e.name}async function q(t){let e=await(await fetch(`https://api.mojang.com/users/profiles/minecraft/${t}`)).json();if(!e?.id)throw new Error("Could not fetch UUID from IGN");return e.id}function V(t,o,e){let r=t.split(e),s=Object.fromEntries(o.map((n,a)=>[n,r[a]]));return s.port=+s.port,s}async function W(t){let o=t.args,e=t.opts();return{server:{host:o[0],port:e.port},client:{version:o[1],account:{auth:e.auth,uuid:e.uuid??await q(e.ign),ign:e.ign??await J(e.uuid),email:e.email}},...e.prox?{proxy:{...V(e.prox,e.proxFieldOrder??S,e.proxFieldSep??k),type:e.proxType}}:{},options:{logMessages:e.noLogMessages??!0,verboseLogging:e.verbose??!1}}}var b=m(),he=b.log,ye=b.warn,xe=b.error;l.parse();export{b as defaultLogger,xe as error,he as log,ye as warn};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mincraft/cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Mineflayer CLI tool with support for macros and proxies",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mincraft": "./dist/index.mjs"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"esbuild": "^0.27.2",
|
|
19
19
|
"mineflayer": "^4.33.0",
|
|
20
20
|
"socks": "^2.8.7",
|
|
21
|
-
"@mincraft/types": "1.5.
|
|
21
|
+
"@mincraft/types": "1.5.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/debug": "^4.1.12",
|
package/src/cli.ts
CHANGED
|
@@ -4,15 +4,15 @@ import type {
|
|
|
4
4
|
ProxyCredentials,
|
|
5
5
|
} from "@mincraft/types";
|
|
6
6
|
import { type Command, Option, program } from "commander";
|
|
7
|
-
import { version } from ".";
|
|
8
7
|
import { parseExecCommands } from "./exec";
|
|
9
8
|
import { run } from "./repl";
|
|
9
|
+
import { version } from "./version";
|
|
10
10
|
|
|
11
11
|
// meta
|
|
12
12
|
program
|
|
13
13
|
.name("mincraft")
|
|
14
14
|
.description("Mineflayer CLI tool with supports for macros and proxies.")
|
|
15
|
-
.version(version)
|
|
15
|
+
.version(version.slice(1))
|
|
16
16
|
.addHelpText(
|
|
17
17
|
"after",
|
|
18
18
|
`
|
package/src/index.ts
CHANGED
package/src/repl.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as readline from "node:readline";
|
|
2
2
|
import type { Config, DelayableCommands } from "@mincraft/types";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
-
import { version } from ".";
|
|
5
4
|
import { BotClient } from "./bot";
|
|
6
5
|
import { createLogger } from "./logger";
|
|
7
6
|
import { loadAndRunMacro } from "./macro";
|
|
7
|
+
import { version } from "./version";
|
|
8
8
|
|
|
9
9
|
export enum BotCommand {
|
|
10
10
|
Exit = ".exit",
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = "v1.5.1";
|