forked from cadence/out-of-your-element
Add heatsync and support hot reloading
This commit is contained in:
parent
7913b68c41
commit
11e5cd7f77
7 changed files with 155 additions and 106 deletions
48
index.js
48
index.js
|
@ -1,39 +1,23 @@
|
|||
const repl = require("repl")
|
||||
const util = require("util")
|
||||
const HeatSync = require("heatsync")
|
||||
|
||||
const config = require("./config")
|
||||
const passthrough = require("./passthrough")
|
||||
|
||||
const sync = new HeatSync()
|
||||
|
||||
Object.assign(passthrough, { config, sync })
|
||||
|
||||
const DiscordClient = require("./modules/DiscordClient")
|
||||
|
||||
const config = require("./config")
|
||||
|
||||
const discord = new DiscordClient(config.discordToken)
|
||||
passthrough.discord = discord
|
||||
|
||||
discord.cloud.connect().then(() => console.log("Discord gateway started"))
|
||||
;(async () => {
|
||||
await discord.cloud.connect()
|
||||
console.log("Discord gateway started")
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {import("vm").Context} _context
|
||||
* @param {string} _filename
|
||||
* @param {(err: Error | null, result: unknown) => unknown} callback
|
||||
* @returns
|
||||
*/
|
||||
async function customEval(input, _context, _filename, callback) {
|
||||
let depth = 0
|
||||
if (input === "exit\n") return process.exit()
|
||||
if (input.startsWith(":")) {
|
||||
const depthOverwrite = input.split(" ")[0]
|
||||
depth = +depthOverwrite.slice(1)
|
||||
input = input.slice(depthOverwrite.length + 1)
|
||||
}
|
||||
/** @type {unknown} */
|
||||
let result
|
||||
try {
|
||||
result = await eval(input)
|
||||
const output = util.inspect(result, false, depth, true)
|
||||
return callback(null, output)
|
||||
} catch (e) {
|
||||
return callback(e, undefined)
|
||||
}
|
||||
}
|
||||
require("./stdin")
|
||||
})()
|
||||
|
||||
const cli = repl.start({ prompt: "", eval: customEval, writer: s => s })
|
||||
cli.once("exit", process.exit)
|
||||
process.on("unhandledRejection", console.error)
|
||||
process.on("uncaughtException", console.error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue