From 4d3c11eb211cf355eedb89d9cb64abbb7546b5e7 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sun, 27 Oct 2024 14:40:41 -0400 Subject: [PATCH] twitter embed fix --- client.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/client.js b/client.js index 3fb3fe1..53ee8e6 100755 --- a/client.js +++ b/client.js @@ -14,7 +14,7 @@ const emitter = require("events"); const deek = new emitter(); const name = "rena_chan"; -const password = "still no"; +const password = "yourmom"; const userid = 12; var channels = []; var ws = []; @@ -49,7 +49,8 @@ var fortunes = [ "Your fortune: You may rely on it.", "Your fortune: Concentrate and ask again.", "Your fortune: The future is uncertain.", - "Your fortune: :fuck-off: fuck you" + "Your fortune: :fuck-off: fuck you", + "Your fortune: it's over" ]; var headers = { @@ -143,7 +144,7 @@ async function serveddg(msg, results, page){ signal: AbortSignal.timeout(3000) } ); - + var res_get = await res.buffer(); var m = await getmime(res_get); @@ -488,17 +489,33 @@ deek.on("message", async function(msg, user){ if(link = msg.text.match(/https?:\/\/[^ \n\r'>]+/)){ link = link[0]; + var download = null; + var mimetype = null; try{ - if(tweet = link.match(/https?:\/\/(?:www\.)?(twitter|x)\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){ + if(tweet = link.match(/https?:\/\/(?:www\.)?(?:twitter|x)\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){ + + // + // twitter embed + // tweet = tweet[1]; - var res = await fetch("https://cdn.syndication.twimg.com/tweet-result?id=" + tweet + "&token=2rkokdcv41v"); + var res = await fetch("https://cdn.syndication.twimg.com/tweet-result?id=" + tweet + "&token=5"); var json = await res.json(); var title = json.user.name + " (@" + json.user.screen_name + ") " + " on twatter"; - var description = json.text; + var description = "❤️ " + json.favorite_count + " • 💬 " + json.conversation_count + " • 📅 " + json.created_at + "\n" + json.text + " ‎ "; + + if(typeof json.video == "object"){ + + download = json.video.variants[json.video.variants.length - 1].src; + mimetype = ["video/mp4", "mp4", true]; + }else if(typeof json.photos[0].url == "string"){ + + download = json.photos[0].url; + mimetype = ["image/jpeg", "jpeg", true]; + } }else if(watch = link.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i)){ @@ -609,7 +626,27 @@ deek.on("message", async function(msg, user){ text += "\n>" + description[i]; } - send(msg, title + text); + if(download !== null){ + + try{ + + var image = await fetch( + download, + { + headers: img_headers, + signal: AbortSignal.timeout(3000) + } + ); + + var download = await image.buffer(); + + }catch(err){ + + download = null; + } + } + + send(msg, title + text, download, mimetype); }catch(err){ send(msg, "Stupid retarded website alert!!!! I got an error accessing this shit...\n>" + err); @@ -949,8 +986,8 @@ deek.on("message", async function(msg, user){ text.push( ">Duration: " + (new Date(res_get.video[i].duration * 1000).toISOString().slice(11, 19)) + - " • Views: " + (new Intl.NumberFormat().format(res_get.video[i].views)) + - " • Author: " + res_get.video[i].author.name + + " • Views: " + (new Intl.NumberFormat().format(res_get.video[i].views)) + + " • Author: " + res_get.video[i].author.name + "\n" + res_get.video[i].title + "\nâ–¶ " + res_get.video[i].url );