diff --git a/client.js b/client.js index aae12c6..68ea1f5 100644 --- a/client.js +++ b/client.js @@ -5,6 +5,7 @@ const fetch = require("node-fetch"); const formdata = require("form-data"); const he = require("he"); const cheerio = require("cheerio"); +const sharp = require("sharp"); var mmm = require("mmmagic"); var Magic = mmm.Magic; @@ -42,7 +43,7 @@ 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:130.0) Gecko/20100101 Firefox/130.0", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.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", @@ -620,7 +621,7 @@ function init_irc(){ irc_client.addListener("close", function(message){ - console.log("IRC error"); + console.log("IRC disconnect!"); console.log(message); irc_logged_in = false; @@ -629,6 +630,12 @@ function init_irc(){ init_irc(); }); + + irc_client.addListener("error", function(error){ + + console.log("IRC error"); + console.log(error); + }); } init_irc(); @@ -660,13 +667,27 @@ async function fetch_xeno(recording, index, msg){ ); } +async function fetch_image(image_link){ + + var res = await fetch(image_link); + return await res.buffer(); +} + deek.on("login", function(channel){ console.log("Connected to websocket xoxo"); }); +// @TODO remove +var last_image = "https://deek.chat/storage/files/Dek1873481580533551104.png"; + deek.on("message", async function(msg, user){ + if(msg.files.length !== 0){ + + last_image = msg.files[msg.files.length - 1]; + } + if( ( user.id === 13 || // me lol @@ -1458,17 +1479,243 @@ deek.on("message", async function(msg, user){ ); break; + // + // Image manipulation tools + // + case "greyify": + case "grayify": + case "grey": + case "gray": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image), + {animated: true} + ).greyscale() + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "invertify": + case "invert": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image), + {animated: true} + ).flatten( + { + background: "#282828" + } + ).negate() + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "flatify": + case "flatten": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image), + {animated: true} + ).flatten( + { + background: "#282828" + } + ) + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "jpegify": + case "jpgify": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image) + ).jpeg( + { + mozjpeg: true + } + ) + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "pngify": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image) + ).png() + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "rotatify": + case "rotate": + value = parseInt(value); + + if( + isNaN(value) || + value == "" + ){ + + value = 90; + } + + if(value <= 0){ + + value += 360; + } + + if(value >= 1080){ + + send(msg, "Fuck you the image can't spin that much!!"); + break; + } + + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image) + ).rotate(value) + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + + break; + + case "flip": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image), + {animated: true} + ).flip() + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "flop": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image), + {animated: true} + ).flop() + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + + case "deepfry": + try{ + send( + msg, + "", + await sharp( + await fetch_image(last_image) + ) + .resize( + { + width: 350, + fit: "inside" + } + ) + .jpeg({ quality: 5 }) + .sharpen({ sigma: 3 }) + .modulate({ + saturation: 3.0, + brightness: 1.2, + contrast: 1.5, + }) + .toBuffer() + ); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + break; + case "help": case "h": + if(value == "image"){ + + send( + msg, + "== image manipulation help menu ==\n\n" + + ".help image => lol idk\n" + + ".rotatify (deg) => Ro ta te\n" + + ".flip => gucci flip flops\n" + + ".flop => make it kick rocks\n" + + ".deepfry => Make images look better\n" + + ".invertify => Make da colors crayyyzaayy\n" + + ".greyify => Turn image grey and depressing\n" + + ".flatify => Remove dogshit transparency\n" + + ".jpegify => Convert to jay peg\n" + + ".pngify => Convert to pee n j\n" + ); + break; + } + send( msg, "== help menu ==\n\n" + ".help => lol idk\n" + + ".help image => Image manipulation help\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" + - ".fortune/.f => fortune teller cause cynic cant code :trol:\n" + + ".fortune/.f => fortune teller cause cynic cant code\n" + ".yt/.youtube => search the jewish propaganda catalog\n" + ".x/xeno => search for bird sounds\n" + ".roll/.r => Because deekchat was too slow\n" +