diff --git a/client.js b/client.js index 248ca2a..f206e98 100755 --- a/client.js +++ b/client.js @@ -1,634 +1,978 @@ -const ws = require("websocket").client; -const ddg = require("duckduckgo-images-api"); +const fs = require("fs"); +const websocket = require("ws"); const fetch = require("node-fetch"); - -const cheerio = require("cheerio"); - const formdata = require("form-data"); +const he = require("he"); +const cheerio = require("cheerio"); +const ddg = require("duckduckgo-images-api"); +const yt = require("ytsr"); +var mmm = require("mmmagic"); +var Magic = mmm.Magic; + +const emitter = require("events"); +const deek = new emitter(); const name = "rena_chan"; const password = "renachanlovesyou"; +const userid = 12; +var channels = []; +var ws = []; +var ddg_cache = []; +var ddg_mod = true; // dont show porn in .img +var global_page = 1; // .img page +var raid = false; // raid? +var img_headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/110.0", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Accept-Encoding": "gzip, deflate", + "DNT": "1", + "Connection": "keep-alive" +}; -const client = new ws(); -// get token -async function login(){ - console.log("logging in...") +var headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0", + Origin: "https://deek.chat" +}; - // login and get token +/* + Helper functions +*/ +async function getmime(file){ + + return new Promise(function(resolve, reject){ + + var magic = new Magic(mmm.MAGIC_MIME_TYPE); + magic.detect(file, function(err, result){ + + if(err){ + + resolve([ + "image/png", + "png", + false + ]); + }else{ + + resolve([ + result, + result.split("/")[1], + true + ]); + } + }); + }); +} + +function removehtml(html){ + + return he.decode(html.replace(/<[^>]+>/ig,"")); +}; + +async function serveddg(msg, results, page){ + + page--; + + try{ + + var res = await fetch( + results[page].image, + {headers: img_headers} + ); + + var res_get = await res.buffer(); + var m = await getmime(res_get); + + if( + m[2] === false || + m[0].split("/")[0] != "image" + ){ + + var res = await fetch( + results[page].thumbnail, + {headers: img_headers} + ); + + var res_get = await res.buffer(); + } + + }catch(err){ + + var res = await fetch( + results[page].thumbnail, + {headers: img_headers} + ); + + var res_get = await res.buffer(); + } + + send( + msg, + "Page " + (page + 1) + "/" + (results.length) + "\n[" + results[page].width + "x" + results[page].height + "] " + results[page].title + "\n" + results[page].url, + res_get + ); +} + +/* + Websocket functions +*/ +async function send(channel, text, file = null){ + + if(typeof channel == "object"){ + + channel = channel.channel; + } + + for(var i=0; i { - var response = await res_post.json(); - response.message.text = msg; - - conn.sendUTF(JSON.stringify({ - type: "files", - data: { - message: response.message, - } - })); + channels.push({ + name: res[i].room.name, + id: res[i].room.id, + users: [] }); } - console.log("Connected"); - var link = ""; - var ratelimitbuffer = []; - var mail = []; - - conn.on("error", function(e){ report_error(e); }); - conn.on("close", function(e){ console.log("Disconnected!"); connect(); }); - - var results_cache = []; - - conn.on("message", function(msg){ - // {"data":{"message":{"id":160316,"text":"Shit link don't click, I got this error accessing this shit!!!\nFetchError: request to http://www.youtub.../ failed, reason: getaddrinfo ENOTFOUND www.youtub... www.youtub...:80","files":null,"mentions":[],"userId":3572,"name":"rena_chan"}},"type":"message","userId":3572} - - if(msg.type != "utf8"){ return; } - msg = JSON.parse(msg.utf8Data); + for(var i=0; i]+/)){ + switch(m.type){ - link = link[0]; - - getlink().catch(async err => { - - send("Stupid retarded website alert!!!! I got an error accessing this shit...\n>" + err); - }); - - async function getlink(){ - - // test file: - // https://deekchat.ml/storage/files/DEK1523047738939314176.mp4 - - var res = await fetch(link); - - var headers_arr = [...res.headers]; - var headers = []; - - for(i=0; i 10485760 // 10MB - ) - ){ + for(var k=0; k { - - results_cache = results; - - if(results.length === 0){ - - send("No results found for " + value + "!!"); - return; - } - - var res = await fetch( - results[0].image - ); - - var res_get = await res.buffer(); - - send_img( - "Page 0/" + (results.length - 1) + "\n[" + results[0].width + "x" + results[0].height + "] " + results[0].title + "\n" + results[0].url, - res_get - ); - - }).catch(async err => { - - var res2 = await fetch( - results_cache[0].thumbnail - ); - - var res2_get = await res2.buffer(); - - send_img( - err + ". Downloading thumbnail instead!!" + - "\n\nPage 0/" + (results_cache.length - 1) + "\n[" + results_cache[0].width + "x" + results_cache[0].height + "] " + results_cache[0].title + "\n" + results_cache[0].url, - res2_get - ); - return; - }); - - break; - - case "page": - value = parseInt(value); - if( - isNaN(value) || - value == "" - ){ - - send("You didn't enter a valid number you dumbass!!"); - return; - } - - if(results_cache.length === 0){ - - send("Search buffer doesn't contain any links!!"); - return; - } - - if( - value >= results_cache.length || - value <= -1 - ){ - - send("Page offset must be between 0 and " + (results_cache.length - 1) + " you dumbass!!"); - return; - } - - // download image - async function stupid(){ - - var res = await fetch( - results_cache[value].image - ); - - var res_get = await res.buffer(); - - send_img( - "Page " + value + "/" + (results_cache.length - 1) + "\n[" + results_cache[value].width + "x" + results_cache[value].height + "] " + results_cache[value].title + "\n" + results_cache[value].url, - res_get - ); - } - - - stupid() - .catch(async err => { - - var res2 = await fetch( - results_cache[value].thumbnail - ); - - var res2_get = await res2.buffer(); - - send_img( - err + ". Downloading thumbnail instead!!" + - "\n\nPage " + value + "/" + (results_cache.length - 1) + "\n[" + results_cache[value].width + "x" + results_cache[value].height + "] " + results_cache[value].title + "\n" + results_cache[value].url, - res2_get - ); - return; - }); - return; - - case "prop": - - async function stupid_the_sequel(){ - var res = await fetch("https://www.hamqsl.com/solarn0nbh.php"); - var res_get = await res.buffer(); - - send_img("Good news: the sun has not yet exploded", res_get); - } - - stupid_the_sequel() - .catch(async err => { - - send("Could not fetch image!!! FUCK!!!!111\n" + err); - }); + ); break; - case "mumble": - - var port = 64738; - - if(value == ""){ - - var ip = "lolcat.ca"; - }else{ - - var value = value.split(":"); - - if(value.length >= 2){ - - var port = value[1]; - } - - var ip = value[0]; - } - - async function mumble(){ - var res = await fetch("https://lolcat.ca/api/mumble/?ip=" + ip + "&port=" + port); - var res_get = await res.json(); - - if(res_get.status != "ok"){ - - send("An error occured... " + res_get.status); - return; - } - - res_get = res_get.server; - - send( - "Server information for " + ip.toLowerCase() + ":" + port + ":\n\n" + - "Ping => " + res_get.ping + "\n" + - "Users => " + res_get.online + "/" + res_get.max + "\n" + - "Bandwidth => " + res_get.bandwidth + "\n" + - "Country => " + res_get.country.name + " (" + res_get.country.code + ")\n" + - "Version => " + res_get.version - ); - - } - mumble().catch(async err =>{ - - send("lolcat.ca/api/mumble/ is online, trust me. I just don't feel like giving you the status right now. (It's offline)"); - }); - break; + case "files": - case "mail": + m.message.files = m.message.files === null ? [] : m.message.files; + var files = []; - if(value == ""){ + for(var k=0; k lol idk\n" + - ".img/.im/.i => search duckduckgo for birds\n" + - ".page/.p => get page offset for image search\n" + - ".mumble <[optional]ip:port> => check if lolcat died\n" + - ".prop => check if the sun has exploded or smth\n" + - ".mail => Use our worldwide AI enabled mailing system\n" + - ".ping => spam deekchat" ); break; + + default: + //console.warn(m); + break; } - - } - }); -}); - -async function connect(){ - headers = await login(); - - client.connect("wss://deekchat.ml/ws", "", "", - headers, - null - ); + }); + } } -connect(); + +/* + User defined FUN-ctions!!! +*/ +deek.on("login", function(channel){ + + console.log("connected to channel " + channel.name + " (id:" + channel.id + ")"); +}); + +deek.on("message", async function(msg, user){ + + if( + ( + user.id === 13 || + raid === false + ) === false + ){ + + return; + } + + if( + user.id === userid || + user.name == name + ){ + return; + } + + switch(msg.text.toLowerCase()){ + + case "hello rena": + case "hi rena": + case "what's up rena": + case "whats up rena": + send(msg, "hi " + user.name); + return; + + case "/help": + send(msg, "lmao newfag"); + break; + } + + /* + shitty embed support + */ + if(link = msg.text.match(/https?:\/\/[^ \n\r'>]+/)){ + + link = link[0]; + + try{ + + if(tweet = link.match(/https?:\/\/(?:www\.)?twitter\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/)){ + + tweet = tweet[1]; + var res = await fetch("https://cdn.syndication.twimg.com/tweet-result?id=" + tweet); + var json = await res.json(); + + var title = json.user.name + " (@" + json.user.screen_name + ") " + " on twatter"; + var description = json.text; + + }else{ + + var res = await fetch( + link, + {headers: img_headers} + ); + + var headers_arr = [...res.headers]; + var headers = []; + + for(i=0; i 10485760 // 10MB + ) + ){ + + var text = "This thingy^ "; + + if(headers["content-type"]){ + + var format = headers["content-type"].split("/"); + format = format[format.length - 1].split(";")[0]; + + text += "is a " + format + " file "; + }else{ + + text += "is uhh... something.. err.. " + } + + if(headers["content-length"]){ + var filesize = Math.round(parseInt(headers["content-length"]) / 1048576); + + text += "that weighs " + (Math.round(parseInt(headers["content-length"]) / 1048576)) + "MB!!"; + }else{ + + text += "that uhh weighs something probably idk!!!"; + } + + text += " lol thats all i know fuck you"; + + send(msg, text); + return; + } + + // cancerous code ahead + + var buffer = await res.buffer(); + + const parser = cheerio.load(buffer); + + // get title + var title = "Unknown title lol, shit website"; + var tag_title = parser("title"); + var tag_name_og_title = parser("meta[name='og:title']"); + var tag_property_og_title = parser("meta[property='og:title']"); + + if(tag_title.length !== 0){ title = tag_title.text(); } + if(tag_name_og_title.length !== 0){ title = tag_name_og_title.attr("content"); } + if(tag_property_og_title.length !== 0){ title = tag_property_og_title.attr("content"); } + + + // get description + var description = "Unknown description lol, stupid website do not click"; + var tag_name_description = parser("meta[name='description']"); + var tag_name_og_description = parser("meta[name='og:description']"); + var tag_property_description = parser("meta[property='description']"); + var tag_property_og_description = parser("meta[property='og:description']"); + + if(typeof tag_name_description.attr("content") != "undefined"){description = tag_name_description.attr("content"); } + if(typeof tag_name_og_description.attr("content") != "undefined"){description = tag_name_og_description.attr("content"); } + if(typeof tag_property_description.attr("content") != "undefined"){description = tag_property_description.attr("content"); } + if(typeof tag_property_og_description.attr("content") != "undefined"){description = tag_property_og_description.attr("content"); } + + if(typeof tag_name_description.attr("value") != "undefined"){description = tag_name_description.attr("value"); } + if(typeof tag_name_og_description.attr("value") != "undefined"){description = tag_name_og_description.attr("value"); } + if(typeof tag_property_description.attr("value") != "undefined"){description = tag_property_description.attr("value"); } + if(typeof tag_property_og_description.attr("value") != "undefined"){description = tag_property_og_description.attr("value"); } + + } + + var text = ""; + + description = description.split("\n"); + + for(var i=0; i" + err); + } + + return; + } + + + /* + Commands + */ + var regex = msg.text.match(/^\.([^ ]+)(?: (.*))?/); + + if( + regex === null || + typeof regex[1] == "undefined" + ){ + return; + } + + var cmd = regex[1]; + + if(typeof regex[2] != "undefined"){ + var value = regex[2]; + }else{ + + var value = ""; + } + + switch(cmd){ + + case "raid": + if(user.id !== 13){ + + break; + } + + if(raid === false){ + + raid = true; + send(msg, "Ignoring all messages from now on, fuck you lol!!"); + }else{ + + raid = false; + send(msg, "Now listening to messages!!!"); + } + break; + + case "rc": + case "reconnect": + if(user.id !== 13){ + + break; + } + + send(msg, "brb"); + + setTimeout(function(){ + + fs.utimesSync(__filename, Date.now(), Date.now()); + }, 1000); + break; + + case "ping": + send(msg, "Pong!!!!"); + break; + + case "dice": + case "roll": + case "d": + case "r": + value = parseInt(value); + if(isNaN(value)){ + + value = 6; + } + + if(value <= 1){ + + send( + msg, + "Rolling a " + value + " faced dice...\nWait what?? " + + "You fucking shit, a black hole just appeared!!!!!! Oh my fucking shit!!!!!" + ); + return; + } + + send( + msg, + "Rolling a " + value + " faced dice...\nAnd you got " + + ( + Math.floor(Math.random() * value + 1) + ) + "!!!" + ); + break; + + case "mumble": + case "m": + var port = 64738; + + if(value == ""){ + + var ip = "lolcat.ca"; + }else{ + + var value = value.split(":"); + + if(value.length >= 2){ + + var port = value[1]; + } + + var ip = value[0]; + } + + try{ + var res = await fetch("https://lolcat.ca/api/mumble/?ip=" + ip + "&port=" + port); + var res_get = await res.json(); + + if(res_get.status != "ok"){ + + send(msg, "An error occured... " + res_get.status); + return; + } + + res_get = res_get.server; + + var servername = res_get.name === null ? res_get.domains[0] : res_get.name; + var website = res_get.website === null ? "No website available" : res_get.website; + + send( + msg, + ">Server information for " + servername + ":\n" + + "Known domains => " + res_get.domains.join(", ") + "\n" + + "Ping => " + res_get.ping + "\n" + + "Users => " + res_get.online + "/" + res_get.max + "\n" + + "Bandwidth => " + res_get.bandwidth + "\n" + + "Country => " + res_get.country.name + " (" + res_get.country.code + ")\n" + + "Version => " + res_get.version + "\n" + + "Website => " + website + ); + + }catch(err){ + + send(msg, "lolcat.ca api sucks and is offline and dead"); + } + break; + + case "prop": + try{ + var res = await fetch("https://www.hamqsl.com/solarn0nbh.php"); + var res_get = await res.buffer(); + + send(msg, "Good news: the sun has not yet exploded", res_get); + }catch(err){ + + send(msg, "Could not fetch image!!! FUCK!!!!111\n" + err); + } + break; + + case "img": + case "im": + case "i": + + if(value.trim() == ""){ + + send(msg, "You need to search for something cum licker!!!"); + return; + } + + global_page = 1; + + ddg.image_search( + { + query: value, + moderate: ddg_mod + } + ).then(async results => { + + ddg_cache = results; + + if(results.length === 0){ + + send(msg, "No results found for " + value + "!!"); + return; + } + + await serveddg(msg, results, 1); + }); + break; + + case "boobs": + case "boob": + case "nsfw": + switch(value.toLowerCase()){ + + case "yes": + case "y": + case "1": + case "yea": + case "true": + case "yup": + send(msg, "I will now show boobs when using .img"); + ddg_mod = false; + break; + + case "no": + case "n": + case "nae": + case "false": + case "no": + case "off": + case "nope": + case "nah": + case "0": + send(msg, "I will now prevent eagle from jacking off in main chat"); + ddg_mod = true; + break; + + default: + + var active = ddg_mod ? "NOT " : ""; + send(msg, "I will " + active + "show boobs. Use .boobs to toggle"); + break; + } + break; + + case "page": + case "p": + + value = parseInt(value); + if( + isNaN(value) || + value == "" + ){ + + send(msg, "You didn't enter a valid number you dumbass!!"); + return; + } + + if(ddg_cache.length === 0){ + + send(msg, "Search buffer doesn't contain any links you horse fucker!!"); + return; + } + + if( + value > ddg_cache.length || + value <= 0 + ){ + + send(msg, "Page offset must be between 1 and " + ddg_cache.length + " you dumbass!!"); + return; + } + + global_page = value; + await serveddg(msg, ddg_cache, value); + break; + + case "pp": + global_page++; + + if(global_page > ddg_cache.length){ + + send(msg, "You reached the end of results stupid kike sucker!!"); + return; + } + + await serveddg(msg, ddg_cache, global_page); + break; + + case "youtube": + case "jewtube": + case "yt": + + if(value.trim() == ""){ + + send(msg, "You need to search for something cum licker!!!"); + return; + } + + var ytsearch = await yt(value); + + if(ytsearch.items.length === 0){ + + send(msg, "No results found for " + value + "!!"); + return; + } + + var text = ""; + + var k = 0; + for(var i=0; i lol idk\n" + + ".img/.im/.i => search duckduckgo for birds\n" + + ".boobs => Boobs?\n" + + ".page/.p => get page offset for image search\n" + + ".pp => get next page\n" + + ".yt/.youtube => search the jewish propaganda catalog\n" + + ".roll/.r => Because deekchat was too slow\n" + + ".mumble/.m <[optional]ip:port> => check if lolcat died\n" + + ".prop => check if the sun has exploded or smth\n" + + ".ping => spam deekchat" + ); + break; + } +}); + +deek.on("close", function(channel){ + + console.log("It's over. Disconnected from channel " + channel.name + ". Attempting reconnection in 10 seconds"); + + setTimeout(function(){ + + fs.utimesSync(__filename, Date.now(), Date.now()); + }, 10000); +}); + +deek.on("error", function(message){ + + console.error("Serber error: " + message + ". Attempting reconnection in 10 seconds"); + + setTimeout(function(){ + + fs.utimesSync(__filename, Date.now(), Date.now()); + }, 10000); +}); + +// connect to serber +handshake(name, password);