From 6f09ed9cf8359bbc47fec0c56638765a9ea89231 Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 18 Jul 2023 13:00:11 +0000 Subject: [PATCH] vm2 instead of sandbox, remove googlesearch --- chatCommands.js | 95 +++++++++++++------------------------------------ 1 file changed, 24 insertions(+), 71 deletions(-) diff --git a/chatCommands.js b/chatCommands.js index 1b3abec..31751c6 100644 --- a/chatCommands.js +++ b/chatCommands.js @@ -1,35 +1,7 @@ "use strict"; let crypto = require("crypto"); -let Sandbox = require("sandbox"); -let google = require("google"); -google.resultsPerPage = 1; -google.lang = "de"; -google.tld = "de"; -google.nextText = "Weiter"; - -const googleSearch = function (client, o) { - google(o.args, function (err, res) { - if (err) return; - - const links = res.links; - - if (links.length === 0) { - client.say(o.to, o.from + ": could not find anything D:"); - } - else { - client.say(o.to, o.from + ": " + links[0].link + " " + links[0].title + " - " + links[0].description.replace(/(\r\n|\r|\n|\t)/g, " ")); - } - }); -}; - -let s = new Sandbox({ - timeout: 1000 -}); - -setInterval(x=>{ - s.run("true", x=>{}); -}, 10000); +let VM = require('vm2').VM; let sbhead = "\"use strict\";const mett=9000,belst=Math.random()*mett|0;"; sbhead += Object.getOwnPropertyNames(Math).map(function(v){return "const " + v + "=Math." + v + ";"}).join(""); @@ -56,25 +28,25 @@ p.run = function (o) { if (level === null || level === undefined) level = -1; switch(o.cmd) { case ".adhs": - let fuckyoujs = [...o.args.toLowerCase()]; + let fuckyoujs = [...(o.args || o.from).toLowerCase()]; fuckyoujs = fuckyoujs.filter(c => /[a-z]/.test(c)); fuckyoujs = fuckyoujs.map((c, i) => { return alphanoise[((c.charCodeAt() -97) * (i+1) * 107) %26] /26; }).reduce((a,b)=>a+b) %1; - client.say(o.to, o.args + " has " + (fuckyoujs * 100).toFixed(2) + "% adhs"); + client.say(o.to, (o.args || o.from) + " has " + (fuckyoujs * 100).toFixed(2) + "% adhs"); return true; case ".level": client.say(o.to, o.from + " your level: " + userLevelNames[level]); return true; case ".reboot": - if (level < getLevel("admin") || o.args != "yourself") { + if (level < getLevel("admin")) { client.say(o.to, o.from + " go kill yourself"); break; } client.say(o.to, "kthx bai"); setTimeout(process.exit, 100); return true; - case ".reg": + /*case ".reg": if (level < getLevel("admin")) { client.say(o.to, o.from + ": your level: " + userLevelNames[level] + ", needed level: admin"); return true; @@ -87,7 +59,11 @@ p.run = function (o) { exec("/bin/bash /home/sirx/web/w0bm.com/resources/views/"+o.args+".sh", (err, sout, serr)=>{ client.say(o.to, "Registration successfully " + (o.args == "open" ? "opened you can now register your account at https://w0bm.com/register" : "closed")); }); - break; + break;*/ + + case ".reg": + client.say(o.to, "User limit reached"); + return true; case ".status": /*if (level < getLevel("admin")) { client.say(o.to, o.from + ": dein level: " + userLevelNames[level] + ", benötigtes level: admin"); @@ -96,11 +72,11 @@ p.run = function (o) { db.getConnection((err, con) => { if (err) { - client.say(o.to, "sorry.. datenbank is kapott D: BKA belst gz"); - con.release(); + client.say(o.to, "sorry.. datenbank is kapott D: nixc jkhsjdhjs Flummi"); + console.error(err); return; } - con.query("select disabled, deleted_at, banend, banreason, verified from users where username like ?", o.args, (err, rows, fields) => { + con.query("select disabled, deleted_at, banend, banreason, verified from users where username like ?", o.args || o.from, (err, rows, fields) => { if (err) { client.say(o.to, "ich bin zu doof zum coden.. hier hat sich ein fehler eingeschlichen D:"); con.release(); @@ -124,7 +100,7 @@ p.run = function (o) { if (row.banend) stati.push("gebannt mit grund: " + row.banreason + ", bis: " + row.banend); if (row.deleted_at) stati.push("gelöscht seit: " + row.deleted_at); - client.say(o.to, o.args + " ist: " + stati.join(", ")); + client.say(o.to, (o.args || o.from) + " ist: " + stati.join(", ")); /*var vid = rows[0]; if (!vid.id) { client.say(to, from + ": konnte kein video finden D:"); @@ -163,15 +139,16 @@ p.run = function (o) { return true; case "js": - /*if (level < getLevel("voiced")) { - client.say(o.to, o.from + ": dein level: " + userLevelNames[level] + ", benötigtes level: voiced"); - return true; - }*/ - s.run(sbhead + o.args + "+\"\"", function (out) { - let con = out.console.length > 0 ? " and printed to console: " + out.console : ""; - let text = (out.result + con).replace(/[\r\n\t]/g, " "); - client.say(o.to, o.from + " it returned: " + (text.length > 400 ? "fuck you" : text)); - }); + let s = new VM({timeout: 1000, sandbox: {}}); + let text; + try { + const out = s.run(sbhead + o.args + "+\"\""); + text = out.replace(/[\r\n\t]/g, " "); + } + catch(e) { + text = e.toString(); + } + client.say(o.to, o.from + " it returned: " + (text.length > 400 ? "fuck you" : text)); return true; case "throw": @@ -191,30 +168,6 @@ p.run = function (o) { client.say(o.to, o.from + ": i'd choose: " + choice); return true; - case ".mdn": - case "mdn": - o.args += " site:developer.mozilla.org"; - googleSearch(client, o); - return true; - - case "hoogle": - case ".hs": - case "hs": - case "hss": - o.args += " site:www.haskell.org/hoogle/"; - googleSearch(client, o); - return true; - - case ".die": - o.args += " site:die.net"; - googleSearch(client, o); - return true; - - //case "google": - case ".google": - googleSearch(client, o); - return true; - case "b2o": case "b2d": case "b2h":