Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var discord = require("discord.js");
- var client = new discord.Client();
- var fs = require("fs"),
- time = 10000,
- settings = {}
- var runtimes = {}, prefix = "#";
- fs.readFile(__dirname + "/settings.json", (error, data) => {
- if (error) return fs.writeFile(__dirname + "/settings.json", "{\"tags\":{}}", e => {});
- settings = JSON.parse(data);
- });
- client.on("ready", pingTrash);
- function pingTrash() {
- client.channels.get("234257773079035914").send("Ok").then(m => m.delete());
- console.log("Pinged #trash");
- }
- setInterval(pingTrash, 61000);
- client.on("message", message => {
- if (message.author.id != 263617003904958465) return;
- var args = message.content.split(" ");
- /* ///////////////// NODE.JS EXECUTION ///////////////// */
- if (args[0] == prefix + "eval") {
- message.delete();
- message.channel.send({
- embed: {
- title: "Executing Javascript",
- color: 0x336699,
- description: "Executing Javascript. Please wait."
- }
- }).then(messag => {
- var arg2 = args.splice(1).join(" ");
- var code = arg2.replace(/\`\`\`(js|javascript)/, "");
- if (code == arg2) {
- code = arg2.replace("```", "");
- if (code == args.splice(1).join(" ")) {
- return messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "Failed to execute code: Invalid command syntax."
- }
- });
- }
- }
- code = code.substring(0, code.length - 3);
- var id = Math.random().toString(36).substr(7, 3), output = "\n";
- fs.writeFile(`${__dirname}/nodejs_execute_${id}.js`, code, err => {
- if (err) return messag.edit({
- embed: {
- title: "Executing Javascript",
- color: 0x336699,
- description: "Failed to execute code, could not write file."
- }
- });
- messag.edit({
- embed: {
- title: "Executing Javascript",
- color: 0x336699,
- description: "**Code:**```js\n" + code.substr(0, 500) + "```**Output:**``` ```"
- }
- });
- var child_process = require("child_process");
- var _ = child_process.exec(`node "${__dirname}/nodejs_execute_${id}.js"`, (error, stdout, stdin) => {
- if (!error) messag.edit({
- embed: {
- title: "Executing Javascript",
- color: 0x336699,
- description: "**Code:**```js\n" + code + "```**Output:**```" + stdout.toString() + "```"
- }
- }); else messag.edit({
- embed: {
- title: "Executing Javascript",
- color: 0x336699,
- description: "**Code:**```js\n" + code + "```**Error:**```" + error.toString().replace(/C:\\Users\\.+(?:\\)/g, "<path>/") + "```"
- }
- });
- fs.unlink(`${__dirname}/nodejs_execute_${id}.js`, () => {});
- });
- });
- });
- }
- /* ///////////////// NODE.JS ENVIRONMENT ///////////////// */
- if (args[0] == prefix + "nodejs-runtime" || args[0] == prefix + "?nre") {
- message.delete();
- message.channel.send({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "Preparing Node.js Runtime Environment, please stand by."
- }
- }).then(messag => {
- var arg2 = args.splice(1).join(" ");
- var code = arg2.replace(/\`\`\`(js|javascript)/, "");
- if (code == arg2) {
- code = arg2.replace("```", "");
- if (code == args.splice(1).join(" ")) {
- return messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "Failed to execute code: Invalid command syntax."
- }
- });
- }
- }
- code = code.substring(0, code.length - 3);
- var id = Math.random().toString(36).substr(7, 3), output = "\n";
- fs.writeFile(`${__dirname}/nodejs_environment_${id}.js`, code, err => {
- if (err) return messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "Failed to execute code, could not write file."
- }
- });
- messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "**ID: " + id + "**\n**Code:**```js\n" + code.substr(0, 500) + "```**Output:**``` ```"
- }
- });
- var child_process = require("child_process");
- runtimes[id] = child_process.spawn(`node`, [`${__dirname}/nodejs_environment_${id}.js`]);
- setTimeout(function () {
- if (!runtimes[id]) return;
- runtimes[id].stdin.pause();
- runtimes[id].kill();
- }, 300000);
- runtimes[id].stdout.on("data", (d) => {
- output = output + d.toString();
- messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "**ID: " + id + "**\n**Code:**```js\n" + code.substr(0, 500) + "```**Output:**```" + output.substr(output.length - 500) + "```"
- }
- });
- });
- runtimes[id].on("exit", (d) => {
- message.channel.send({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: `NRE \`${id}\` has closed.`
- }
- });
- delete runtimes[id];
- fs.unlink(`${__dirname}/nodejs_environment_${id}.js`, () => {});
- });
- runtimes[id].stderr.on("data", (d) => {
- messag.edit({
- embed: {
- title: "Node.js Runtime Environment",
- color: 0x336699,
- description: "**ID: " + id + "**\n**Code:**```js\n" + code.substr(0, 500) + "```**Output:**```" + output.substr(output.length - 500) + "```**Error:**```" + d.toString().replace(/C:\\Users\\.+(?:\\)/g, "<path>/") + "```"
- }
- });
- });
- });
- });
- }
- if (args[0] == prefix + "close-rt") {
- message.delete();
- runtimes[args[1]].stdin.pause();
- runtimes[args[1]].kill();
- }
- if (args[0] == prefix + "tag") {
- message.delete();
- if (!args[1]) return;
- if (args[1] == "-c") {
- if (args[2] && args[3]) {
- settings.tags[args[2].toLowerCase()] = args.splice(3).join(" ");
- }
- } else if (args[1] == "-l") {
- message.channel.send({
- embed: {
- title: "Tag",
- color: 0x336699,
- description: Object.keys(settings.tags).toString()
- }
- });
- } else if (args[1] == "-d") {
- if (args[2]) {
- delete settings.tags[args[2].toLowerCase()];
- }
- } else {
- var tag = settings.tags[args[1].toLowerCase()];
- if (!tag) message.channel.send(`Tag '${args[1]}' not found.`);
- while (tag.substr(0, 2) == "a:") {
- tag = settings.tags[tag.substr(2)].toLowerCase();
- console.log(tag);
- }
- message.channel.send(tag || `Tag '${args[1]}' not found.`);
- }
- fs.writeFile(`${__dirname}/settings.json`, JSON.stringify(settings), err => {});
- }
- for (let i = 0;i < args.length; i++){
- let a = args[i].toLowerCase();
- if (a.match(/\?.+/g) && a.match(/\?.+/g)[0] == a) {
- let v = a.substr(1);
- if (settings.tags[v]) {
- var tag = settings.tags[v];
- if (!tag) return;
- while (tag.substr(0, 2) == "a:") {
- tag = settings.tags[tag.substr(2)].toLowerCase();
- if (!tag) return;
- console.log(tag);
- }
- args[i] = tag;
- message.edit(args.join(" "));
- }
- }
- }
- });
- client.login("MjYzNjE3MDAzOTA0OTU4NDY1.DFtH7A.44t7aYtRQPvRdgWPu4HTEZHJNIw");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement