This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
86 lines (81 loc) · 2.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { spawn } from "child_process";
import readline from "readline";
import { WebSocketServer } from "ws";
import chalk from "chalk";
let connected = false;
const logUtils = {
incoming: (message) => {
logUtils.info(chalk.greenBright("<-- ") + message);
},
info: (message) => {
logUtils.clearLine();
console.info(message);
if (connected) process.stdout.write(chalk.cyanBright("--> "));
},
success: (message) => {
logUtils.clearLine();
console.info(chalk.greenBright(message));
},
error: (message) => {
logUtils.clearLine();
console.error(chalk.redBright(message));
},
clearLine: () => {
process.stdout.clearLine();
process.stdout.cursorTo(0);
}
};
const wss = new WebSocketServer({ port: 3000 });
wss.on("connection", async (ws) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
ws.on("message", data => {
const parsed = JSON.parse(data.toString());
switch (parsed.level) {
case 0:
logUtils.info(`${chalk.bold("T:")} ` + parsed.message);
break;
case 1:
logUtils.info(`${chalk.greenBright("I:")} ` + parsed.message);
break;
case 2:
logUtils.info(`${chalk.yellow("W:")} ` + parsed.message);
break;
case 3:
logUtils.info(`${chalk.redBright("E:")} ` + parsed.message);
break;
}
});
ws.on("close", () => {
connected = false;
rl.close();
logUtils.error("Websocket connection closed, waiting for reconnection");
});
logUtils.incoming("Discord client connected to websocket");
connected = true;
while (connected) {
await new Promise(r => {
rl.question(chalk.cyanBright("--> "), (cmd) => {
if (!connected) return;
else if (["exit", "quit"].includes(cmd)) {
ws.close();
process.exit();
} else if (cmd == "clear") {
console.clear();
process.stdout.write(chalk.cyanBright("--> "));
} else if (/^\s*$/.test(cmd)) {
r();
} else {
ws.send(cmd);
r();
}
});
});
}
});
spawn("adb", ["reverse", "tcp:3000", "tcp:3000"], { stdio: "ignore" }).on("exit", (code) => {
if (code !== 0) logUtils.error(`Port forwarding port 3000 with adb exited with code ${code}, aliucord may not load`);
else logUtils.success("Successfully forwarded port 3000 to phone with adb");
});