Merge pull request #32 from yupix/feat/support-v13

Feat/support v13
pull/35/head
yupix 2 years ago committed by GitHub
commit 5e123b4b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from mipac.abstract.action import AbstractAction
from mipac.config import config
from mipac.errors.base import NotSupportVersion
from mipac.http import Route
from mipac.models.emoji import CustomEmoji
from mipac.models.note import NoteReaction
@ -78,10 +80,16 @@ class ReactionActions(AbstractAction):
return [NoteReaction(i, client=self.__client) for i in res]
async def get_emoji_list(self) -> list[CustomEmoji]:
if config.use_version >= 13:
raise NotSupportVersion('Misskey v13以降では使用できません')
data: IInstanceMetaLite = await self.__session.request(
Route('GET', '/api/meta'),
json={'detail': False},
auth=True,
replace_list={'ToSUrl': 'tos_url', 'ToSTextUrl': 'tos_text_url'},
)
return [CustomEmoji(i, client=self.__client) for i in data['emojis']]
return [
CustomEmoji(i, client=self.__client)
for i in data.get('emojis', [])
]

@ -38,3 +38,7 @@ class NotExistRequiredData(Exception):
class ParameterError(Exception):
"""引数に関するエラー"""
class NotSupportVersion(Exception):
"""サポートされていないバージョンのインスタンス"""

@ -3,7 +3,12 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from mipac.models.lite.instance import LiteInstanceMeta
from mipac.types.instance import IFederationInstance, IInstanceMeta
from mipac.types.instance import (
IFederationInstance,
IInstanceFeatures,
IInstanceMeta,
IInstancePolicies,
)
if TYPE_CHECKING:
from mipac.client import ClientActions
@ -115,12 +120,11 @@ class FederationInstance:
return self.__instance.get('last_communicated_at')
class InstanceMeta(LiteInstanceMeta):
class InstanceFeatures:
def __init__(
self, instance: IInstanceMeta, *, client: ClientActions
self, features: IInstanceFeatures, *, client: ClientActions
) -> None:
super().__init__(instance, client=client)
self.__features = instance['features']
self.__features = features
@property
def registration(self) -> bool:
@ -173,3 +177,116 @@ class InstanceMeta(LiteInstanceMeta):
@property
def miauth(self) -> bool:
return self.__features['miauth']
class InstancePolicies:
def __init__(self, policies: IInstancePolicies) -> None:
self.__policies = policies
@property
def gtl_available(self) -> bool:
return self.__policies['gtl_available']
@property
def ltl_available(self) -> bool:
return self.__policies['ltl_available']
@property
def can_public_note(self) -> bool:
return self.__policies['can_public_note']
@property
def can_invite(self) -> bool:
return self.__policies['can_invite']
@property
def can_manage_custom_emojis(self) -> bool:
return self.__policies['can_manage_custom_emojis']
@property
def can_hide_ads(self) -> bool:
return self.__policies['can_hide_ads']
@property
def drive_capacity_mb(self) -> int:
return self.__policies['drive_capacity_mb']
@property
def pin_limit(self) -> int:
return self.__policies['pin_limit']
@property
def antenna_limit(self) -> int:
return self.__policies['antenna_limit']
@property
def word_mute_limit(self) -> int:
return self.__policies['word_mute_limit']
@property
def webhook_limit(self) -> int:
return self.__policies['webhook_limit']
@property
def clip_limit(self) -> int:
return self.__policies['clip_limit']
@property
def note_each_clips_limit(self) -> int:
return self.__policies['note_each_clips_limit']
@property
def user_list_limit(self) -> int:
return self.__policies['user_list_limit']
@property
def user_each_user_lists_limit(self) -> int:
return self.__policies['user_each_user_lists_limit']
@property
def rate_limit_factor(self) -> int:
return self.__policies['rate_limit_factor']
class InstanceMeta(LiteInstanceMeta):
def __init__(
self, instance: IInstanceMeta, *, client: ClientActions
) -> None:
super().__init__(instance, client=client)
self.__meta = instance
@property
def policies(self) -> InstancePolicies | None:
return (
InstancePolicies(self.__meta['policies'])
if 'policies' in self.__meta
else None
)
@property
def features(self):
return InstanceFeatures(self.__meta['features'], client=self.__client)
@property
def cache_remote_files(self) -> bool:
return self.__meta['cache_remote_files']
@property
def pinned_pages(self) -> list[str]:
return self.__meta.get('pinned_pages', [])
@property
def pinned_clip_id(self) -> str | None:
return self.__meta.get('pinned_clip_id')
@property
def require_setup(self) -> bool:
return self.__meta.get('require_setup', False)
@property
def proxy_account_name(self) -> str | None:
return self.__meta.get('proxy_account_name')
@property
def proxy_account(self) -> str | None:
return self.__meta.get('proxy_account')

