fix reddit embeds

This commit is contained in:
lolcat 2024-12-09 23:53:07 -05:00
parent 1369446721
commit c1dc22a57c
1 changed files with 64 additions and 10 deletions

View File

@ -215,6 +215,17 @@ async function send(channel, text, file = null, forcemime = null){
channel = channel.channel;
}
if(channel === -1){
channel = 1;
}else{
if(channel === 1){
irc_client.say("#deekchat", text);
}
}
if(file === null){
ws.send(JSON.stringify({
@ -585,7 +596,7 @@ function init_irc(){
switch(to){
case "#deekchat":
send(1, "<" + from + "> " + message);
send(-1, "<" + from + "> " + message);
deek.emit(
"message",
@ -607,7 +618,7 @@ function init_irc(){
}
});
irc_client.addListener("error", function(message){
irc_client.addListener("close", function(message){
console.log("IRC error");
console.log(message);
@ -616,10 +627,7 @@ function init_irc(){
irc_debounce = false;
//irc_client.disconnect();
setTimeout(function(){
init_irc();
}, 2000);
init_irc();
});
}
@ -673,6 +681,19 @@ deek.on("message", async function(msg, user){
return;
}
if(
user.id === userid &&
irc_bridge_enabled &&
msg.channel === 1 &&
msg.files.length !== 0
){
for(var i=0; i<msg.files.length; i++){
irc_client.say("#deekchat", msg.files[i]);
}
}
if(
user.id === userid ||
user.name == name
@ -771,7 +792,21 @@ deek.on("message", async function(msg, user){
try{
if(tweet = link.match(/https?:\/\/(?:www\.)?(?:twitter|x)\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){
if(reddit = link.match(/^https?:\/\/(?:old\.|www\.|m\.)?reddit\.com(\/r\/[^\/]+.*)/i)){
//
// reddit embed
//
reddit = reddit[1];
var res = await fetch("https://www.reddit.com/oembed?url=" + reddit);
var json = await res.json();
var title = json.title;
var description = "By " + json.author_name;
}else if(tweet = link.match(/^https?:\/\/(?:www\.)?(?:twitter|x)\.com\/[A-Za-z0-9_]+\/status\/([0-9]+)/i)){
//
// twitter embed
@ -794,16 +829,31 @@ deek.on("message", async function(msg, user){
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(/^https?:\/\/(?:www\.|m\.)?youtu(?:(?:\.be\/([A-z0-9_-]{11}))|be\.[a-z]+\/(?:watch.*(?:\?|&)v=|shorts\/|embed\/|e\/)([A-z0-9_-]{11}))/i)){
//
// youtube embed
//
if(typeof watch[1] !== "undefined"){
watch = watch[1];
}else if(typeof watch[2] !== "undefined"){
watch = watch[2];
}
watch = watch[1];
var res = await fetch("https://youtube.com/oembed?url=/watch?v=" + watch);
var json = await res.json();
var title = json.title;
var description = "By " + json.author_name;
}else if(bsky = link.match(/https?:\/\/bsky\.app\/profile\/([^\/]+)\/post\/([^?]+)/)){
}else if(bsky = link.match(/^https?:\/\/bsky\.app\/profile\/([^\/]+)\/post\/([^?]+)/)){
//
// bluesky embed
//
var bsky_profile = bsky[1];
var bsky_post = bsky[2];
@ -854,6 +904,10 @@ deek.on("message", async function(msg, user){
}
}else{
//
// link parser fallback
//
var res = await fetch(
link,
{