JSFiddle - React, Tailwind, and code Playground
by electronoob
JavaScript
var command = "!ls";
var result = {
err: "",
stdout: "cocks\ncocks\nlol\n",
stderr: "trollolol"
};
// stuff to get repo code functioning
var message = {
author: {},
channel: {
send: function (e) {console.log(e)},
id: "790410772302921770"
},
content: command
};
function exec(command, callback) {
console.log("exec", command);
callback(result.err, result.stdout, result.stderr);
}
msg(message);
// below code from repo unmodified
function msg (message) {
if (message.author.bot) return;
/**
* Checks if message starts with string
* @param {string} string - beginning string to check
* @returns {boolean} if message starts with string
*/
function msgStartsWith(string) {
if (message.content.substr(0, string.length) == string) {
return true
} else {
return false
}
}
/**
* Exectues the command and sends text
* @param {string} command - Command to be executed
* @param {true} [isCodeBlock] - If the return text should be in Code Block format
*/
function execute(command, isCodeBlock) {
// console.log("35: execute function start")
exec(command, (err, stdout, stderr) => {
let text = ""
if (stderr) {
// console.log("39: stderr")
text += "stderr```\n" + stderr.substr(0, 1000 - 16) + "```\n"
text += "stdout```\n" + stdout.substr(0, 1000 - 14) + "```"
} else {
// console.log("43: else no stderr")
if (isCodeBlock) { text += "```" }
text += "\n" + stdout.substr(0, 2000 - 8)
if (isCodeBlock) { text += "```" }
}
// Change command to executable if not found err
if (stderr == `/bin/sh: 1: ${command.substr(0, command.indexOf(" "))}: not found\n` && command.substr(0, 2) != "./") {
// console.log("54: change command as executable")
execute("./" + command, isCodeBlock)
} else {
// console.log("54: send text")
message.channel.send(text)
}
})
}
if...