142 lines
3.2 KiB
Python
142 lines
3.2 KiB
Python
# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge.
|
|
# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
from typing import Optional, Union
|
|
from enum import IntEnum
|
|
|
|
from attr import dataclass
|
|
|
|
from mautrix.types import SerializableAttrs
|
|
|
|
from ...bson import Long
|
|
from . import Attachment
|
|
from .emoticon import EmoticonAttachment
|
|
|
|
|
|
class KnownPostItemType(IntEnum):
|
|
TEXT = 1
|
|
FOOTER = 2
|
|
HEADER = 3
|
|
EMOTICON = 4
|
|
IMAGE = 5
|
|
VIDEO = 6
|
|
FILE = 7
|
|
SCHEDULE = 8
|
|
VOTE = 9
|
|
SCRAP = 10
|
|
|
|
PostItemType = Union[KnownPostItemType, int]
|
|
|
|
|
|
class KnownPostSubItemType(IntEnum):
|
|
pass
|
|
|
|
PostSubItemType = Union[KnownPostSubItemType, int]
|
|
|
|
|
|
class KnownPostFooterStyle(IntEnum):
|
|
ARTICLE = 1
|
|
SCHEDULE = 2
|
|
SCHEDULE_ANSWER = 3
|
|
VOTE = 4
|
|
VOTE_RESULT = 5
|
|
|
|
PostFooterStyle = Union[KnownPostFooterStyle, int]
|
|
|
|
|
|
class PostItem:
|
|
@dataclass
|
|
class Unknown(SerializableAttrs):
|
|
t: PostItemType
|
|
|
|
@dataclass(kw_only=True)
|
|
class Text(Unknown):
|
|
t = KnownPostItemType.TEXT
|
|
ct: str
|
|
jct: str
|
|
|
|
@dataclass(kw_only=True)
|
|
class Header(Unknown):
|
|
t = KnownPostItemType.HEADER
|
|
st: int
|
|
|
|
@dataclass
|
|
class UDict(SerializableAttrs):
|
|
id: Union[int, Long]
|
|
|
|
u: Optional[UDict]
|
|
|
|
@dataclass(kw_only=True)
|
|
class Image(Unknown):
|
|
t = KnownPostItemType.IMAGE
|
|
tt: Optional[str] = None
|
|
th: list[str]
|
|
g: Optional[bool] = None
|
|
|
|
@dataclass(kw_only=True)
|
|
class Emoticon(Unknown):
|
|
t = KnownPostItemType.EMOTICON
|
|
ct: EmoticonAttachment
|
|
|
|
@dataclass(kw_only=True)
|
|
class Vote(Unknown):
|
|
t = KnownPostItemType.VOTE
|
|
st: int
|
|
tt: str
|
|
ittpe: Optional[str] = None
|
|
its: list[dict]
|
|
|
|
@dataclass(kw_only=True)
|
|
class Video(Unknown):
|
|
t = KnownPostItemType.VIDEO
|
|
th: str
|
|
|
|
@dataclass(kw_only=True)
|
|
class File(Unknown):
|
|
t = KnownPostItemType.FILE
|
|
tt: str
|
|
c: int
|
|
|
|
@dataclass(kw_only=True)
|
|
class Footer(Unknown):
|
|
t = KnownPostItemType.FOOTER
|
|
st: PostFooterStyle
|
|
url: str
|
|
|
|
|
|
@dataclass(kw_only=True)
|
|
class PostAttachment(Attachment):
|
|
subtype: Optional[PostSubItemType] = None
|
|
os: list[PostItem.Unknown]
|
|
|
|
|
|
@dataclass
|
|
class VoteAttachment(PostAttachment):
|
|
voteId: int
|
|
title: str
|
|
|
|
|
|
__all__ = [
|
|
"KnownPostItemType",
|
|
"PostItemType",
|
|
"KnownPostSubItemType",
|
|
"PostSubItemType",
|
|
"KnownPostFooterStyle",
|
|
"PostFooterStyle",
|
|
"PostItem",
|
|
"PostAttachment",
|
|
"VoteAttachment",
|
|
]
|