social media crossposting tool. 3rd time's the charm
mastodon
misskey
crossposting
bluesky
1import cross
2from util.media import MediaInfo
3
4
5class MisskeyPost(cross.Post):
6 def __init__(
7 self,
8 instance_url: str,
9 note: dict,
10 tokens: list[cross.Token],
11 files: list[MediaInfo],
12 ) -> None:
13 super().__init__()
14 self.note = note
15 self.id = note["id"]
16 self.parent_id = note.get("replyId")
17 self.tokens = tokens
18 self.timestamp = note["createdAt"]
19 self.media_attachments = files
20 self.spoiler = note.get("cw")
21 self.sensitive = any(
22 [a.get("isSensitive", False) for a in note.get("files", [])]
23 )
24 self.url = instance_url + "/notes/" + note["id"]
25
26 def get_id(self) -> str:
27 return self.id
28
29 def get_parent_id(self) -> str | None:
30 return self.parent_id
31
32 def get_tokens(self) -> list[cross.Token]:
33 return self.tokens
34
35 def get_text_type(self) -> str:
36 return "text/x.misskeymarkdown"
37
38 def get_timestamp(self) -> str:
39 return self.timestamp
40
41 def get_attachments(self) -> list[MediaInfo]:
42 return self.media_attachments
43
44 def get_spoiler(self) -> str | None:
45 return self.spoiler
46
47 def get_languages(self) -> list[str]:
48 return []
49
50 def is_sensitive(self) -> bool:
51 return self.sensitive or (self.spoiler is not None and self.spoiler != "")
52
53 def get_post_url(self) -> str | None:
54 return self.url