@ -1,23 +1,10 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, TypedDict
from typing import Any, TypedDict
from mipac.types.ads import IAds
from mipac.types.emoji import ICustomEmoji
if TYPE_CHECKING:
from mipac.types.emoji import EmojiPayload
__all__ = (
'FeaturesPayload',
'MetaPayload',
'InstancePayload',
'OptionalInstance',
'OptionalMeta',
'IInstanceLite',
'IInstanceMeta',
)
class IFederationInstanceRequired(TypedDict):
id: str
@ -58,7 +45,7 @@ class IInstanceLite(TypedDict):
theme_color: str
class FeaturesPayload(TypedDict):
class IInstanceFeatures(TypedDict):
registration: bool
local_time_line: bool
global_time_line: bool
@ -74,49 +61,6 @@ class FeaturesPayload(TypedDict):
miauth: bool
class OptionalMeta(TypedDict, total=False):
pinned_page: list[str]
cache_remote_files: bool
proxy_remote_files: bool
require_setup: bool
features: FeaturesPayload
class MetaPayload(OptionalMeta):
maintainer_name: str
maintainer_email: str
version: str
name: str
uri: str
description: str
langs: list[str]
tos_url: str | None
repository_url: str
feedback_url: str
secure: bool
disable_registration: bool
disable_local_timeline: bool
disable_global_timeline: bool
drive_capacity_per_local_user_mb: int
drive_capacity_per_remote_user_mb: int
email_required_for_signup: bool
enable_hcaptcha: bool
enable_recaptcha: bool
recaptcha_site_key: str
sw_publickey: str
mascot_image_url: str
error_image_url: str
max_note_text_length: int
emojis: list[EmojiPayload]
ads: list
enable_email: bool
enable_twitter_integration: bool
enable_github_integration: bool
enable_discord_integration: bool
enable_service_worker: bool
translator_available: bool
class IInstanceMetaLiteRequired(TypedDict):
version: str
uri: str
@ -132,17 +76,18 @@ class IInstanceMetaLiteRequired(TypedDict):
enable_github_integration: bool
enable_discord_integration: bool
enable_service_worker: bool
emojis: list[ICustomEmoji]
mascot_image_url: str
banner_url: str
icon_url: str
description: str
repository_url: str
turnstile_site_key: str | None
class IInstanceMetaLite(IInstanceMetaLiteRequired, total=False):
maintainer_name: str
maintainer_email: str
name: str
description: str
langs: list[str]
tos_url: str
tos_text_url: str
@ -151,21 +96,88 @@ class IInstanceMetaLite(IInstanceMetaLiteRequired, total=False):
enable_recaptcha: bool
recaptcha_siteKey: str
sw_publickey: str
ads: list[IAds] # v12 only
class IInstanceMeta(IInstanceMetaLite):
features: FeaturesPayload
class OptionalInstance(TypedDict, total=False):
host: str
software_name: str
software_version: str
icon_url: str
favicon_url: str
theme_color: str
disable_global_timeline: bool # ayuskey or v11
disable_local_timeline: bool # ayuskey or v11
enable_emoji_reaction: bool
github_client_id: str
github_client_secret: str
hidden_tags: list[str]
machine: str
node: str
object_storage_access_key: str
object_storage_base_url: str
object_storage_bucket: str
object_storage_endpoint: str
object_storage_port: int
object_storage_prefix: str
object_storage_region: str
object_storage_s3_force_path_style: bool
object_storage_secret_key: str
object_storage_set_public_read: bool
object_storage_use_proxy: bool
object_storage_use_ssl: bool
os: str
pinned_users: list[str]
proxy_account: str
proxy_remote_files: bool
psql: str
recaptcha_secret_key: str
secure: bool
smtp_host: str
smtp_pass: str
smtp_port: str
smtp_secure: bool
smtp_user: str
summaly_proxy: str
sw_private_key: str
turnstile_secret_key: str
twitter_consumer_key: str
twitter_consumer_secret: str
use_object_storage: bool
use_star_for_reaction_fallback: bool
email: str # ayuskey or v11
discord_client_id: str # ayuskey or v11
discord_client_secret: str # ayuskey or v11
drive_capacity_per_local_user_mb: int # ayuskey or v11
drive_capacity_per_remote_user_mb: int # ayuskey or v11
emojis: list[ICustomEmoji] # v13から無くなった為
background_image_url: str
default_dark_theme: str
default_light_theme: str
email_required_for_signup: bool
logo_image_url: str
ads: list[IAds] # v12 only
translator_available: bool # v12 only
class IInstancePolicies(TypedDict):
gtl_available: bool
ltl_available: bool
can_public_note: bool
can_invite: bool
can_manage_custom_emojis: bool
can_hide_ads: bool
drive_capacity_mb: int
pin_limit: int
antenna_limit: int
word_mute_limit: int
webhook_limit: int
clip_limit: int
note_each_clips_limit: int
user_list_limit: int
user_each_user_lists_limit: int
rate_limit_factor: int
class IInstanceMetaRequired(IInstanceMetaLite):
features: IInstanceFeatures
cache_remote_files: bool
class InstancePayload(OptionalInstance, MetaPayload):
meta: MetaPayload
class IInstanceMeta(IInstanceMetaRequired, total=False):
policies: IInstancePolicies
pinned_pages: list[str]
pinned_clip_id: str
require_setup: bool
proxy_account_name: str

Loading…
Cancel
Save