social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky
1from typing import Callable, Any 2from database import DataBaseWorker 3 4# generic token 5class Token(): 6 def __init__(self, type: str) -> None: 7 self.type = type 8 9class TextToken(Token): 10 def __init__(self, text: str) -> None: 11 super().__init__('text') 12 self.text = text 13 14# token that represents a link to a website. e.g. [link](https://google.com/) 15class LinkToken(Token): 16 def __init__(self, href: str, label: str) -> None: 17 super().__init__('link') 18 self.href = href 19 self.label = label 20 21# token that represents a hashtag. e.g. #SocialMedia 22class TagToken(Token): 23 def __init__(self, tag: str) -> None: 24 super().__init__('tag') 25 self.tag = tag 26 27# token that represents a mention of a user. 28class MentionToken(Token): 29 def __init__(self, username: str, uri: str) -> None: 30 super().__init__('mention') 31 self.username = username 32 self.uri = uri 33 34class MediaMeta(): 35 def __init__(self, width: int, height: int, duration: float) -> None: 36 self.width = width 37 self.height = height 38 self.duration = duration 39 40 def get_width(self) -> int: 41 return self.width 42 43 def get_height(self) -> int: 44 return self.height 45 46 def get_duration(self) -> float: 47 return self.duration 48 49class MediaAttachment(): 50 def __init__(self) -> None: 51 self.bytes: bytes | None = None # filled-in later 52 pass 53 54 def create_meta(self, bytes: bytes) -> MediaMeta: 55 return MediaMeta(-1, -1, -1) 56 57 def get_url(self) -> str: 58 return '' 59 60 def get_type(self) -> str | None: 61 return None 62 63 def get_alt(self) -> str: 64 return '' 65 66class Post(): 67 def __init__(self) -> None: 68 pass 69 70 def get_tokens(self) -> list[Token]: 71 return [] 72 73 def get_parent_id(self) -> str | None: 74 return None 75 76 def get_attachments(self) -> list[MediaAttachment]: 77 return [] 78 79 def get_id(self) -> str: 80 return '' 81 82 def get_cw(self) -> str: 83 return '' 84 85 def get_languages(self) -> list[str]: 86 return [] 87 88 def is_sensitive(self) -> bool: 89 return False 90 91# generic input service. 92# user and service for db queries 93class Input(): 94 def __init__(self, service: str, user_id: str, settings: dict, db: DataBaseWorker) -> None: 95 self.service = service 96 self.user_id = user_id 97 self.settings = settings 98 self.db = db 99 100 async def listen(self, handler: Callable[[Post], Any]): 101 pass 102 103class Output(): 104 def __init__(self, input: Input, settings: dict, db: DataBaseWorker) -> None: 105 self.input = input 106 self.settings = settings 107 self.db = db 108 109 def accept_post(self, post: Post): 110 pass 111 112 def delete_post(self, identifier: str): 113 pass