"use strict"; let crypto = require("crypto"); 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(""); let handleChatCommands = function (irc, db) { this.irc = irc; this.db = db; }; let p = handleChatCommands.prototype; const userLevels = ["","+","%","@","&","~"]; const userLevelNames = ["user", "voiced", "halfop", "op", "admin", "owner"]; const getLevel = name => userLevelNames.indexOf(name); const exec = require("child_process").exec; const alphanoise = [8,20,10,14,12,11,26,16,4,21,22,13,24,6,5,15,2,23,7,19,18,25,9,3,17,1]; p.run = function (o) { let client = this.irc.client; let db = this.db; //let level = client.chans[o.to] ? client.chans[o.to].users[o.from] : undefined; let level = client.chans["#w0bm"] ? client.chans["#w0bm"].users[o.from] : undefined; level = level !== undefined ? level.split("").map(x=>userLevels.indexOf(x)).sort().pop() : -1; if (level === null || level === undefined) level = -1; switch(o.cmd) { case ".adhs": 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 || 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")) { client.say(o.to, o.from + " go kill yourself"); break; } client.say(o.to, "kthx bai"); setTimeout(process.exit, 100); return true; /*case ".reg": if (level < getLevel("admin")) { client.say(o.to, o.from + ": your level: " + userLevelNames[level] + ", needed level: admin"); return true; } if (!~["open", "close"].indexOf(o.args)) { client.say(o.to, "momentane befehle: open und close"); return true; } client.say(o.to, "Your word is my command"); 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;*/ 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"); return true; }*/ db.getConnection((err, con) => { if (err) { 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 || 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(); return; } if (rows.length == 0) { client.say(o.to, "konnte keinen benutzer mit dem namen finden D:"); con.release(); return; } if (rows.length > 1) { client.say(o.to, "fick dich. hör auf wildcards zu nutzen… oder… wir haben ein datenbank problem…"); con.release(); return; } const row = rows[0]; const stati = []; if (row.disabled) stati.push("deaktiviert"); if (!row.disabled) stati.push("aktiviert"); if (!row.verified) stati.push("nicht verifiziert"); 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 || o.from) + " ist: " + stati.join(", ")); /*var vid = rows[0]; if (!vid.id) { client.say(to, from + ": konnte kein video finden D:"); con.release(); return; } var txt = []; if (vid.deleted_at) txt.push("\x02gelöscht\x0f"); if (webm) txt.push("Link: \x02https://w0bm.com/" + vid.id + "\x0f"); ["interpret", "songtitle", "category", "username", "comments"].forEach((v, i) => { if (vid[v]) { txt.push( ["Interpret", "Titel", "Kategorie", "Uploader", "Kommentare"][i] + ": " +"\x02" + vid[v] + "\x0f"); } }); client.say(to, txt.join(" | "));*/ con.release(); }); }); return true; case "md5sum": case "sha1sum": case "sha256sum": case "sha512sum": o.cmd = o.cmd.substr(0, o.cmd.length -3); case "md5": case "sha1": case "sha256": case "sha512": let crypt = crypto.createHash(o.cmd); crypt.update(o.args); client.say(o.to, "teh " + o.cmd + " sum iz: " + crypt.digest("hex")); return true; case "js": 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": if (o.args != "a dice") break; client.say(o.to, o.from + ": the magic dice shows " + ((Math.random()*6|0)+1) + " eyes."); return true; case ".choose": case "choose:": case "choice:": let choices = o.args.split(",").map((str)=>str.trim()); if (choices.length < 2) { client.say(o.to, "fuck you " + o.from + "!"); return true; }; let choice = ~choices.indexOf("w0bm") ? "w0bm of course!" : choices[Math.random() * choices.length | 0]; client.say(o.to, o.from + ": i'd choose: " + choice); return true; case "b2o": case "b2d": case "b2h": case "o2b": case "o2d": case "o2h": case "d2b": case "d2o": case "d2h": case "h2b": case "h2o": case "h2d": if ({b:/[^01]/,o:/[^0-7]/,d:/[^\d]/,h:/[^\da-fA-F]/}[o.cmd[0]].test(o.args)) return false; client.say(o.to, o.from + ": " + parseInt(o.args, {b:2,o:8,d:10,h:16}[o.cmd[0]]).toString({b:2,o:8,d:10,h:16}[o.cmd[2]])); return true; } return false; }; module.exports = function (irc, db) { let hcc = new handleChatCommands(irc, db); return function (o) { hcc.run(o); } };