mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
message simple docs
This commit is contained in:
parent
b6aa4791ec
commit
8303342e30
12 changed files with 78 additions and 54 deletions
2
.flake8
2
.flake8
|
@ -2,4 +2,4 @@
|
||||||
ignore = D203, H501, F403, F401, C901, W503
|
ignore = D203, H501, F403, F401, C901, W503
|
||||||
exclude = .git, .idea, __pycache__, docs, build, dev, dist, venv, .history, .github, examples
|
exclude = .git, .idea, __pycache__, docs, build, dev, dist, venv, .history, .github, examples
|
||||||
max-complexity = 10
|
max-complexity = 10
|
||||||
max-line-length = 100
|
max-line-length = 101
|
29
docs/source/models/message.rst
Normal file
29
docs/source/models/message.rst
Normal 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()
|
|
@ -81,7 +81,9 @@ class Client:
|
||||||
self.intents = sum(intents)
|
self.intents = sum(intents)
|
||||||
|
|
||||||
if intents is None:
|
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
|
self._token = token
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Gateway:
|
||||||
|
|
||||||
async def connect(self) -> None:
|
async def connect(self) -> None:
|
||||||
self.ws = await self.__session.ws_connect(
|
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)
|
_logger.debug("(Shard %s) Starting...", self.shard_id)
|
||||||
|
|
||||||
|
|
|
@ -260,4 +260,3 @@ class HTTPClient:
|
||||||
JSON response from the Discord API.
|
JSON response from the Discord API.
|
||||||
"""
|
"""
|
||||||
return await self.__send("PUT", route, json=data, headers=headers)
|
return await self.__send("PUT", route, json=data, headers=headers)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,16 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import IntEnum
|
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 ..message.message import Message
|
||||||
from ...utils import Snowflake, Timestamp
|
from ...utils import Snowflake, Timestamp
|
||||||
|
@ -297,16 +306,16 @@ class MessageableChannel(Channel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = await self._http.post(
|
data = await self._http.post(
|
||||||
f"channels/{self.id}/threads",
|
f"channels/{self.id}/threads",
|
||||||
headers={"X-Audit-Log-Reason": reason},
|
headers={"X-Audit-Log-Reason": reason},
|
||||||
data={
|
data={
|
||||||
"name": name,
|
"name": name,
|
||||||
"auto_archive_duration": auto_archive_duration,
|
"auto_archive_duration": auto_archive_duration,
|
||||||
"type": type,
|
"type": type,
|
||||||
"invitable": invitable,
|
"invitable": invitable,
|
||||||
"rate_limit_per_user": rate_limit_per_user,
|
"rate_limit_per_user": rate_limit_per_user,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return Thread.from_dict(data)
|
return Thread.from_dict(data)
|
||||||
|
|
||||||
|
@ -563,7 +572,7 @@ class MessageableChannel(Channel):
|
||||||
private: bool = False,
|
private: bool = False,
|
||||||
joined: bool = False,
|
joined: bool = False,
|
||||||
before: Optional[Union[Snowflake, Timestamp]] = None,
|
before: Optional[Union[Snowflake, Timestamp]] = None,
|
||||||
limit: Optional[int] = 50
|
limit: Optional[int] = 50,
|
||||||
) -> ThreadsList:
|
) -> ThreadsList:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
@ -577,7 +586,8 @@ class MessageableChannel(Channel):
|
||||||
before: Optional[Union[:class:`~melisa.utils.Snowflake`, :class:`~melisa.utils.Timestamp`]]
|
before: Optional[Union[:class:`~melisa.utils.Snowflake`, :class:`~melisa.utils.Timestamp`]]
|
||||||
Retrieve archived channels before the given date or ID.
|
Retrieve archived channels before the given date or ID.
|
||||||
limit: Optional[:class:`int`]
|
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
|
Note, however, that this would make it a slow operation
|
||||||
private: :class:`bool`
|
private: :class:`bool`
|
||||||
Whether to retrieve private archived threads.
|
Whether to retrieve private archived threads.
|
||||||
|
@ -656,10 +666,7 @@ class TextChannel(MessageableChannel):
|
||||||
class Thread(MessageableChannel):
|
class Thread(MessageableChannel):
|
||||||
"""A subclass of ``Channel`` for threads with all the same attributes."""
|
"""A subclass of ``Channel`` for threads with all the same attributes."""
|
||||||
|
|
||||||
async def add_user(
|
async def add_user(self, user_id: Snowflake) -> None:
|
||||||
self,
|
|
||||||
user_id: Snowflake
|
|
||||||
) -> None:
|
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Adds a user to this thread.
|
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}")
|
await self._http.put(f"channels/{self.id}/thread-members/{user_id}")
|
||||||
|
|
||||||
async def remove_user(
|
async def remove_user(self, user_id: Snowflake) -> None:
|
||||||
self,
|
|
||||||
user_id: Snowflake
|
|
||||||
) -> None:
|
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Removes a user from this thread.
|
Removes a user from this thread.
|
||||||
|
|
|
@ -531,9 +531,7 @@ class Guild(APIModelBase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return ThreadsList.from_dict(
|
return ThreadsList.from_dict(
|
||||||
await self._http.get(
|
await self._http.get(f"/guilds/{self.id}/threads/active")
|
||||||
f"/guilds/{self.id}/threads/active"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ class ThreadMetadata(APIModelBase):
|
||||||
create_timestamp: Optional[:class:`~melisa.utils.timestamp.Timestamp`]
|
create_timestamp: Optional[:class:`~melisa.utils.timestamp.Timestamp`]
|
||||||
Timestamp when the thread was created; only populated for threads created after 2022-01-09
|
Timestamp when the thread was created; only populated for threads created after 2022-01-09
|
||||||
"""
|
"""
|
||||||
|
|
||||||
archived: bool
|
archived: bool
|
||||||
auto_archive_duration: int
|
auto_archive_duration: int
|
||||||
archive_timestamp: Timestamp
|
archive_timestamp: Timestamp
|
||||||
|
@ -58,8 +59,8 @@ class ThreadMember(APIModelBase):
|
||||||
flags: :class:`int`
|
flags: :class:`int`
|
||||||
Any user-thread settings, currently only used for notifications
|
Any user-thread settings, currently only used for notifications
|
||||||
"""
|
"""
|
||||||
|
|
||||||
join_timestamp: Timestamp
|
join_timestamp: Timestamp
|
||||||
flags: int
|
flags: int
|
||||||
id: APINullable[Snowflake] = None
|
id: APINullable[Snowflake] = None
|
||||||
user_id: APINullable[Snowflake] = None
|
user_id: APINullable[Snowflake] = None
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
# Copyright MelisaDev 2022 - Present
|
# Copyright MelisaDev 2022 - Present
|
||||||
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||||
|
|
||||||
from .message import (
|
from .message import MessageActivityType, MessageFlags, MessageType, Message
|
||||||
MessageActivityType, MessageFlags, MessageType, Message
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = ("MessageActivityType", "MessageFlags", "MessageType", "Message")
|
||||||
"MessageActivityType",
|
|
||||||
"MessageFlags",
|
|
||||||
"MessageType",
|
|
||||||
"Message"
|
|
||||||
)
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
class MessageType(IntEnum):
|
class MessageType(IntEnum):
|
||||||
"""Message Type
|
"""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
|
DEFAULT = 0
|
||||||
|
@ -150,7 +151,8 @@ class Message(APIModelBase):
|
||||||
application: :class:`typing.Any`
|
application: :class:`typing.Any`
|
||||||
Sent with Rich Presence-related chat embeds
|
Sent with Rich Presence-related chat embeds
|
||||||
application_id: :class:`~melisa.Snowflake`
|
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`
|
message_reference: :class:`typing.Any`
|
||||||
Data showing the source of a crosspost, channel follow add, pin, or reply message
|
Data showing the source of a crosspost, channel follow add, pin, or reply message
|
||||||
flags: :class:`int`
|
flags: :class:`int`
|
||||||
|
@ -160,7 +162,8 @@ class Message(APIModelBase):
|
||||||
thread: :class:`typing.Any`
|
thread: :class:`typing.Any`
|
||||||
The thread that was started from this message, includes thread member object
|
The thread that was started from this message, includes thread member object
|
||||||
components: :class:`typing.Any`
|
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`
|
sticker_items: :class:`typing.Any`
|
||||||
Sent if the message contains stickers
|
Sent if the message contains stickers
|
||||||
stickers: :class:`typing.Any`
|
stickers: :class:`typing.Any`
|
||||||
|
@ -197,4 +200,3 @@ class Message(APIModelBase):
|
||||||
components: APINullable[List] = None
|
components: APINullable[List] = None
|
||||||
sticker_items: APINullable[List] = None
|
sticker_items: APINullable[List] = None
|
||||||
stickers: APINullable[List] = None
|
stickers: APINullable[List] = None
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ from typing import (
|
||||||
Union,
|
Union,
|
||||||
Generic,
|
Generic,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Any, get_origin, Tuple, get_args,
|
Any,
|
||||||
|
get_origin,
|
||||||
|
Tuple,
|
||||||
|
get_args,
|
||||||
)
|
)
|
||||||
|
|
||||||
from typing_extensions import get_type_hints
|
from typing_extensions import get_type_hints
|
||||||
|
@ -87,7 +90,7 @@ class APIModelBase:
|
||||||
|
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
return (arg_type, )
|
return (arg_type,)
|
||||||
|
|
||||||
def __attr_convert(self, attr_value: Dict, attr_type: T) -> T:
|
def __attr_convert(self, attr_value: Dict, attr_type: T) -> T:
|
||||||
factory = attr_type
|
factory = attr_type
|
||||||
|
@ -126,9 +129,7 @@ class APIModelBase:
|
||||||
types = self.__get_types(attr_type)
|
types = self.__get_types(attr_type)
|
||||||
|
|
||||||
types = tuple(
|
types = tuple(
|
||||||
filter(
|
filter(lambda tpe: tpe is not None and tpe is not None, types)
|
||||||
lambda tpe: tpe is not None and tpe is not None, types
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not types:
|
if not types:
|
||||||
|
@ -191,9 +192,7 @@ class APIModelBase:
|
||||||
map(
|
map(
|
||||||
lambda key: (
|
lambda key: (
|
||||||
key,
|
key,
|
||||||
data[key].value
|
data[key].value if isinstance(data[key], Enum) else data[key],
|
||||||
if isinstance(data[key], Enum)
|
|
||||||
else data[key],
|
|
||||||
),
|
),
|
||||||
filter(
|
filter(
|
||||||
lambda object_argument: data.get(object_argument) is not None,
|
lambda object_argument: data.get(object_argument) is not None,
|
||||||
|
|
|
@ -21,10 +21,7 @@ class Singleton(type):
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
def __call__(cls, *args, **kwargs):
|
||||||
if cls not in cls._instances:
|
if cls not in cls._instances:
|
||||||
cls._instances[cls] = super(
|
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||||
Singleton,
|
|
||||||
cls
|
|
||||||
).__call__(*args, **kwargs)
|
|
||||||
return cls._instances[cls]
|
return cls._instances[cls]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue