From 7a2c977e7dcc73f1eace115a25fd486c819b6a91 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sat, 22 Jul 2023 15:27:10 -0400 Subject: [PATCH] done --- LICENSE | 9 + README.md | 28 +++ client.js | 634 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 671 insertions(+) create mode 100755 LICENSE create mode 100755 README.md create mode 100755 client.js diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..3540bfe --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# DeekChat's Rena Chan bot + +Just some retarded image searching bot for deekchat.ml version TWOOO + +https://deekchat.ml + +## Features +1. Made in javascript. Wait, that's not a feature. +2. Has FIVE incredible commands + - `.img ` (aliases: `.i`, `.im`) + - `.page ` (aliases: `.p`) + - `.prop` Check if the sun has exploded + - `.mumble <[optional]ip:port>` Ping mum + - `.mail ` Mail offline people who will never come back + - `.help` If you need help using your dilator + - and `.ping`... for spamming purposes. + +3. Command ratelimiting cause we can't have nice things +4. Simple link embed thingy +5. Less buggy than deekchat, lolcatware stay winning + +## Setup +```sh +sudo apt install nodejs npm +npm install node-fetch@v2 duckduckgo-images-api websocket form-data cheerio + +node client.js # enjoy!! +``` diff --git a/client.js b/client.js new file mode 100755 index 0000000..248ca2a --- /dev/null +++ b/client.js @@ -0,0 +1,634 @@ +const ws = require("websocket").client; +const ddg = require("duckduckgo-images-api"); +const fetch = require("node-fetch"); + +const cheerio = require("cheerio"); + +const formdata = require("form-data"); + +const name = "rena_chan"; +const password = "renachanlovesyou"; + +const client = new ws(); +// get token +async function login(){ + console.log("logging in...") + + // login and get token + const form = new formdata(); + + form.append("name", name); + form.append("password", password); + form.append("submit", "log+in"); + + var login = await fetch( + "https://deekchat.ml/login/submit", + { + method: "POST", + redirect: 'manual', + body: form, + headers: { + 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0", + Origin: "https://deekchat.ml", + DNT: 1 + } + } + ) + + cookie = await login.headers.get("set-cookie"); + + cookie = cookie.match(/(?:api_token|session_id)=[^;]+/g); + cookie = cookie[0] + "; " + cookie[1]; + + return { + 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0", + Origin: "https://deekchat.ml", + DNT: 1, + Cookie: cookie + }; +} + +function report_error(e){ + + console.log("error: " + e.toString()); +} + +client.on("connectFailed", function(e){ + + report_error(e); +}); + +client.on("connect", function(conn){ + + // functions + function send(msg){ + + conn.sendUTF(JSON.stringify({ + type: "message", + data: { + message: msg + } + })); + } + + async function send_img(msg, data){ + var form_data = new formdata(); + + form_data.append("files[]", data, { + + contentType: 'image/png', + name: 'file', + filename: 'file.png' + }); + + fetch("https://deekchat.ml/message/send", { + method: 'POST', + body: form_data, + headers: { + 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0", + Origin: "https://deekchat.ml", + DNT: 1, + "Content-Type": form_data.getHeaders()["content-type"], + Cookie: cookie + } + }) + + .then(async res_post => { + var response = await res_post.json(); + response.message.text = msg; + + conn.sendUTF(JSON.stringify({ + type: "files", + data: { + message: response.message, + } + })); + }); + } + + 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); + + /* + Mail + */ + if(msg.type == "enter"){ + + var username = msg.name; + + if(typeof mail[username] != "undefined"){ + + var msg = ">Whats up " + username + "!! You have unread mail:\n"; + + for(i=0; i]+/)){ + + 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 + ) + ){ + + 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(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(tag_name_description.length !== 0){ description = tag_name_description.attr("content"); } + if(tag_name_og_description.length !== 0){ description = tag_name_og_description.attr("content"); } + if(tag_property_description.length !== 0){ description = tag_property_description.attr("content"); } + if(tag_property_og_description.length !== 0){ description = tag_property_og_description.attr("content"); } + + var text = ""; + + description = description.split("\n"); + + for(i=0; i { + + 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 "mail": + + if(value == ""){ + + send("You need to specify a recipient you face fucked horse!!"); + return; + } + + value = value.split(" "); + var recipient = value[0]; + var message = ""; + + for(i=1; i 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; + } + + } + }); +}); + +async function connect(){ + headers = await login(); + + client.connect("wss://deekchat.ml/ws", "", "", + headers, + null + ); +} + +connect();