matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/kt/types/openlink/__init__.py

147 lines
3.4 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 .open_channel_info import *
from .open_channel import *
from .open_link_type import *
from .open_link_user_info import *
"""
from typing import TYPE_CHECKING, Optional, Union
from attr import dataclass
from enum import IntEnum
from mautrix.types import SerializableAttrs
from ..bson import Long
from .open_link_type import OpenLinkType
if TYPE_CHECKING:
from .open_link_user_info import OpenLinkUserInfo
@dataclass
class OpenLinkComponent(SerializableAttrs):
linkId: Long
@dataclass
class OpenTokenComponent(SerializableAttrs):
openToken: int
# Moved before OpenPrivilegeComponent which requires this
class KnownLinkPrivilegeMask(IntEnum):
URL_SHARABLE = 2
REPORTABLE = 4
PROFILE_EDITABLE = 8
ANY_PROFILE_ALLOWED = 32
USE_PASS_CODE = 64
BLINDABLE = 128
NON_SPECIAL_LINK = 512
USE_BOT = 1024
LinkPrivilegeMask = Union[KnownLinkPrivilegeMask, int, Long]
@dataclass
class OpenPrivilegeComponent(SerializableAttrs):
privilege: LinkPrivilegeMask
@dataclass(kw_only=True)
class OpenLinkSettings(SerializableAttrs):
linkName: str
linkCoverURL: Optional[str] = None
description: Optional[str] = None
searchable: bool
activated: bool
@dataclass
class OpenLink(OpenLinkSettings, OpenLinkComponent, OpenTokenComponent, OpenPrivilegeComponent):
type: OpenLinkType
linkURL: str
openToken: int
linkOwner: "OpenLinkUserInfo"
profileTagList: list[str]
createdAt: int
@dataclass
class OpenLinkChannelInfo(SerializableAttrs):
userLimit: int
@dataclass
class OpenLinkProfileInfo(SerializableAttrs):
directLimit: int
@dataclass
class OpenLinkInfo(OpenLinkChannelInfo, OpenLinkProfileInfo):
pass
@dataclass
class InformedOpenLink(SerializableAttrs):
openLink: OpenLink
info: OpenLinkInfo
# KnownLinkPrivilegeMask and LinkPrivilegeMask moved from here
@dataclass(kw_only=True)
class OpenLinkUpdateTemplate(SerializableAttrs):
passcode: Optional[str] = None
@dataclass(kw_only=True)
class OpenLinkCreateTemplate(SerializableAttrs):
mainProfileOnly: Optional[bool] = None
@dataclass
class OpenLinkProfileTemplate(OpenLinkSettings, OpenLinkProfileInfo):
tags: str
@dataclass
class OpenLinkChannelTemplate(OpenLinkSettings, OpenLinkChannelInfo):
pass
__all__ = [
"OpenLinkComponent",
"OpenTokenComponent",
"KnownLinkPrivilegeMask",
"LinkPrivilegeMask",
"OpenPrivilegeComponent",
"OpenLinkSettings",
"OpenLink",
"OpenLinkChannelInfo",
"OpenLinkProfileInfo",
"OpenLinkInfo",
"InformedOpenLink",
"OpenLinkUpdateTemplate",
"OpenLinkCreateTemplate",
"OpenLinkProfileTemplate",
"OpenLinkChannelTemplate",
]