Compare commits
2 Commits
9bead82ecf
...
5da60912be
Author | SHA1 | Date | |
---|---|---|---|
5da60912be | |||
a8552b8e20 |
69
index.mjs
69
index.mjs
@ -1,5 +1,9 @@
|
||||
import "dotenv/config";
|
||||
import {Bot, RichText} from "@skyware/bot";
|
||||
import {Bot, RichText, Post} from "@skyware/bot";
|
||||
import {DidResolver} from "@atproto/identity";
|
||||
|
||||
var didres = new DidResolver({});
|
||||
var getServiceEndpoint = async did => (await didres.resolve(did)).service.find(s => s.id == "#atproto_pds")?.serviceEndpoint;
|
||||
|
||||
var bot = new Bot();
|
||||
await bot.login({
|
||||
@ -8,43 +12,54 @@ await bot.login({
|
||||
});
|
||||
bot.on("error", console.error);
|
||||
|
||||
bot.on("mention", async mention => {
|
||||
//console.log({mention});
|
||||
var parent = mention.replyRef?.parent;
|
||||
if (!parent) return;
|
||||
//console.log({parent});
|
||||
bot.on("mention", async post => {
|
||||
try {
|
||||
var parentPost = await bot.getPost(parent.uri);
|
||||
//console.log({parentPost});
|
||||
// video in mentioning post or quoted post
|
||||
var vid = await findVideoInPost(post);
|
||||
|
||||
var embed = parentPost.embed;
|
||||
if (!embed || !embed.isVideo()) {
|
||||
//await mention.reply({text: "Sorry, it doesn't seem that this post has a video."})
|
||||
return;
|
||||
// ignore original posts without video
|
||||
if (!vid && !post.replyRef) return;
|
||||
|
||||
// video in replied post or quoted in replied post
|
||||
if (!vid) {
|
||||
var parentPost = await bot.getPost(post.replyRef.parent.uri);
|
||||
vid = await findVideoInPost(parentPost);
|
||||
}
|
||||
|
||||
var did = parentPost.author.did;
|
||||
var cid = embed.cid;
|
||||
var url = `${await getServiceEndpoint(did)}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}`;
|
||||
url = `https://avps.owo69.me/download.html?filename=${cid}.mp4&url=${encodeURIComponent(url)}`;
|
||||
// video in original post or quoted in original post
|
||||
if (!vid) {
|
||||
var rootPost = await bot.getPost(post.replyRef.root.uri);
|
||||
vid = await findVideoInPost(rootPost);
|
||||
}
|
||||
|
||||
if (!vid) {
|
||||
await post.reply({text: "Could not find Bluesky video in replied post, quoted post, or parent post"});
|
||||
return;
|
||||
}
|
||||
|
||||
var url = `${await getServiceEndpoint(vid.did)}/xrpc/com.atproto.sync.getBlob?did=${vid.did}&cid=${vid.cid}`;
|
||||
url = `https://avps.owo69.me/download.html?filename=${vid.cid}.mp4&url=${encodeURIComponent(url)}`;
|
||||
|
||||
var text = new RichText().addLink("Click or touch here to download this video", url);
|
||||
await mention.reply({text});
|
||||
await post.reply({text});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await mention.reply({text: "error"});
|
||||
await post.reply({text: String(error.message?.substring(0,300))});
|
||||
}
|
||||
});
|
||||
|
||||
async function findVideoInPost(post) {
|
||||
if (!post.embed) return;
|
||||
|
||||
if (post.embed.isVideo())
|
||||
return {did: post.author.did, cid: post.embed.cid};
|
||||
|
||||
async function getServiceEndpoint(did) {
|
||||
//try {
|
||||
var doc = await fetch(`https://plc.directory/${did}`).then(res => res.json());
|
||||
var {serviceEndpoint} = doc.service.find(s => s.id == "#atproto_pds");
|
||||
return serviceEndpoint;
|
||||
//} catch (error) {
|
||||
// console.error(error);
|
||||
// return `https://bsky.network`;
|
||||
//}
|
||||
if (post.embed.isRecordWithMedia() && post.embed.media.isVideo())
|
||||
return {did: post.author.did, cid: post.embed.media.cid};
|
||||
|
||||
if (post.embed.isRecord() && post.embed.record instanceof Post) {
|
||||
// post.embed.record.embed is undefined
|
||||
let quotedPost = await bot.getPost(post.embed.record.uri);
|
||||
return await findVideoInPost(quotedPost);
|
||||
}
|
||||
}
|
||||
|
96
package-lock.json
generated
96
package-lock.json
generated
@ -5,7 +5,8 @@
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"@skyware/bot": "^0.3.7",
|
||||
"@atproto/identity": "^0.4.7",
|
||||
"@skyware/bot": "^0.3.11",
|
||||
"dotenv": "^16.4.5"
|
||||
}
|
||||
},
|
||||
@ -83,10 +84,71 @@
|
||||
"integrity": "sha512-NEBOGkdaDY8cjlDg49kefIsRM7iv/4oReEnOr3bN4tF3IxBGdc6Io1NCJz1xNBNdUL+3VDG3CKHiRji91HXaTg==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/@atproto/common-web": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@atproto/common-web/-/common-web-0.4.1.tgz",
|
||||
"integrity": "sha512-Ghh+djHYMAUCktLKwr2IuGgtjcwSWGudp+K7+N7KBA9pDDloOXUEY8Agjc5SHSo9B1QIEFkegClU5n+apn2e0w==",
|
||||
"dependencies": {
|
||||
"graphemer": "^1.4.0",
|
||||
"multiformats": "^9.9.0",
|
||||
"uint8arrays": "3.0.0",
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@atproto/crypto": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/@atproto/crypto/-/crypto-0.4.4.tgz",
|
||||
"integrity": "sha512-Yq9+crJ7WQl7sxStVpHgie5Z51R05etaK9DLWYG/7bR5T4bhdcIgF6IfklLShtZwLYdVVj+K15s0BqW9a8PSDA==",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.7.0",
|
||||
"@noble/hashes": "^1.6.1",
|
||||
"uint8arrays": "3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@atproto/identity": {
|
||||
"version": "0.4.7",
|
||||
"resolved": "https://registry.npmjs.org/@atproto/identity/-/identity-0.4.7.tgz",
|
||||
"integrity": "sha512-A61OT9yc74dEFi1elODt/tzQNSwV3ZGZCY5cRl6NYO9t/0AVdaD+fyt81yh3mRxyI8HeVOecvXl3cPX5knz9rQ==",
|
||||
"dependencies": {
|
||||
"@atproto/common-web": "^0.4.1",
|
||||
"@atproto/crypto": "^0.4.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/curves": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.8.1.tgz",
|
||||
"integrity": "sha512-warwspo+UYUPep0Q+vtdVB4Ugn8GGQj8iyB3gnRWsztmUHTI3S1nhdiWNsPUGL0vud7JlRRk1XEu7Lq1KGTnMQ==",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "1.7.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.21.3 || >=16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@noble/hashes": {
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.7.1.tgz",
|
||||
"integrity": "sha512-B8XBPsn4vT/KJAGqDzbwztd+6Yte3P4V7iafm24bxgDe/mlRuK6xmWPuCNrKt2vDafZ8MfJLlchDG/vYafQEjQ==",
|
||||
"engines": {
|
||||
"node": "^14.21.3 || >=16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/@skyware/bot": {
|
||||
"version": "0.3.7",
|
||||
"resolved": "https://registry.npmjs.org/@skyware/bot/-/bot-0.3.7.tgz",
|
||||
"integrity": "sha512-27k7r4/YA+h8FobXokMa3iv8fm/850a7NmajOHP3/CaMbCYicXXBDnAIY4kIPP58Zl/A/JvdcFLpQBpfFkiQHQ==",
|
||||
"version": "0.3.11",
|
||||
"resolved": "https://registry.npmjs.org/@skyware/bot/-/bot-0.3.11.tgz",
|
||||
"integrity": "sha512-fG4uvD/3+ynlQPRHv6pz4kk+5fbDNJYTORbLXwmlwWAzJ7FSBkahG1NeK2M+hqIYBVqdzAI5QqcM17fwJXeZeQ==",
|
||||
"dependencies": {
|
||||
"@atcute/bluesky": "^1.0.7",
|
||||
"@atcute/bluesky-richtext-builder": "^1.0.1",
|
||||
@ -144,6 +206,16 @@
|
||||
"url": "https://github.com/sponsors/mysticatea"
|
||||
}
|
||||
},
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag=="
|
||||
},
|
||||
"node_modules/multiformats": {
|
||||
"version": "9.9.0",
|
||||
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz",
|
||||
"integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg=="
|
||||
},
|
||||
"node_modules/partysocket": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/partysocket/-/partysocket-1.0.2.tgz",
|
||||
@ -172,6 +244,14 @@
|
||||
"node": "^14.13.1 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uint8arrays": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz",
|
||||
"integrity": "sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==",
|
||||
"dependencies": {
|
||||
"multiformats": "^9.4.2"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
||||
@ -192,6 +272,14 @@
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "3.24.2",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz",
|
||||
"integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@skyware/bot": "^0.3.7",
|
||||
"@atproto/identity": "^0.4.7",
|
||||
"@skyware/bot": "^0.3.11",
|
||||
"dotenv": "^16.4.5"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user