Compare commits
	
		
			No commits in common. "5da60912bedbee6832f0d980adac4b5e02b3e3d8" and "9bead82ecf3ed49908d9f1c9e5eeb19abee55240" have entirely different histories.
		
	
	
		
			5da60912be
			...
			9bead82ecf
		
	
		
							
								
								
									
										69
									
								
								index.mjs
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								index.mjs
									
									
									
									
									
								
							@ -1,9 +1,5 @@
 | 
				
			|||||||
import "dotenv/config";
 | 
					import "dotenv/config";
 | 
				
			||||||
import {Bot, RichText, Post} from "@skyware/bot";
 | 
					import {Bot, RichText} 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();
 | 
					var bot = new Bot();
 | 
				
			||||||
await bot.login({
 | 
					await bot.login({
 | 
				
			||||||
@ -12,54 +8,43 @@ await bot.login({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
bot.on("error", console.error);
 | 
					bot.on("error", console.error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bot.on("mention", async post => {
 | 
					bot.on("mention", async mention => {
 | 
				
			||||||
 | 
						//console.log({mention});
 | 
				
			||||||
 | 
						var parent = mention.replyRef?.parent;
 | 
				
			||||||
 | 
						if (!parent) return;
 | 
				
			||||||
 | 
						//console.log({parent});
 | 
				
			||||||
	try {
 | 
						try {
 | 
				
			||||||
		// video in mentioning post or quoted post
 | 
							var parentPost = await bot.getPost(parent.uri);
 | 
				
			||||||
		var vid = await findVideoInPost(post);
 | 
							//console.log({parentPost});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// ignore original posts without video
 | 
							var embed = parentPost.embed;
 | 
				
			||||||
		if (!vid && !post.replyRef) return;
 | 
							if (!embed || !embed.isVideo()) {
 | 
				
			||||||
 | 
								//await mention.reply({text: "Sorry, it doesn't seem that this post has a video."})
 | 
				
			||||||
		// video in replied post or quoted in replied post
 | 
					 | 
				
			||||||
		if (!vid) {
 | 
					 | 
				
			||||||
			var parentPost = await bot.getPost(post.replyRef.parent.uri);
 | 
					 | 
				
			||||||
			vid = await findVideoInPost(parentPost);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// 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;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		var url = `${await getServiceEndpoint(vid.did)}/xrpc/com.atproto.sync.getBlob?did=${vid.did}&cid=${vid.cid}`;
 | 
							var did = parentPost.author.did;
 | 
				
			||||||
		url = `https://avps.owo69.me/download.html?filename=${vid.cid}.mp4&url=${encodeURIComponent(url)}`;
 | 
							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)}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var text = new RichText().addLink("Click or touch here to download this video", url);
 | 
							var text = new RichText().addLink("Click or touch here to download this video", url);
 | 
				
			||||||
		await post.reply({text});
 | 
							await mention.reply({text});
 | 
				
			||||||
	} catch (error) {
 | 
						} catch (error) {
 | 
				
			||||||
		console.error(error);
 | 
							console.error(error);
 | 
				
			||||||
		await post.reply({text: String(error.message?.substring(0,300))});
 | 
							await mention.reply({text: "error"});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function findVideoInPost(post) {
 | 
					 | 
				
			||||||
	if (!post.embed) return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (post.embed.isVideo())
 | 
					 | 
				
			||||||
		return {did: post.author.did, cid: post.embed.cid};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (post.embed.isRecordWithMedia() && post.embed.media.isVideo())
 | 
					async function getServiceEndpoint(did) {
 | 
				
			||||||
		return {did: post.author.did, cid: post.embed.media.cid};
 | 
						//try {
 | 
				
			||||||
 | 
							var doc = await fetch(`https://plc.directory/${did}`).then(res => res.json());
 | 
				
			||||||
	if (post.embed.isRecord() && post.embed.record instanceof Post) {
 | 
							var {serviceEndpoint} = doc.service.find(s => s.id == "#atproto_pds");
 | 
				
			||||||
		// post.embed.record.embed is undefined
 | 
							return serviceEndpoint;
 | 
				
			||||||
		let quotedPost = await bot.getPost(post.embed.record.uri);
 | 
						//} catch (error) {
 | 
				
			||||||
		return await findVideoInPost(quotedPost);
 | 
						//	console.error(error);
 | 
				
			||||||
	}
 | 
						//	return `https://bsky.network`;
 | 
				
			||||||
 | 
						//}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										96
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										96
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -5,8 +5,7 @@
 | 
				
			|||||||
  "packages": {
 | 
					  "packages": {
 | 
				
			||||||
    "": {
 | 
					    "": {
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "@atproto/identity": "^0.4.7",
 | 
					        "@skyware/bot": "^0.3.7",
 | 
				
			||||||
        "@skyware/bot": "^0.3.11",
 | 
					 | 
				
			||||||
        "dotenv": "^16.4.5"
 | 
					        "dotenv": "^16.4.5"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -84,71 +83,10 @@
 | 
				
			|||||||
      "integrity": "sha512-NEBOGkdaDY8cjlDg49kefIsRM7iv/4oReEnOr3bN4tF3IxBGdc6Io1NCJz1xNBNdUL+3VDG3CKHiRji91HXaTg==",
 | 
					      "integrity": "sha512-NEBOGkdaDY8cjlDg49kefIsRM7iv/4oReEnOr3bN4tF3IxBGdc6Io1NCJz1xNBNdUL+3VDG3CKHiRji91HXaTg==",
 | 
				
			||||||
      "optional": true
 | 
					      "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": {
 | 
					    "node_modules/@skyware/bot": {
 | 
				
			||||||
      "version": "0.3.11",
 | 
					      "version": "0.3.7",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/@skyware/bot/-/bot-0.3.11.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/@skyware/bot/-/bot-0.3.7.tgz",
 | 
				
			||||||
      "integrity": "sha512-fG4uvD/3+ynlQPRHv6pz4kk+5fbDNJYTORbLXwmlwWAzJ7FSBkahG1NeK2M+hqIYBVqdzAI5QqcM17fwJXeZeQ==",
 | 
					      "integrity": "sha512-27k7r4/YA+h8FobXokMa3iv8fm/850a7NmajOHP3/CaMbCYicXXBDnAIY4kIPP58Zl/A/JvdcFLpQBpfFkiQHQ==",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "@atcute/bluesky": "^1.0.7",
 | 
					        "@atcute/bluesky": "^1.0.7",
 | 
				
			||||||
        "@atcute/bluesky-richtext-builder": "^1.0.1",
 | 
					        "@atcute/bluesky-richtext-builder": "^1.0.1",
 | 
				
			||||||
@ -206,16 +144,6 @@
 | 
				
			|||||||
        "url": "https://github.com/sponsors/mysticatea"
 | 
					        "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": {
 | 
					    "node_modules/partysocket": {
 | 
				
			||||||
      "version": "1.0.2",
 | 
					      "version": "1.0.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/partysocket/-/partysocket-1.0.2.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/partysocket/-/partysocket-1.0.2.tgz",
 | 
				
			||||||
@ -244,14 +172,6 @@
 | 
				
			|||||||
        "node": "^14.13.1 || >=16.0.0"
 | 
					        "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": {
 | 
					    "node_modules/ws": {
 | 
				
			||||||
      "version": "8.18.0",
 | 
					      "version": "8.18.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
 | 
				
			||||||
@ -272,14 +192,6 @@
 | 
				
			|||||||
          "optional": true
 | 
					          "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,7 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "@atproto/identity": "^0.4.7",
 | 
					    "@skyware/bot": "^0.3.7",
 | 
				
			||||||
    "@skyware/bot": "^0.3.11",
 | 
					 | 
				
			||||||
    "dotenv": "^16.4.5"
 | 
					    "dotenv": "^16.4.5"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user