message simple docs

This commit is contained in:
grey-cat-1908 2022-04-07 22:20:05 +03:00
parent b6aa4791ec
commit 8303342e30
12 changed files with 78 additions and 54 deletions

View file

@ -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
max-line-length = 101

View file

@ -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()

View file

@ -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

View file

@ -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)

View file

@ -260,4 +260,3 @@ class HTTPClient:
JSON response from the Discord API.
"""
return await self.__send("PUT", route, json=data, headers=headers)

View file

@ -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
@ -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.

View file

@ -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")
)

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -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
@ -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,

View file

@ -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]