From 8303342e30f6bee032c313e81014d701a6e8d464 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Thu, 7 Apr 2022 22:20:05 +0300 Subject: [PATCH] message simple docs --- .flake8 | 2 +- docs/source/models/message.rst | 29 +++++++++++++++++++ melisa/client.py | 4 ++- melisa/core/gateway.py | 2 +- melisa/core/http.py | 1 - melisa/models/guild/channel.py | 46 +++++++++++++++++-------------- melisa/models/guild/guild.py | 4 +-- melisa/models/guild/thread.py | 3 +- melisa/models/message/__init__.py | 11 ++------ melisa/models/message/message.py | 10 ++++--- melisa/utils/api_model.py | 15 +++++----- melisa/utils/types.py | 5 +--- 12 files changed, 78 insertions(+), 54 deletions(-) create mode 100644 docs/source/models/message.rst diff --git a/.flake8 b/.flake8 index 4f3f4e6..9f510d9 100644 --- a/.flake8 +++ b/.flake8 @@ -2,4 +2,4 @@ ignore = D203, H501, F403, F401, C901, W503 exclude = .git, .idea, __pycache__, docs, build, dev, dist, venv, .history, .github, examples max-complexity = 10 -max-line-length = 100 \ No newline at end of file +max-line-length = 101 \ No newline at end of file diff --git a/docs/source/models/message.rst b/docs/source/models/message.rst new file mode 100644 index 0000000..a42150c --- /dev/null +++ b/docs/source/models/message.rst @@ -0,0 +1,29 @@ +.. currentmodule:: melisa.models + +Melisa Models Message +=========================== + + +Message +-------- + +MessageType +~~~~~~~~~~~~~ + +.. autoclass:: MessageType() + +MessageActivityType +~~~~~~~~~~~~~~~~~~ + +.. autoclass:: MessageActivityType() + +MessageFlags +~~~~~~~~~~~~~~~~~~ + +.. autoclass:: MessageFlags() + +Message +~~~~~~ +.. attributetable:: Message + +.. autoclass:: Message() diff --git a/melisa/client.py b/melisa/client.py index a7f1910..7637b89 100644 --- a/melisa/client.py +++ b/melisa/client.py @@ -81,7 +81,9 @@ class Client: self.intents = sum(intents) if intents is None: - self.intents = Intents.all() - Intents.GUILD_PRESENCES - Intents.GUILD_MEMBERS + self.intents = ( + Intents.all() - Intents.GUILD_PRESENCES - Intents.GUILD_MEMBERS + ) self._token = token diff --git a/melisa/core/gateway.py b/melisa/core/gateway.py index d37ac98..aa7c152 100644 --- a/melisa/core/gateway.py +++ b/melisa/core/gateway.py @@ -91,7 +91,7 @@ class Gateway: async def connect(self) -> None: self.ws = await self.__session.ws_connect( - f"wss://gateway.discord.gg/?v=10&encoding=json&compress=zlib-stream" + "wss://gateway.discord.gg/?v=10&encoding=json&compress=zlib-stream" ) _logger.debug("(Shard %s) Starting...", self.shard_id) diff --git a/melisa/core/http.py b/melisa/core/http.py index 0932aa8..d189e96 100644 --- a/melisa/core/http.py +++ b/melisa/core/http.py @@ -260,4 +260,3 @@ class HTTPClient: JSON response from the Discord API. """ return await self.__send("PUT", route, json=data, headers=headers) - diff --git a/melisa/models/guild/channel.py b/melisa/models/guild/channel.py index fb5ea1a..6985026 100644 --- a/melisa/models/guild/channel.py +++ b/melisa/models/guild/channel.py @@ -6,7 +6,16 @@ from __future__ import annotations import asyncio from dataclasses import dataclass from enum import IntEnum -from typing import List, Any, Optional, AsyncIterator, Union, Dict, overload, TYPE_CHECKING +from typing import ( + List, + Any, + Optional, + AsyncIterator, + Union, + Dict, + overload, + TYPE_CHECKING, +) from ..message.message import Message from ...utils import Snowflake, Timestamp @@ -297,16 +306,16 @@ class MessageableChannel(Channel): """ data = await self._http.post( - f"channels/{self.id}/threads", - headers={"X-Audit-Log-Reason": reason}, - data={ - "name": name, - "auto_archive_duration": auto_archive_duration, - "type": type, - "invitable": invitable, - "rate_limit_per_user": rate_limit_per_user, - }, - ) + f"channels/{self.id}/threads", + headers={"X-Audit-Log-Reason": reason}, + data={ + "name": name, + "auto_archive_duration": auto_archive_duration, + "type": type, + "invitable": invitable, + "rate_limit_per_user": rate_limit_per_user, + }, + ) return Thread.from_dict(data) @@ -563,7 +572,7 @@ class MessageableChannel(Channel): private: bool = False, joined: bool = False, before: Optional[Union[Snowflake, Timestamp]] = None, - limit: Optional[int] = 50 + limit: Optional[int] = 50, ) -> ThreadsList: """|coro| @@ -577,7 +586,8 @@ class MessageableChannel(Channel): before: Optional[Union[:class:`~melisa.utils.Snowflake`, :class:`~melisa.utils.Timestamp`]] Retrieve archived channels before the given date or ID. limit: Optional[:class:`int`] - The number of threads to retrieve. If None, retrieves every archived thread in the channel. + The number of threads to retrieve. + If None, retrieves every archived thread in the channel. Note, however, that this would make it a slow operation private: :class:`bool` Whether to retrieve private archived threads. @@ -656,10 +666,7 @@ class TextChannel(MessageableChannel): class Thread(MessageableChannel): """A subclass of ``Channel`` for threads with all the same attributes.""" - async def add_user( - self, - user_id: Snowflake - ) -> None: + async def add_user(self, user_id: Snowflake) -> None: """|coro| Adds a user to this thread. @@ -683,10 +690,7 @@ class Thread(MessageableChannel): await self._http.put(f"channels/{self.id}/thread-members/{user_id}") - async def remove_user( - self, - user_id: Snowflake - ) -> None: + async def remove_user(self, user_id: Snowflake) -> None: """|coro| Removes a user from this thread. diff --git a/melisa/models/guild/guild.py b/melisa/models/guild/guild.py index 4963b1e..8717dfc 100644 --- a/melisa/models/guild/guild.py +++ b/melisa/models/guild/guild.py @@ -531,9 +531,7 @@ class Guild(APIModelBase): """ return ThreadsList.from_dict( - await self._http.get( - f"/guilds/{self.id}/threads/active" - ) + await self._http.get(f"/guilds/{self.id}/threads/active") ) diff --git a/melisa/models/guild/thread.py b/melisa/models/guild/thread.py index a0d08cc..2f04dba 100644 --- a/melisa/models/guild/thread.py +++ b/melisa/models/guild/thread.py @@ -35,6 +35,7 @@ class ThreadMetadata(APIModelBase): create_timestamp: Optional[:class:`~melisa.utils.timestamp.Timestamp`] Timestamp when the thread was created; only populated for threads created after 2022-01-09 """ + archived: bool auto_archive_duration: int archive_timestamp: Timestamp @@ -58,8 +59,8 @@ class ThreadMember(APIModelBase): flags: :class:`int` Any user-thread settings, currently only used for notifications """ + join_timestamp: Timestamp flags: int id: APINullable[Snowflake] = None user_id: APINullable[Snowflake] = None - diff --git a/melisa/models/message/__init__.py b/melisa/models/message/__init__.py index 29c3db0..77d95ac 100644 --- a/melisa/models/message/__init__.py +++ b/melisa/models/message/__init__.py @@ -1,13 +1,6 @@ # Copyright MelisaDev 2022 - Present # Full MIT License can be found in `LICENSE.txt` at the project root. -from .message import ( - MessageActivityType, MessageFlags, MessageType, Message -) +from .message import MessageActivityType, MessageFlags, MessageType, Message -__all__ = ( - "MessageActivityType", - "MessageFlags", - "MessageType", - "Message" -) +__all__ = ("MessageActivityType", "MessageFlags", "MessageType", "Message") diff --git a/melisa/models/message/message.py b/melisa/models/message/message.py index baa1de5..ba2d2b6 100644 --- a/melisa/models/message/message.py +++ b/melisa/models/message/message.py @@ -17,7 +17,8 @@ if TYPE_CHECKING: class MessageType(IntEnum): """Message Type - NOTE: Type `19` and `20` are only in API v8. In v6, they are still type `0`. Type `21` is only in API v9. + NOTE: Type `19` and `20` are only in API v8. + In v6, they are still type `0`. Type `21` is only in API v9. """ DEFAULT = 0 @@ -150,7 +151,8 @@ class Message(APIModelBase): application: :class:`typing.Any` Sent with Rich Presence-related chat embeds application_id: :class:`~melisa.Snowflake` - If the message is an Interaction or application-owned webhook, this is the id of the application + If the message is an Interaction or application-owned webhook, + this is the id of the application message_reference: :class:`typing.Any` Data showing the source of a crosspost, channel follow add, pin, or reply message flags: :class:`int` @@ -160,7 +162,8 @@ class Message(APIModelBase): thread: :class:`typing.Any` The thread that was started from this message, includes thread member object components: :class:`typing.Any` - Sent if the message contains components like buttons, action rows, or other interactive components + Sent if the message contains components like buttons, + action rows, or other interactive components sticker_items: :class:`typing.Any` Sent if the message contains stickers stickers: :class:`typing.Any` @@ -197,4 +200,3 @@ class Message(APIModelBase): components: APINullable[List] = None sticker_items: APINullable[List] = None stickers: APINullable[List] = None - diff --git a/melisa/utils/api_model.py b/melisa/utils/api_model.py index ec0e59b..8e75c60 100644 --- a/melisa/utils/api_model.py +++ b/melisa/utils/api_model.py @@ -16,7 +16,10 @@ from typing import ( Union, Generic, TypeVar, - Any, get_origin, Tuple, get_args, + Any, + get_origin, + Tuple, + get_args, ) from typing_extensions import get_type_hints @@ -87,7 +90,7 @@ class APIModelBase: raise TypeError - return (arg_type, ) + return (arg_type,) def __attr_convert(self, attr_value: Dict, attr_type: T) -> T: factory = attr_type @@ -126,9 +129,7 @@ class APIModelBase: types = self.__get_types(attr_type) types = tuple( - filter( - lambda tpe: tpe is not None and tpe is not None, types - ) + filter(lambda tpe: tpe is not None and tpe is not None, types) ) if not types: @@ -191,9 +192,7 @@ class APIModelBase: map( lambda key: ( key, - data[key].value - if isinstance(data[key], Enum) - else data[key], + data[key].value if isinstance(data[key], Enum) else data[key], ), filter( lambda object_argument: data.get(object_argument) is not None, diff --git a/melisa/utils/types.py b/melisa/utils/types.py index fc26904..2095396 100644 --- a/melisa/utils/types.py +++ b/melisa/utils/types.py @@ -21,10 +21,7 @@ class Singleton(type): def __call__(cls, *args, **kwargs): if cls not in cls._instances: - cls._instances[cls] = super( - Singleton, - cls - ).__call__(*args, **kwargs) + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls]