commit b75598801122ccde2531eab1cb4964c88e408659 Author: Jan-Stefan Janetzky Date: Fri Nov 18 11:58:50 2016 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/boot.sh b/boot.sh new file mode 100755 index 0000000..9ce8ac9 --- /dev/null +++ b/boot.sh @@ -0,0 +1,11 @@ +#!/bin/bash +export NVM_DIR="/home/gz/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm + +nvm use node + +while true; do + echo starting node... $(date) + node index.js + sleep 3 +done diff --git a/chatCommands.js b/chatCommands.js new file mode 100644 index 0000000..78edfdf --- /dev/null +++ b/chatCommands.js @@ -0,0 +1,214 @@ +"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 sbhead = "\"use strict\";const mett=9000,belst=Math.random()*mett|0;"; + sbhead += Object.getOwnPropertyNames(Math).map(function(v){return "const " + v + "=Math." + v + ";" + (typeof Math[v] == "function" ? v + ".bind(Math);" : "")}).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; + +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 = typeof level != "undefined" ? level.split("").map(x=>userLevels.indexOf(x)).sort().pop() : -1; + if (level === null) level = -1; + switch(o.cmd) { + case ".reg": + if (level < getLevel("admin")) { + client.say(o.to, o.from + ": dein level: " + userLevelNames[level] + ", benötigtes 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, "kleinen moment bitte"); + exec("/bin/bash /var/www/w0bm.com/resources/views/"+o.args+".sh", (err, sout, serr)=>{ + client.say(o.to, "registrierung erfolgreich " + (o.args == "open" ? "geöffnet" : "geschlossen")); + }); + break; + 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: BKA belst gz"); + con.release(); + return; + } + con.query("select disabled, deleted_at, banend, banreason, verified from users where username like ?", o.args, (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 + " 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": + /*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)); + }); + 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 "mdn": + o.args += " site:developer.mozilla.org"; + googleSearch(client, o); + return true; + + case "hoogle": + o.args += " site:www.haskell.org/hoogle/"; + googleSearch(client, o); + return true; + + //case "google": + case ".google": + googleSearch(client, o); + 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); + } +}; + diff --git a/index.js b/index.js new file mode 100644 index 0000000..ef3a1a6 --- /dev/null +++ b/index.js @@ -0,0 +1,259 @@ +"use strict"; + +const Irc = require("irc"); +const Mysql = require("mysql"); + +let db = Mysql.createPool({ + host: "localhost", + user: "laravel", + password: "mvYx-.c6{m98rwKE", + database: "laravel", + timezone: "utc" +}); + +let irc = {}; + +/*Irc.Client.prototype._connectionHandler = function() { + if (this.opt.webirc.ip && this.opt.webirc.pass && this.opt.webirc.host) { + this.send('WEBIRC', this.opt.webirc.pass, this.opt.userName, this.opt.webirc.host, this.opt.webirc.ip); + } + if (this.opt.password) { + this.send('PASS', this.opt.password); + } + if (this.opt.debug) + console.log('Sending irc NICK/USER'); + this.send('NICK', this.opt.nick); + this.nick = this.opt.nick; + this._updateMaxLineLength(); + this.send('USER', this.opt.userName, 'realnetzprotokolladresse.w0bm.com', 'realnetzprotokolladresse.w0bm.com', this.opt.realName); + this.emit('connect'); +};*/ + +//irc.client = new Irc.Client('irc.rizon.so', 'w0bm', { +//irc.client = new Irc.Client('irc.n0xy.net', 'w0bm', { +irc.client = new Irc.Client('znc.gottz.de', 'w0bm', { + // channels: ["#gz", "#w0bm"], + port: 6667, + secure: false, + retryCount: 12000, + retryDelay: 3000, + userName: "Abdullah", + realName: "Fritz", + debug: false, + selfSigned: false, + debugRaw: false, + autoConnect: false, + password: "w0bm/n0xy:Roquaib7jae9miey3aey" +}); + +const repl = require("repl").start("> "); +repl.context.i = irc; +repl.context.c = irc.client; +repl.context.w = (msg) => irc.client.say("#w0bm", msg); +repl.context.s = (cmd, msg) => irc.client.send(cmd, msg); + +Object.defineProperty(repl.context, "q", {get:process.exit}); + +let needJoin = false; +irc.client.addListener("registered", () => { + console.log("registered…"); + const c = irc.client; + //c.say("NickServ", "IDENTIFY dI0k2k7PH"); + //c.say("NickServ", "IDENTIFY jae2Loax"); + //c.say("HostServ", "ON"); + //needJoin = true; +}); +irc.client.addListener("notice", (from, to, text) => { + if (needJoin && from == "NickServ" && text.indexOf("Password accepted") != -1) { + needJoin = false; + const c = irc.client; + //c.join("#w0bm"); + //c.join("#gz"); + } +}); +process.nextTick(()=>irc.client.connect()); + +const handleChatCommands = require("./chatCommands")(irc, db); + +const shiftRegex = /^(\.?\w+:?)\s+(.+)/; +const w0bmregex = /(?:[^\/]|^|\/\/)w0bm\.com\/(?:(?:b\/)?\w+\/)?([^ '\/@`´]+\.(webm)|\d+)/i; + +const capsmsg = [ + "Captain capslock did not approve this!", + "CAPS", + "caps lock. unleash the mother fucking fury", + "DON'T YOU TYPE AT ME IN THAT TONE OF VOICE.", + "Suddenly, CAPS LOCK", + "OH, so you wanna argue? BRING IT. I got my CAPS LOCK ON", + "WELCOME TO THE INTERNET" +]; + +irc.client.addListener("error", message => console.log("error: ", message)); + +irc.client.on("raw", raw => { + if (irc.client.opt.debugRaw) console.log(raw); + /*if (raw.command == "rpl_whoischannels") { + let chan = raw.args[2].split(" ").filter(c => /#w0bm$/.test(c)); + if (!chan || !chan[0] || chan[0].split("#")) return; + let mode = chan[0].split("#")[0]; + irc.client.chans["#w0bm"].users[raw.args[1]] = mode; + }*/ +}); + +/*irc.client.on("-mode", (chan, nick, mode, user, message) => { + if (typeof user != "undefined") + irc.client.send("WHOIS", user); +}) +irc.client.on("+mode", (chan, nick, mode, user, message) => { + if (typeof user != "undefined") + irc.client.send("WHOIS", user); +})*/ + +irc.client.addListener("message", (from, to, message, raw) => { + const client = irc.client; + // if (client.opt.debug) console.log("raw:", raw); + let pm; + if (pm = !/^#/.test(to)) { + if (client.opt.debug) console.log("setting to from:", to, "to:", from, "cause its a PM"); + to = from; + } + if (client.opt.debug) console.log("from:", from, "to:", to, "message:", message); + if (shiftRegex.test(message)) { + let cmd = message.match(shiftRegex); + let args = cmd[2].trim(); + cmd = cmd[1]; + + if (handleChatCommands({ + from: from, + to: to, + message: message, + cmd: cmd, + args: args + })) { + //console.log("cmd:", cmd, "arg:", arg); + return; + } + } + + /*if (/w0bm\.com\/\d+/.test(message)) { + client.say(to, "durch Aufruf des Links: "+(message.match(/(w0bm\.com\/\d+)/)[0])+" machen Sie sich strafbar!"); + return; + }*/ + + if (/pr0gramm\.com/.test(message) && to == "#w0bm") { + client.say(to, pr0text[Math.random()*pr0text.length|0]); + return; + } + +/* if (message.toUpperCase() == message && message.trim().split("").filter(c=>/[A-Z]/.test(c)).length > 5) { + client.say(to, capsmsg[Math.random()*capsmsg.length|0]); + } +*/ + + if (w0bmregex.test(message)) { + var link = message.match(w0bmregex); + if (link) { + var id = link[1]; + if (id.length > 20) { + client.say(to, "fuck you"); + return; + } + var webm = link[2]; + db.getConnection((err, con) => { + if (err) { + client.say(to, "sorry.. there seems to be a database problem right now D:"); + con.release(); + return; + } + con.query( + "select v.id, v.deleted_at, u.username, c.name as category, v.interpret, v.songtitle, v.imgsource,"+ + " (select 1 from taggable_taggables t where t.taggable_id = v.id and t.tag_id = 1) as sfw,"+ + " (select count(cm.id) from comments cm where cm.video_id = v.id and cm.deleted_at is NULL) as comments"+ + " from videos v, users u, categories c where v.user_id = u.id and v.category_id = c.id"+ + " and " + (webm ? "v.file" : "v.id") + " = '" + id + "'", (err, rows, fields) => { + if (err) { + client.say(to, "sorry.. there seems to be an sql query problem D:"); + client.say(to, "" + err); + con.release(); + return; + } + var vid = rows[0]; + if (!vid) { + 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"); + txt.push(vid["sfw"] ? "\x039SFW\x0f" : "\x034NSFW\x0f"); + ["interpret", "songtitle", "category", "username", "comments"].forEach((v, i) => { + if (vid[v]) { + txt.push( + ["Artist", "Title", "Category", "Uploader", "Comments"][i] + ": " + +"\x02" + vid[v] + "\x0f" + ); + } + }); + + client.say(to, txt.join(" | ")); + con.release(); + }); + }); + + return; + } + } + + if (~haitext.indexOf(message.toLowerCase())) { + client.say(to, haitext[Math.random()*haitext.length|0] + " " + from + "!"); + return; + } + + if (/^!d$/.test(message)) { + client.say(to, from + ": the magic dice shows " + ((Math.random()*6|0)+1) + " eyes."); + } + + if (/^a+[yi][yiou]*$/.test(message)) { + client.say(to, "ayy lmao"); + return; + } + + if (/.+\?\?$/.test(message)) { + let ye = Math.random() * 2 | 0; + client.say(to, "[" + (ye?"x":" ") + "] ja [" + (ye?" ":"x") + "] nein | " + message); + return; + } + + if (~[".guuchan", ".vizon", ".lottery"].indexOf(message)) { + let values = new Array(29).fill().map((v,i)=>1+i); + let choices = new Array(6).fill().map(()=>values.splice(Math.random()*values.length|0,1)).sort((x,y)=>x-y).join(" "); + client.say(to, "/notice guuchan !bet " + choices); + return; + } +}); + +const haitext = ["ohaio", "ohayou", "ohayo", "ohaiou", "ohai", "nabend", "morgen", "guten tag", "hallo", "hi", "hai", "hey", "moin", "hellau", "hello", "hallu", "yo", "servus", "tag", "tach", "alaaf", "alaf", "As-Salamu 'alaikum wa Rahmatullahi wa Barakatuhu"]; + + +const pr0text = [ + "pr0gramm.com existiert nicht!", + "endlich oc von deiner fotze?", + "Pfui Daibel", + "kommandozeile war vorher da", + "keiner von uns", + "Falsches Grau", + "das reicht uns nicht", + "Zapalot nochmal!", + "meinten sie reddit, 9gag oder fagbook?", + "lustig weil pr0gramm", + "lustig weil fett", + "marina die huuure", + "har har har kefer", + "Ach du scheiße. Da drückste Minus.", + "0815 wie fick", + "stumpf ist trumpf", + "f man weiß ja nie", + "lass das nicht die repost polizei sehen!" +]; + diff --git a/package.json b/package.json new file mode 100644 index 0000000..166c24d --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "ircbot", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "gz", + "license": "ISC", + "dependencies": { + "google": "^2.0.0", + "irc": "^0.5.0", + "mysql": "^2.10.2", + "sandbox": "^0.8.6" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..00a3575 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +woop woop