snapshot before merge
This commit is contained in:
1 parent
06a5f3da4d
commit
671871e0b2
145 files changed
+9786
-59
No files matched your search
@@ -0,0 +1,63 @@
|
||||
const fs = require("fs");
|
||||
const path = "E:/GitHub/blog/bot/index.js";
|
||||
let c = fs.readFileSync(path, "utf8");
|
||||
|
||||
// Fix the broken start/stop/status/ip handlers (newlines got literalized)
|
||||
// Remove the broken block and re-insert correctly
|
||||
|
||||
var brokenStart = c.indexOf("\nCMD_HANDLERS.start = async function (chatId) {");
|
||||
if (brokenStart === -1) { console.log("ERR: no start"); process.exit(1); }
|
||||
// Find end of ip handler (the `},` before CMD_HANDLERS.view)
|
||||
var afterIp = c.indexOf("CMD_HANDLERS.view = async function", brokenStart);
|
||||
if (afterIp === -1) { console.log("ERR: no view after"); process.exit(1); }
|
||||
|
||||
// Remove broken block
|
||||
c = c.substring(0, brokenStart + 1) + c.substring(afterIp);
|
||||
|
||||
// Insert correct handlers
|
||||
var correctHandlers = `
|
||||
CMD_HANDLERS.start = async function (chatId) {
|
||||
if (writeProcess && writeReady) {
|
||||
var ip = getLanIP();
|
||||
await sendMessage(chatId, "\\u2705 Write is running\\n\\nDesktop: http://localhost:" + WRITE_PORT + "\\nPhone: http://" + ip + ":" + WRITE_PORT);
|
||||
return CMD_HANDLERS.help(chatId);
|
||||
}
|
||||
if (writeProcess && !writeReady) {
|
||||
return sendMessage(chatId, "\\u23f3 Write is starting, please wait...");
|
||||
}
|
||||
var result = startWriteServer();
|
||||
if (!result.started) return sendMessage(chatId, "\\u274c Failed to start");
|
||||
await sendMessage(chatId, "\\u23f3 Starting Write...");
|
||||
var ready = await waitForReady(WRITE_PORT);
|
||||
if (ready) {
|
||||
writeReady = true;
|
||||
var ip = getLanIP();
|
||||
await sendMessage(chatId, "\\u2705 Write is ready!\\n\\nDesktop: http://localhost:" + WRITE_PORT + "\\nPhone: http://" + ip + ":" + WRITE_PORT);
|
||||
return CMD_HANDLERS.help(chatId);
|
||||
}
|
||||
return sendMessage(chatId, "\\u274c Start timed out, check console log.");
|
||||
},
|
||||
async stop(chatId) {
|
||||
if (!writeProcess) return sendMessage(chatId, "\\u23f8 Write is not running.");
|
||||
stopWriteServer();
|
||||
return sendMessage(chatId, "\\u26a1 Write stopped.");
|
||||
},
|
||||
async status(chatId) {
|
||||
var s = getWriteStatus();
|
||||
var status = s.running ? "\\u2705 Running" : s.starting ? "\\u23f3 Starting..." : "\\u23f8 Stopped";
|
||||
var lines = ["Status: " + status];
|
||||
if (s.running) {
|
||||
lines.push("Local: http://localhost:" + WRITE_PORT);
|
||||
lines.push("Phone: http://" + s.ip + ":" + WRITE_PORT);
|
||||
}
|
||||
return sendMessage(chatId, lines.join("\\n"));
|
||||
},
|
||||
async ip(chatId) {
|
||||
var ip = getLanIP();
|
||||
return sendMessage(chatId, "Phone: http://" + ip + ":" + WRITE_PORT + " (" + PREFER_IFACE + ")");
|
||||
},
|
||||
`;
|
||||
|
||||
c = c.substring(0, brokenStart + 1) + correctHandlers + c.substring(brokenStart + 1);
|
||||
fs.writeFileSync(path, c, "utf8");
|
||||
console.log("start/stop/status/ip fixed");
|
||||
Reference in new issue
Block a user