social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky

verify quotes actually hit the db

zenfyr.dev 9f45c8ac 5f5b5f17

verified
Changed files
+28 -7
bluesky
mastodon
misskey
+14 -7
bluesky/input.py
···
embed: dict[str, Any] = record.get("embed", {})
blob_urls: list[tuple[str, str, str | None]] = []
-
def handle_embeds(embed: dict[str, Any]):
+
def handle_embeds(embed: dict[str, Any]) -> str | None:
nonlocal blob_urls, post
match cast(str, embed["$type"]):
case "app.bsky.embed.record" | "app.bsky.embed.recordWithMedia":
rcrd = embed['record']['record'] if embed['record'].get('record') else embed['record']
did, collection, _ = AtUri.record_uri(rcrd["uri"])
if collection != "app.bsky.feed.post":
-
return
+
return f"Unhandled record collection {collection}"
if did != self.did:
-
return
+
return ""
+
+
rquote = self._get_post(self.url, did, rcrd["uri"])
+
if not rquote:
+
return f"Quote {rcrd["uri"]} not found in the db"
post.attachments.put(QuoteAttachment(quoted_id=rcrd["uri"], quoted_user=did))
if embed.get('media'):
-
handle_embeds(embed["media"])
+
return handle_embeds(embed["media"])
case "app.bsky.embed.images":
for image in embed["images"]:
blob_cid = image["image"]["ref"]["$link"]
···
url = f"{self.pds}/xrpc/com.atproto.sync.getBlob?did={self.did}&cid={blob_cid}"
blob_urls.append((url, blob_cid, embed.get("alt")))
case _:
-
self.log.warning(f"Unhandled embedd type {embed['$type']}")
-
pass
+
self.log.warning(f"Unhandled embed type {embed['$type']}")
+
if embed:
-
handle_embeds(embed)
+
fexit = handle_embeds(embed)
+
if fexit is not None:
+
self.log.info("Skipping %s! %s", post_uri, fexit)
+
return
if blob_urls:
blobs: list[Blob] = []
+7
mastodon/input.py
···
if not quote or quote["account"]["id"] != self.user_id:
return
+
rquote = self._get_post(self.url, self.user_id, quote['id'])
+
if not rquote:
+
self.log.info(
+
"Skipping %s, parent %s not found in db", status["id"], quote['id']
+
)
+
return
+
in_reply: str | None = status.get("in_reply_to_id")
in_reply_to: str | None = status.get("in_reply_to_account_id")
if in_reply_to and in_reply_to != self.user_id:
+7
misskey/input.py
···
if renote["userId"] != self.user_id:
return
+
rrenote = self._get_post(self.url, self.user_id, renote["id"])
+
if not rrenote:
+
self.log.info(
+
"Skipping %s, quote %s not found in db", note["id"], renote["id"]
+
)
+
return
+
reply: dict[str, Any] | None = note.get("reply")
if reply:
if reply.get("userId") != self.user_id: