mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
Use message model in some methods
This commit is contained in:
parent
35ebe54e88
commit
b6aa4791ec
3 changed files with 58 additions and 20 deletions
|
@ -6,12 +6,15 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
from typing import List, Any, Optional, AsyncIterator, Union, Dict, overload
|
||||
from typing import List, Any, Optional, AsyncIterator, Union, Dict, overload, TYPE_CHECKING
|
||||
|
||||
from ..message.message import Message
|
||||
from ...utils import Snowflake, Timestamp
|
||||
from ...utils import APIModelBase
|
||||
from ...utils.types import APINullable
|
||||
from .thread import ThreadMember, ThreadMetadata
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .thread import ThreadMember, ThreadMetadata
|
||||
|
||||
|
||||
class ChannelType(IntEnum):
|
||||
|
@ -165,7 +168,7 @@ class Channel(APIModelBase):
|
|||
owner_id: APINullable[Snowflake] = None
|
||||
application_id: APINullable[Snowflake] = None
|
||||
parent_id: APINullable[Snowflake] = None
|
||||
last_pin_timestamp: APINullable[int] = None
|
||||
last_pin_timestamp: APINullable[Timestamp] = None
|
||||
rtc_region: APINullable[str] = None
|
||||
video_quality_mode: APINullable[int] = None
|
||||
message_count: APINullable[int] = None
|
||||
|
@ -314,14 +317,15 @@ class MessageableChannel(Channel):
|
|||
before: Optional[Snowflake] = None,
|
||||
after: Optional[Snowflake] = None,
|
||||
around: Optional[Snowflake] = None,
|
||||
) -> AsyncIterator[Dict[str, Any]]:
|
||||
) -> AsyncIterator[Message]:
|
||||
"""|coro|
|
||||
|
||||
Returns a list of messages in this channel.
|
||||
|
||||
Examples
|
||||
---------
|
||||
Flattening messages into a list: ::
|
||||
Flattening messages into a list:
|
||||
.. code-block:: python
|
||||
messages = [message async for message in channel.history(limit=111)]
|
||||
|
||||
All parameters are optional.
|
||||
|
@ -346,7 +350,7 @@ class MessageableChannel(Channel):
|
|||
|
||||
Returns
|
||||
-------
|
||||
AsyncIterator[Dict[:class:`str`, Any]]
|
||||
AsyncIterator[:class:`~melisa.Message`]
|
||||
An iterator of messages.
|
||||
"""
|
||||
|
||||
|
@ -372,7 +376,7 @@ class MessageableChannel(Channel):
|
|||
break
|
||||
|
||||
for message_data in raw_messages:
|
||||
yield message_data
|
||||
yield Message.from_dict(message_data)
|
||||
|
||||
before = raw_messages[-1]["id"]
|
||||
limit -= search_limit
|
||||
|
@ -380,7 +384,7 @@ class MessageableChannel(Channel):
|
|||
async def fetch_message(
|
||||
self,
|
||||
message_id: Optional[Snowflake, int, str],
|
||||
) -> Dict[str, Any]:
|
||||
) -> Message:
|
||||
"""|coro|
|
||||
|
||||
Returns a specific message in the channel.
|
||||
|
@ -399,7 +403,7 @@ class MessageableChannel(Channel):
|
|||
|
||||
Returns
|
||||
-------
|
||||
Dict[:class:`str`, Any]
|
||||
:class:`~melisa.Message`
|
||||
Message object.
|
||||
"""
|
||||
|
||||
|
@ -407,7 +411,30 @@ class MessageableChannel(Channel):
|
|||
f"/channels/{self.id}/messages/{message_id}",
|
||||
)
|
||||
|
||||
return message
|
||||
return Message.from_dict(message)
|
||||
|
||||
async def pins(self) -> AsyncIterator[Message]:
|
||||
"""|coro|
|
||||
|
||||
Retrieves all messages that are currently pinned in the channel.
|
||||
|
||||
Raises
|
||||
-------
|
||||
HTTPException
|
||||
The request to perform the action failed with other http exception.
|
||||
|
||||
Returns
|
||||
-------
|
||||
AsyncIterator[:class:`~melisa.Message`]
|
||||
AsyncIterator of Message objects.
|
||||
"""
|
||||
|
||||
messages = await self._http.get(
|
||||
f"/channels/{self.id}/pins",
|
||||
)
|
||||
|
||||
for message in messages:
|
||||
yield Message.from_dict(message)
|
||||
|
||||
async def bulk_delete_messages(
|
||||
self, messages: List[Snowflake], *, reason: Optional[str] = None
|
||||
|
@ -719,9 +746,9 @@ class ThreadsList(APIModelBase):
|
|||
|
||||
Attributes
|
||||
----------
|
||||
threads: List[:class:`~melisa.models.guild.channel.Thread`]
|
||||
threads: List[:class:`~melisa.Thread`]
|
||||
Async iterator of threads. To get their type use them `.type` attribute.
|
||||
members: List[:class:`Any`]
|
||||
members: List[:class:`~melisa.ThreadMember`]
|
||||
Async iterator of thread members.
|
||||
has_more: Optional[:class:`bool`]
|
||||
Whether there are potentially additional threads that could be returned on a subsequent cal
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
# Copyright MelisaDev 2022 - Present
|
||||
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||
|
||||
from .message import *
|
||||
from .message import (
|
||||
MessageActivityType, MessageFlags, MessageType, Message
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
"MessageActivityType",
|
||||
"MessageFlags",
|
||||
"MessageType",
|
||||
"Message"
|
||||
)
|
||||
|
|
|
@ -5,16 +5,18 @@ from __future__ import annotations
|
|||
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
from typing import List, Any, Optional
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
from ... import Thread
|
||||
from ...utils import Snowflake, Timestamp
|
||||
from ...utils import APIModelBase
|
||||
from ...utils.types import APINullable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..guild.channel import Thread
|
||||
|
||||
class MessageTypes(IntEnum):
|
||||
"""Message Types
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
|
@ -46,8 +48,8 @@ class MessageTypes(IntEnum):
|
|||
return self.value
|
||||
|
||||
|
||||
class MessageActivityTypes(IntEnum):
|
||||
"""Message Activity Types"""
|
||||
class MessageActivityType(IntEnum):
|
||||
"""Message Activity Type"""
|
||||
|
||||
JOIN = 1
|
||||
SPECTATE = 2
|
||||
|
@ -191,7 +193,7 @@ class Message(APIModelBase):
|
|||
message_reference: APINullable[List] = None
|
||||
flags: APINullable[int] = None
|
||||
interaction: APINullable[List] = None
|
||||
thread: APINullable[List[Thread]] = None
|
||||
thread: APINullable[Thread] = None
|
||||
components: APINullable[List] = None
|
||||
sticker_items: APINullable[List] = None
|
||||
stickers: APINullable[List] = None
|
||||
|
|
Loading…
Reference in a new issue