fix(models): Fix some models attributes parsing

This commit is contained in:
grey-cat-1908 2022-04-16 14:45:54 +03:00
parent e8c7b81c7e
commit 003d6e7bcc
3 changed files with 105 additions and 88 deletions

View file

@ -28,6 +28,16 @@ class GatewayBotInfo(APIModelBase):
shards: int shards: int
session_start_limit: dict 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: class Gateway:

View file

@ -148,7 +148,7 @@ class Channel(APIModelBase):
For guild channels: id of the parent category for a channel For guild channels: id of the parent category for a channel
(each parent category can contain up to 50 channels), (each parent category can contain up to 50 channels),
for threads: id of the text channel this thread was created 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. When the last pinned message was pinned.
This may be `null` in events such as `GUILD_CREATE` when a message is not pinned. This may be `null` in events such as `GUILD_CREATE` when a message is not pinned.
rtc_region: :class:`str` 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 only included when part of the `resolved` data received on a slash command interaction
""" """
id: APINullable[Snowflake] = UNDEFINED id: APINullable[Snowflake] = None
type: APINullable[int] = UNDEFINED type: APINullable[int] = None
guild_id: APINullable[Snowflake] = UNDEFINED guild_id: APINullable[Snowflake] = None
position: APINullable[int] = UNDEFINED position: APINullable[int] = None
permission_overwrites: APINullable[List] = UNDEFINED permission_overwrites: APINullable[List] = None
name: APINullable[str] = UNDEFINED name: APINullable[str] = None
topic: APINullable[str] = UNDEFINED topic: APINullable[str] = None
nsfw: APINullable[bool] = UNDEFINED nsfw: APINullable[bool] = None
last_message_id: APINullable[Snowflake] = UNDEFINED last_message_id: APINullable[Snowflake] = None
bitrate: APINullable[int] = UNDEFINED bitrate: APINullable[int] = None
user_limit: APINullable[int] = UNDEFINED user_limit: APINullable[int] = None
rate_limit_per_user: APINullable[int] = UNDEFINED rate_limit_per_user: APINullable[int] = None
recipients: APINullable[List] = UNDEFINED recipients: APINullable[List] = None
icon: APINullable[str] = UNDEFINED icon: APINullable[str] = None
owner_id: APINullable[Snowflake] = UNDEFINED owner_id: APINullable[Snowflake] = None
application_id: APINullable[Snowflake] = UNDEFINED application_id: APINullable[Snowflake] = None
parent_id: APINullable[Snowflake] = UNDEFINED parent_id: APINullable[Snowflake] = None
last_pin_timestamp: APINullable[Timestamp] = UNDEFINED last_pin_timestamp: APINullable[Timestamp] = None
rtc_region: APINullable[str] = UNDEFINED rtc_region: APINullable[str] = None
video_quality_mode: APINullable[int] = UNDEFINED video_quality_mode: APINullable[int] = None
message_count: APINullable[int] = UNDEFINED message_count: APINullable[int] = None
member_count: APINullable[int] = UNDEFINED member_count: APINullable[int] = None
thread_metadata: APINullable[ThreadMetadata] = UNDEFINED thread_metadata: APINullable[ThreadMetadata] = None
member: APINullable[List] = UNDEFINED member: APINullable[List] = None
default_auto_archive_duration: APINullable[int] = UNDEFINED default_auto_archive_duration: APINullable[int] = None
permissions: APINullable[str] = UNDEFINED permissions: APINullable[str] = None
@property @property
def mention(self): def mention(self):
@ -734,18 +734,22 @@ class TextChannel(MessageableChannel):
self.id = data["id"] self.id = data["id"]
self.type = data["type"] self.type = data["type"]
self.guild_id = Snowflake(data["guild_id"]) self.position = data.get("position")
self.position = data["position"]
self.permission_overwrites = data["permission_overwrites"] self.permission_overwrites = data["permission_overwrites"]
self.name = data["name"] self.name = data.get("name")
self.topic = data.get("topic") self.topic = data.get("topic")
self.nsfw = data["nsfw"] self.nsfw = data.get("nsfw")
if data.get("last_message_id") is not None: if data.get("last_message_id") is not None:
self.last_message_id = Snowflake(data["last_message_id"]) self.last_message_id = Snowflake(data["last_message_id"])
else: else:
self.last_message_id = None 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") self.rate_limit_per_user = data.get("rate_limit_per_user")
if data.get("parent_id") is not None: if data.get("parent_id") is not None:
@ -754,7 +758,7 @@ class TextChannel(MessageableChannel):
self.parent_id = None self.parent_id = None
if data.get("last_pin_timestamp") is not 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: else:
self.last_pin_timestamp = None self.last_pin_timestamp = None
@ -859,7 +863,7 @@ class Thread(MessageableChannel):
self.member_count = data.get("member_count") self.member_count = data.get("member_count")
if data.get("last_pin_timestamp") is not 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: else:
self.last_pin_timestamp = None self.last_pin_timestamp = None

View file

