twitter embed fix

This commit is contained in:
lolcat 2024-10-27 14:40:41 -04:00
parent bd015609cc
commit 4d3c11eb21
1 changed files with 46 additions and 9 deletions

View File

@ -14,7 +14,7 @@ const emitter = require("events");
const deek = new emitter(); const deek = new emitter();
const name = "rena_chan"; const name = "rena_chan";
const password = "still no"; const password = "yourmom";
const userid = 12; const userid = 12;
var channels = []; var channels = [];
var ws = []; var ws = [];
@ -49,7 +49,8 @@ var fortunes = [
"Your fortune: You may rely on it.", "Your fortune: You may rely on it.",
"Your fortune: Concentrate and ask again.", "Your fortune: Concentrate and ask again.",
"Your fortune: The future is uncertain.", "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 = { var headers = {
@ -143,7 +144,7 @@ async function serveddg(msg, results, page){
signal: AbortSignal.timeout(3000) signal: AbortSignal.timeout(3000)
} }
); );
var res_get = await res.buffer(); var res_get = await res.buffer();
var m = await getmime(res_get); 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'>]+/)){ if(link = msg.text.match(/https?:\/\/[^ \n\r'>]+/)){
link = link[0]; link = link[0];
var download = null;
var mimetype = null;
try{ 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]; 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 json = await res.json();
var title = json.user.name + " (@" + json.user.screen_name + ") " + " on twatter"; 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)){ }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]; 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){ }catch(err){
send(msg, "Stupid retarded website alert!!!! I got an error accessing this shit...\n>" + 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( text.push(
">Duration: " + (new Date(res_get.video[i].duration * 1000).toISOString().slice(11, 19)) + ">Duration: " + (new Date(res_get.video[i].duration * 1000).toISOString().slice(11, 19)) +
" • Views: " + (new Intl.NumberFormat().format(res_get.video[i].views)) + " Views: " + (new Intl.NumberFormat().format(res_get.video[i].views)) +
" • Author: " + res_get.video[i].author.name + " Author: " + res_get.video[i].author.name +
"\n" + res_get.video[i].title + "\n" + res_get.video[i].title +
"\nⶠ" + res_get.video[i].url "\nⶠ" + res_get.video[i].url
); );