2016-11-18 10:58:50 +00:00
"use strict" ;
2018-03-15 15:05:46 +00:00
const config = require ( './.config.json' ) ;
2017-03-17 15:55:31 +00:00
const Raven = require ( 'raven' ) ;
2018-03-15 15:05:46 +00:00
Raven . config ( config . sentry ) . install ( ) ;
2017-03-17 15:55:31 +00:00
2016-11-18 10:58:50 +00:00
const Irc = require ( "irc" ) ;
const Mysql = require ( "mysql" ) ;
2017-07-31 11:49:52 +00:00
require ( 'dotenv' ) . config ( { path : '/var/www/w0bm.com/.env' } ) ;
2016-11-18 10:58:50 +00:00
let db = Mysql . createPool ( {
2017-07-31 11:49:52 +00:00
host : process . env . DB _HOST ,
user : process . env . DB _USERNAME ,
password : process . env . DB _PASSWORD ,
database : process . env . DB _DATABASE ,
2016-11-18 10:58:50 +00:00
timezone : "utc"
} ) ;
let irc = { } ;
/ * I r c . C l i e n t . p r o t o t y p e . _ c o n n e c t i o n H a n d l e r = f u n c t i o n ( ) {
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', {
2018-03-15 15:05:46 +00:00
irc . client = new Irc . Client ( config . servers . n0xy . host , config . servers . n0xy . nick , {
2016-11-18 10:58:50 +00:00
// channels: ["#gz", "#w0bm"],
2018-03-15 15:05:46 +00:00
port : config . servers . n0xy . port ,
secure : config . servers . n0xy . secure ,
2016-11-18 10:58:50 +00:00
retryCount : 12000 ,
retryDelay : 3000 ,
2018-03-15 15:05:46 +00:00
userName : config . servers . n0xy . userName ,
realName : config . servers . n0xy . realName ,
2016-11-18 10:58:50 +00:00
debug : false ,
selfSigned : false ,
debugRaw : false ,
autoConnect : false ,
2018-03-15 15:05:46 +00:00
password : config . servers . n0xy . srvPassword
2016-11-18 10:58:50 +00:00
} ) ;
2018-03-15 14:14:13 +00:00
if ( process . env . NODE _ENV != 'production' ) {
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 ) ;
2016-11-18 10:58:50 +00:00
2018-03-15 14:14:13 +00:00
Object . defineProperty ( repl . context , "q" , { get : process . exit } ) ;
}
2016-11-18 10:58:50 +00:00
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+(.+)/ ;
2017-08-25 13:12:06 +00:00
const w0bmregex = /(?:[^\/]|^|\/\/)w0bm\.com\/(?:\w+\/){0,3}([^ '\/@`´ ]+\.(webm)|\d+)/i ;
2016-11-18 10:58:50 +00:00
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 ) ;
/ * i f ( r a w . c o m m a n d = = " r p l _ w h o i s c h a n n e l s " ) {
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 ;
} * /
} ) ;
/ * i r c . c l i e n t . o n ( " - m o d e " , ( c h a n , n i c k , m o d e , u s e r , m e s s a g e ) = > {
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 ;
}
}
/ * i f ( / w 0 b m \ . c o m \ / \ d + / . t e s t ( m e s s a g e ) ) {
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!"
] ;