@ -240,9 +240,9 @@ class Guild(APIModelBase):
States of members currently in voice channels; lacks the `guild_id` key States of members currently in voice channels; lacks the `guild_id` key
members: APINullable[:class:`typing.Any`] members: APINullable[:class:`typing.Any`]
Users in the guild Users in the guild
channels: APINullable[:class:`typing.Any`] channels: APINullable[Dict[:class:`~melisa.models.guild.channel.Channel`]]
Channels in the guild 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 All active threads in the guild that current user has permission to view
presences: APINullable[:class:`typing.Any`] presences: APINullable[:class:`typing.Any`]
Presences of the members in the guild, will only include non-offline members 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 The scheduled events in the guild
""" """
id: APINullable[Snowflake] = UNDEFINED id: Snowflake
name: APINullable[str] = UNDEFINED roles: APINullable[List]
icon: APINullable[str] = UNDEFINED emojis: APINullable[List]
icon_hash: APINullable[str] = UNDEFINED members: APINullable[List]
splash: APINullable[str] = UNDEFINED threads: APINullable[Dict]
discovery_splash: APINullable[str] = UNDEFINED presences: APINullable[List]
owner: APINullable[bool] = UNDEFINED channels: APINullable[Dict]
owner_id: APINullable[Snowflake] = UNDEFINED name: APINullable[str] = None
permissions: APINullable[str] = UNDEFINED icon: APINullable[str] = None
region: APINullable[str] = UNDEFINED icon_hash: APINullable[str] = None
afk_channel_id: APINullable[Snowflake] = UNDEFINED splash: APINullable[str] = None
afk_timeout: APINullable[int] = UNDEFINED discovery_splash: APINullable[str] = None
widget_enabled: APINullable[bool] = UNDEFINED owner: APINullable[bool] = None
widget_channel_id: APINullable[Snowflake] = UNDEFINED owner_id: APINullable[Snowflake] = None
verification_level: APINullable[int] = UNDEFINED permissions: APINullable[str] = None
default_message_notifications: APINullable[int] = UNDEFINED region: APINullable[str] = None
explicit_content_filter: APINullable[int] = UNDEFINED afk_channel_id: APINullable[Snowflake] = None
features: APINullable[List[str]] = UNDEFINED afk_timeout: APINullable[int] = None
roles: APINullable[List] = UNDEFINED widget_enabled: APINullable[bool] = None
emojis: APINullable[List] = UNDEFINED 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 # TODO: Make a structures of emoji and role
mfa_level: APINullable[MFALevel] = UNDEFINED mfa_level: APINullable[MFALevel] = None
application_id: APINullable[Snowflake] = UNDEFINED application_id: APINullable[Snowflake] = None
system_channel_id: APINullable[Snowflake] = UNDEFINED system_channel_id: APINullable[Snowflake] = None
system_channel_flags: APINullable[SystemChannelFlags] = UNDEFINED system_channel_flags: APINullable[SystemChannelFlags] = None
rules_channel_id: APINullable[Snowflake] = UNDEFINED rules_channel_id: APINullable[Snowflake] = None
joined_at: APINullable[Timestamp] = UNDEFINED joined_at: APINullable[Timestamp] = None
large: APINullable[bool] = UNDEFINED large: APINullable[bool] = None
unavailable: APINullable[bool] = UNDEFINED unavailable: APINullable[bool] = None
member_count: APINullable[int] = UNDEFINED member_count: APINullable[int] = None
voice_states: APINullable[List] = UNDEFINED voice_states: APINullable[List] = None
members: APINullable[List] = UNDEFINED
threads: APINullable[List] = UNDEFINED
presences: APINullable[List] = UNDEFINED
channels: APINullable[List] = UNDEFINED
# TODO: Make a structure for voice_states, members, channels, threads, presences(?) # TODO: Make a structure for voice_states, members, channels, threads, presences(?)
max_presences: APINullable[int] = UNDEFINED max_presences: APINullable[int] = None
max_members: APINullable[int] = UNDEFINED max_members: APINullable[int] = None
vanity_url_code: APINullable[str] = UNDEFINED vanity_url_code: APINullable[str] = None
description: APINullable[str] = UNDEFINED description: APINullable[str] = None
banner: APINullable[str] = UNDEFINED banner: APINullable[str] = None
premium_tier: APINullable[str] = UNDEFINED premium_tier: APINullable[str] = None
premium_subscription_count: APINullable[int] = UNDEFINED premium_subscription_count: APINullable[int] = None
preferred_locale: APINullable[str] = UNDEFINED preferred_locale: APINullable[str] = None
public_updates_channel_id: APINullable[Snowflake] = UNDEFINED public_updates_channel_id: APINullable[Snowflake] = None
max_video_channel_users: APINullable[int] = UNDEFINED max_video_channel_users: APINullable[int] = None
approximate_member_count: APINullable[int] = UNDEFINED approximate_member_count: APINullable[int] = None
approximate_presence_count: APINullable[int] = UNDEFINED approximate_presence_count: APINullable[int] = None
nsfw_level: APINullable[int] = UNDEFINED nsfw_level: APINullable[int] = None
premium_progress_bar_enabled: APINullable[bool] = UNDEFINED premium_progress_bar_enabled: APINullable[bool] = None
stage_instances: APINullable[List] = UNDEFINED stage_instances: APINullable[List] = None
stickers: APINullable[List] = UNDEFINED stickers: APINullable[List] = None
welcome_screen: APINullable = UNDEFINED welcome_screen: APINullable = None
guild_scheduled_events: APINullable[List] = UNDEFINED guild_scheduled_events: APINullable[List] = None
# TODO: Make a structure for welcome_screen, stage_instances, # TODO: Make a structure for welcome_screen, stage_instances,
# stickers and guild_scheduled_events # stickers and guild_scheduled_events
@ -429,7 +429,7 @@ class Guild(APIModelBase):
self.afk_channel_id = None self.afk_channel_id = None
if data.get("joined_at") is not 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: else:
self.joined_at = None self.joined_at = None
@ -441,6 +441,9 @@ class Guild(APIModelBase):
self.members = data.get("members") self.members = data.get("members")
self.presences = data.get("presences") self.presences = data.get("presences")
self.threads = {}
self.channels = {}
for thread in data.get("threads", []): for thread in data.get("threads", []):
self.threads[thread["id"]] = Thread.from_dict(thread) self.threads[thread["id"]] = Thread.from_dict(thread)