2023-07-18 13:01:09 +00:00
#!/usr/bin/env node
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
2023-07-18 13:01:09 +00:00
const Irc = require ( "matrix-org-irc" ) ;
2016-11-18 10:58:50 +00:00
const Mysql = require ( "mysql" ) ;
2023-07-18 13:01:09 +00:00
require ( 'dotenv' ) . config ( { path : '/srv/http/w0bm/.env' } ) ;
2017-07-31 11:49:52 +00:00
2016-11-18 10:58:50 +00:00
let db = Mysql . createPool ( {
2023-07-20 12:49:05 +00:00
socketPath : '/run/mysqld/mysqld.sock' ,
user : process . env . DB _USERNAME ,
password : process . env . DB _PASSWORD ,
database : process . env . DB _DATABASE ,
timezone : "utc"
2016-11-18 10:58:50 +00:00
} ) ;
let irc = { } ;
2018-03-15 15:05:46 +00:00
irc . client = new Irc . Client ( config . servers . n0xy . host , config . servers . n0xy . nick , {
2023-07-20 12:49:05 +00:00
port : config . servers . n0xy . port ,
secure : config . servers . n0xy . secure ,
userName : config . servers . n0xy . userName ,
realName : config . servers . n0xy . realName ,
sasl : config . servers . n0xy . sasl ,
debug : false ,
debugRaw : false ,
selfSigned : false ,
autoConnect : true ,
password : config . servers . n0xy . srvPassword ,
channels : [ "#w0bm" , "#f0ck" ]
2016-11-18 10:58:50 +00:00
} ) ;
2018-03-15 14:14:13 +00:00
if ( process . env . NODE _ENV != 'production' ) {
2023-07-20 12:49:05 +00:00
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
2023-07-20 12:49:05 +00:00
Object . defineProperty ( repl . context , "q" , { get : process . exit } ) ;
2018-03-15 14:14:13 +00:00
}
2016-11-18 10:58:50 +00:00
const handleChatCommands = require ( "./chatCommands" ) ( irc , db ) ;
2023-07-18 13:01:09 +00:00
const shiftRegex = /^(\.?\w+:?)(?:\s+(.+))?/ ;
2019-04-04 11:30:14 +00:00
const w0bmregex = /(?:\b(\w+)\.)?\bw0bm\.com\/(?:\w+\/){0,3}([^ '\/@`´ ]+\.(webm)|\d+)/i ;
2016-11-18 10:58:50 +00:00
const capsmsg = [
2023-07-20 12:49:05 +00:00
"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"
2016-11-18 10:58:50 +00:00
] ;
irc . client . addListener ( "error" , message => console . log ( "error: " , message ) ) ;
irc . client . addListener ( "message" , ( from , to , message , raw ) => {
2023-07-20 12:49:05 +00:00
const client = irc . client ;
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
} ) ) {
if ( client . opt . debug )
console . log ( "cmd:" , cmd , "arg:" , args ) ;
return ;
}
}
/ * i f ( / p r 0 g r a m m \ . c o m / . t e s t ( m e s s a g e ) & & t o = = " # w 0 b m " ) {
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 [ 2 ] ;
if ( id . length > 20 ) {
client . say ( to , "fuck you" ) ;
return ;
}
var webm = link [ 3 ] ;
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.videotitle, 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" ) ;
[ "videotitle" , "interpret" , "songtitle" , "category" , "username" , "comments" ] . forEach ( ( v , i ) => {
if ( vid [ v ] ) {
txt . push (
[ "Video Title" , "Artist" , "Song Title" , "Category" , "Uploader" , "Comments" ] [ i ] + ": "
+ "\x02" + vid [ v ] + "\x0f"
) ;
}
} ) ;
client . say ( to , txt . join ( " | " ) ) ;
con . release ( ) ;
} ) ;
} ) ;
return ;
}
}
if ( haitext . includes ( 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 ;
}
2016-11-18 10:58:50 +00:00
} ) ;
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 = [
2023-07-20 12:49:05 +00:00
"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!"
2016-11-18 10:58:50 +00:00
] ;