mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-09-22 19:22:01 +03:00
fix(models): Fix some models attributes parsing
This commit is contained in:
parent
e8c7b81c7e
commit
003d6e7bcc
3 changed files with 105 additions and 88 deletions
|
@ -28,6 +28,16 @@ class GatewayBotInfo(APIModelBase):
|
|||
shards: int
|
||||
session_start_limit: dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, Any]):
|
||||
self: GatewayBotInfo = super().__new__(cls)
|
||||
|
||||
self.url = data.get("url")
|
||||
self.shards = data.get("shards")
|
||||
self.session_start_limit = data.get("session_start_limit")
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class Gateway:
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ class Channel(APIModelBase):
|
|||
For guild channels: id of the parent category for a channel
|
||||
(each parent category can contain up to 50 channels),
|
||||
for threads: id of the text channel this thread was created
|
||||
last_pin_timestamp: :class:`int`
|
||||
last_pin_timestamp: :class:`~melisa.utils.timestamp.Timestamp`
|
||||
When the last pinned message was pinned.
|
||||
This may be `null` in events such as `GUILD_CREATE` when a message is not pinned.
|
||||
rtc_region: :class:`str`
|
||||
|
@ -171,32 +171,32 @@ class Channel(APIModelBase):
|
|||
only included when part of the `resolved` data received on a slash command interaction
|
||||
"""
|
||||
|
||||
id: APINullable[Snowflake] = UNDEFINED
|
||||
type: APINullable[int] = UNDEFINED
|
||||
guild_id: APINullable[Snowflake] = UNDEFINED
|
||||
position: APINullable[int] = UNDEFINED
|
||||
permission_overwrites: APINullable[List] = UNDEFINED
|
||||
name: APINullable[str] = UNDEFINED
|
||||
topic: APINullable[str] = UNDEFINED
|
||||
nsfw: APINullable[bool] = UNDEFINED
|
||||
last_message_id: APINullable[Snowflake] = UNDEFINED
|
||||
bitrate: APINullable[int] = UNDEFINED
|
||||
user_limit: APINullable[int] = UNDEFINED
|
||||
rate_limit_per_user: APINullable[int] = UNDEFINED
|
||||
recipients: APINullable[List] = UNDEFINED
|
||||
icon: APINullable[str] = UNDEFINED
|
||||
owner_id: APINullable[Snowflake] = UNDEFINED
|
||||
application_id: APINullable[Snowflake] = UNDEFINED
|
||||
parent_id: APINullable[Snowflake] = UNDEFINED
|
||||
last_pin_timestamp: APINullable[Timestamp] = UNDEFINED
|
||||
rtc_region: APINullable[str] = UNDEFINED
|
||||
video_quality_mode: APINullable[int] = UNDEFINED
|
||||
message_count: APINullable[int] = UNDEFINED
|
||||
member_count: APINullable[int] = UNDEFINED
|
||||
thread_metadata: APINullable[ThreadMetadata] = UNDEFINED
|
||||
member: APINullable[List] = UNDEFINED
|
||||
default_auto_archive_duration: APINullable[int] = UNDEFINED
|
||||
permissions: APINullable[str] = UNDEFINED
|
||||
id: APINullable[Snowflake] = None
|
||||
type: APINullable[int] = None
|
||||
guild_id: APINullable[Snowflake] = None
|
||||
position: APINullable[int] = None
|
||||
permission_overwrites: APINullable[List] = None
|
||||
name: APINullable[str] = None
|
||||
topic: APINullable[str] = None
|
||||
nsfw: APINullable[bool] = None
|
||||
last_message_id: APINullable[Snowflake] = None
|
||||
bitrate: APINullable[int] = None
|
||||
user_limit: APINullable[int] = None
|
||||
rate_limit_per_user: APINullable[int] = None
|
||||
recipients: APINullable[List] = None
|
||||
icon: APINullable[str] = None
|
||||
owner_id: APINullable[Snowflake] = None
|
||||
application_id: APINullable[Snowflake] = None
|
||||
parent_id: APINullable[Snowflake] = None
|
||||
last_pin_timestamp: APINullable[Timestamp] = None
|
||||
rtc_region: APINullable[str] = None
|
||||
video_quality_mode: APINullable[int] = None
|
||||
message_count: APINullable[int] = None
|
||||
member_count: APINullable[int] = None
|
||||
thread_metadata: APINullable[ThreadMetadata] = None
|
||||
member: APINullable[List] = None
|
||||
default_auto_archive_duration: APINullable[int] = None
|
||||
permissions: APINullable[str] = None
|
||||
|
||||
@property
|
||||
def mention(self):
|
||||
|
@ -734,18 +734,22 @@ class TextChannel(MessageableChannel):
|
|||
|
||||
self.id = data["id"]
|
||||
self.type = data["type"]
|
||||
self.guild_id = Snowflake(data["guild_id"])
|
||||
self.position = data["position"]
|
||||
self.position = data.get("position")
|
||||
self.permission_overwrites = data["permission_overwrites"]
|
||||
self.name = data["name"]
|
||||
self.name = data.get("name")
|
||||
self.topic = data.get("topic")
|
||||
self.nsfw = data["nsfw"]
|
||||
self.nsfw = data.get("nsfw")
|
||||
|
||||
if data.get("last_message_id") is not None:
|
||||
self.last_message_id = Snowflake(data["last_message_id"])
|
||||
else:
|
||||
self.last_message_id = None
|
||||
|
||||
if data.get("guild_id") is not None:
|
||||
self.guild_id = Snowflake(data["guild_id"])
|
||||
else:
|
||||
self.guild_id = None
|
||||
|
||||
self.rate_limit_per_user = data.get("rate_limit_per_user")
|
||||
|
||||
if data.get("parent_id") is not None:
|
||||
|
@ -754,7 +758,7 @@ class TextChannel(MessageableChannel):
|
|||
self.parent_id = None
|
||||
|
||||
if data.get("last_pin_timestamp") is not None:
|
||||
self.last_pin_timestamp = Snowflake(data["last_pin_timestamp"])
|
||||
self.last_pin_timestamp = Timestamp.parse(data["last_pin_timestamp"])
|
||||
else:
|
||||
self.last_pin_timestamp = None
|
||||
|
||||
|
@ -859,7 +863,7 @@ class Thread(MessageableChannel):
|
|||
self.member_count = data.get("member_count")
|
||||
|
||||
if data.get("last_pin_timestamp") is not None:
|
||||
self.last_pin_timestamp = Snowflake(data["last_pin_timestamp"])
|
||||
self.last_pin_timestamp = Timestamp.parse(data["last_pin_timestamp"])
|
||||
else:
|
||||
self.last_pin_timestamp = None
|
||||
|
||||
|
|
|
@ -240,9 +240,9 @@ class Guild(APIModelBase):
|
|||
States of members currently in voice channels; lacks the `guild_id` key
|
||||
members: APINullable[:class:`typing.Any`]
|
||||
Users in the guild
|
||||
channels: APINullable[:class:`typing.Any`]
|
||||
channels: APINullable[Dict[:class:`~melisa.models.guild.channel.Channel`]]
|
||||
Channels in the guild
|
||||
threads: APINullable[:class:`typing.Any`]
|
||||
threads: APINullable[Dict[:class:`~melisa.models.guild.channel.Thread`]]
|
||||
All active threads in the guild that current user has permission to view
|
||||
presences: APINullable[:class:`typing.Any`]
|
||||
Presences of the members in the guild, will only include non-offline members
|
||||
|
@ -293,63 +293,63 @@ class Guild(APIModelBase):
|
|||
The scheduled events in the guild
|
||||
"""
|
||||
|
||||
id: APINullable[Snowflake] = UNDEFINED
|
||||
name: APINullable[str] = UNDEFINED
|
||||
icon: APINullable[str] = UNDEFINED
|
||||
icon_hash: APINullable[str] = UNDEFINED
|
||||
splash: APINullable[str] = UNDEFINED
|
||||
discovery_splash: APINullable[str] = UNDEFINED
|
||||
owner: APINullable[bool] = UNDEFINED
|
||||
owner_id: APINullable[Snowflake] = UNDEFINED
|
||||
permissions: APINullable[str] = UNDEFINED
|
||||
region: APINullable[str] = UNDEFINED
|
||||
afk_channel_id: APINullable[Snowflake] = UNDEFINED
|
||||
afk_timeout: APINullable[int] = UNDEFINED
|
||||
widget_enabled: APINullable[bool] = UNDEFINED
|
||||
widget_channel_id: APINullable[Snowflake] = UNDEFINED
|
||||
verification_level: APINullable[int] = UNDEFINED
|
||||
default_message_notifications: APINullable[int] = UNDEFINED
|
||||
explicit_content_filter: APINullable[int] = UNDEFINED
|
||||
features: APINullable[List[str]] = UNDEFINED
|
||||
roles: APINullable[List] = UNDEFINED
|
||||
emojis: APINullable[List] = UNDEFINED
|
||||
id: Snowflake
|
||||
roles: APINullable[List]
|
||||
emojis: APINullable[List]
|
||||
members: APINullable[List]
|
||||
threads: APINullable[Dict]
|
||||
presences: APINullable[List]
|
||||
channels: APINullable[Dict]
|
||||
name: APINullable[str] = None
|
||||
icon: APINullable[str] = None
|
||||
icon_hash: APINullable[str] = None
|
||||
splash: APINullable[str] = None
|
||||
discovery_splash: APINullable[str] = None
|
||||
owner: APINullable[bool] = None
|
||||
owner_id: APINullable[Snowflake] = None
|
||||
permissions: APINullable[str] = None
|
||||
region: APINullable[str] = None
|
||||
afk_channel_id: APINullable[Snowflake] = None
|
||||
afk_timeout: APINullable[int] = None
|
||||
widget_enabled: APINullable[bool] = None
|
||||
widget_channel_id: APINullable[Snowflake] = None
|
||||
verification_level: APINullable[int] = None
|
||||
default_message_notifications: APINullable[int] = None
|
||||
explicit_content_filter: APINullable[int] = None
|
||||
features: APINullable[List[str]] = None
|
||||
# TODO: Make a structures of emoji and role
|
||||
|
||||
mfa_level: APINullable[MFALevel] = UNDEFINED
|
||||
application_id: APINullable[Snowflake] = UNDEFINED
|
||||
system_channel_id: APINullable[Snowflake] = UNDEFINED
|
||||
system_channel_flags: APINullable[SystemChannelFlags] = UNDEFINED
|
||||
rules_channel_id: APINullable[Snowflake] = UNDEFINED
|
||||
joined_at: APINullable[Timestamp] = UNDEFINED
|
||||
mfa_level: APINullable[MFALevel] = None
|
||||
application_id: APINullable[Snowflake] = None
|
||||
system_channel_id: APINullable[Snowflake] = None
|
||||
system_channel_flags: APINullable[SystemChannelFlags] = None
|
||||
rules_channel_id: APINullable[Snowflake] = None
|
||||
joined_at: APINullable[Timestamp] = None
|
||||
|
||||
large: APINullable[bool] = UNDEFINED
|
||||
unavailable: APINullable[bool] = UNDEFINED
|
||||
member_count: APINullable[int] = UNDEFINED
|
||||
voice_states: APINullable[List] = UNDEFINED
|
||||
members: APINullable[List] = UNDEFINED
|
||||
threads: APINullable[List] = UNDEFINED
|
||||
presences: APINullable[List] = UNDEFINED
|
||||
channels: APINullable[List] = UNDEFINED
|
||||
large: APINullable[bool] = None
|
||||
unavailable: APINullable[bool] = None
|
||||
member_count: APINullable[int] = None
|
||||
voice_states: APINullable[List] = None
|
||||
# TODO: Make a structure for voice_states, members, channels, threads, presences(?)
|
||||
|
||||
max_presences: APINullable[int] = UNDEFINED
|
||||
max_members: APINullable[int] = UNDEFINED
|
||||
vanity_url_code: APINullable[str] = UNDEFINED
|
||||
description: APINullable[str] = UNDEFINED
|
||||
banner: APINullable[str] = UNDEFINED
|
||||
premium_tier: APINullable[str] = UNDEFINED
|
||||
premium_subscription_count: APINullable[int] = UNDEFINED
|
||||
preferred_locale: APINullable[str] = UNDEFINED
|
||||
public_updates_channel_id: APINullable[Snowflake] = UNDEFINED
|
||||
max_video_channel_users: APINullable[int] = UNDEFINED
|
||||
approximate_member_count: APINullable[int] = UNDEFINED
|
||||
approximate_presence_count: APINullable[int] = UNDEFINED
|
||||
nsfw_level: APINullable[int] = UNDEFINED
|
||||
premium_progress_bar_enabled: APINullable[bool] = UNDEFINED
|
||||
stage_instances: APINullable[List] = UNDEFINED
|
||||
stickers: APINullable[List] = UNDEFINED
|
||||
welcome_screen: APINullable = UNDEFINED
|
||||
guild_scheduled_events: APINullable[List] = UNDEFINED
|
||||
max_presences: APINullable[int] = None
|
||||
max_members: APINullable[int] = None
|
||||
vanity_url_code: APINullable[str] = None
|
||||
description: APINullable[str] = None
|
||||
banner: APINullable[str] = None
|
||||
premium_tier: APINullable[str] = None
|
||||
premium_subscription_count: APINullable[int] = None
|
||||
preferred_locale: APINullable[str] = None
|
||||
public_updates_channel_id: APINullable[Snowflake] = None
|
||||
max_video_channel_users: APINullable[int] = None
|
||||
approximate_member_count: APINullable[int] = None
|
||||
approximate_presence_count: APINullable[int] = None
|
||||
nsfw_level: APINullable[int] = None
|
||||
premium_progress_bar_enabled: APINullable[bool] = None
|
||||
stage_instances: APINullable[List] = None
|
||||
stickers: APINullable[List] = None
|
||||
welcome_screen: APINullable = None
|
||||
guild_scheduled_events: APINullable[List] = None
|
||||
|
||||
# TODO: Make a structure for welcome_screen, stage_instances,
|
||||
# stickers and guild_scheduled_events
|
||||
|
@ -429,7 +429,7 @@ class Guild(APIModelBase):
|
|||
self.afk_channel_id = None
|
||||
|
||||
if data.get("joined_at") is not None:
|
||||
self.joined_at = Timestamp(data["joined_at"])
|
||||
self.joined_at = Timestamp.parse(data["joined_at"])
|
||||
else:
|
||||
self.joined_at = None
|
||||
|
||||
|
@ -441,6 +441,9 @@ class Guild(APIModelBase):
|
|||
self.members = data.get("members")
|
||||
self.presences = data.get("presences")
|
||||
|
||||
self.threads = {}
|
||||
self.channels = {}
|
||||
|
||||
for thread in data.get("threads", []):
|
||||
self.threads[thread["id"]] = Thread.from_dict(thread)
|
||||
|
||||
|
|
Loading…
Reference in a new issue