Skip to content

Commit

Permalink
Merge branch 'master' into feat/ua
Browse files Browse the repository at this point in the history
Signed-off-by: plun1331 <plun1331@gmail.com>
  • Loading branch information
plun1331 committed Jun 25, 2024
2 parents ce59672 + 284d40c commit 61dc2cd
Show file tree
Hide file tree
Showing 25 changed files with 1,148 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Run tdg-github-action
uses: ribtoks/tdg-github-action@v0.4.10-beta
uses: ribtoks/tdg-github-action@v0.4.11-beta
with:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
# - --remove-duplicate-keys
# - --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2421](https://github.com/Pycord-Development/pycord/pull/2421))
- Added `member` data to the `raw_reaction_remove` event.
([#2412](https://github.com/Pycord-Development/pycord/pull/2412))
- Added `Poll` and all related features.
([#2408](https://github.com/Pycord-Development/pycord/pull/2408))
- Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`.
([#2450](https://github.com/Pycord-Development/pycord/pull/2450))
- Added support for user-installable applications.
Expand Down Expand Up @@ -56,6 +58,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2458](https://github.com/Pycord-Development/pycord/pull/2458))
- Fixed many inaccurate type hints throughout the library.
([#2457](https://github.com/Pycord-Development/pycord/pull/2457))
- Fixed `AttributeError` due to `discord.Option` being initialised with `input_type` set
to `None`. ([#2464](https://github.com/Pycord-Development/pycord/pull/2464))

### Changed

Expand Down
1 change: 1 addition & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from .partial_emoji import *
from .permissions import *
from .player import *
from .poll import *
from .raw_models import *
from .reaction import *
from .role import *
Expand Down
16 changes: 16 additions & 0 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
from .guild import Guild
from .member import Member
from .message import Message, MessageReference, PartialMessage
from .poll import Poll
from .state import ConnectionState
from .threads import Thread
from .types.channel import Channel as ChannelPayload
Expand Down Expand Up @@ -1351,6 +1352,7 @@ async def send(
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1371,6 +1373,7 @@ async def send(
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1391,6 +1394,7 @@ async def send(
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1411,6 +1415,7 @@ async def send(
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1432,6 +1437,7 @@ async def send(
reference=None,
mention_author=None,
view=None,
poll=None,
suppress=None,
silent=None,
):
Expand Down Expand Up @@ -1515,6 +1521,10 @@ async def send(
Whether to suppress push and desktop notifications for the message.
.. versionadded:: 2.4
poll: :class:`Poll`
The poll to send.
.. versionadded:: 2.6
Returns
-------
Expand Down Expand Up @@ -1594,6 +1604,9 @@ async def send(
else:
components = None

if poll:
poll = poll.to_dict()

if file is not None and files is not None:
raise InvalidArgument("cannot pass both file and files parameter to send()")

Expand All @@ -1616,6 +1629,7 @@ async def send(
stickers=stickers,
components=components,
flags=flags,
poll=poll,
)
finally:
file.close()
Expand Down Expand Up @@ -1643,6 +1657,7 @@ async def send(
stickers=stickers,
components=components,
flags=flags,
poll=poll,
)
finally:
for f in files:
Expand All @@ -1661,6 +1676,7 @@ async def send(
stickers=stickers,
components=components,
flags=flags,
poll=poll,
)

ret = state.create_message(channel=channel, data=data)
Expand Down
24 changes: 24 additions & 0 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from .channel import DMChannel
from .member import Member
from .message import Message
from .poll import Poll
from .voice_client import VoiceProtocol

__all__ = ("Client",)
Expand Down Expand Up @@ -338,6 +339,14 @@ def stickers(self) -> list[GuildSticker]:
"""
return self._connection.stickers

@property
def polls(self) -> list[Poll]:
"""The polls that the connected client has.
.. versionadded:: 2.6
"""
return self._connection.polls

@property
def cached_messages(self) -> Sequence[Message]:
"""Read-only list of messages the connected client has cached.
Expand Down Expand Up @@ -1010,6 +1019,21 @@ def get_sticker(self, id: int, /) -> GuildSticker | None:
"""
return self._connection.get_sticker(id)

def get_poll(self, id: int, /) -> Poll | None:
"""Returns a poll attached to the given message ID.
Parameters
----------
id: :class:`int`
The message ID of the poll to search for.
Returns
-------
Optional[:class:`.Poll`]
The poll or ``None`` if not found.
"""
return self._connection.get_poll(id)

def get_all_channels(self) -> Generator[GuildChannel, None, None]:
"""A generator that retrieves every :class:`.abc.GuildChannel` the client can 'access'.
Expand Down
3 changes: 3 additions & 0 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ def __init__(
"description_localizations", MISSING
)

if input_type is None:
raise TypeError("input_type cannot be NoneType.")

def to_dict(self) -> dict:
as_dict = {
"name": self.name,
Expand Down
8 changes: 7 additions & 1 deletion discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ class EntitlementOwnerType(Enum):
guild = 1
user = 2


class IntegrationType(Enum):
"""The application's integration type"""

Expand All @@ -1036,6 +1036,12 @@ class InteractionContextType(Enum):
bot_dm = 1
private_channel = 2


class PollLayoutType(Enum):
"""The poll's layout type."""

default = 1


T = TypeVar("T")

Expand Down
68 changes: 68 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ def messages(self):
- :class:`Message`
- :attr:`Client.cached_messages`
- :meth:`Client.get_message`
- :attr:`Client.polls`
- :meth:`Client.get_poll`
Note that due to an implicit relationship this also corresponds to the following events:
Expand Down Expand Up @@ -917,6 +919,8 @@ def guild_messages(self):
- :class:`Message`
- :attr:`Client.cached_messages` (only for guilds)
- :meth:`Client.get_message` (only for guilds)
- :attr:`Client.polls` (only for guilds)
- :meth:`Client.get_poll` (only for guilds)
Note that due to an implicit relationship this also corresponds to the following events:
Expand All @@ -931,6 +935,7 @@ def guild_messages(self):
- :attr:`Message.embeds`
- :attr:`Message.attachments`
- :attr:`Message.components`
- :attr:`Message.poll`
For more information go to the :ref:`message content intent documentation <need_message_content_intent>`.
"""
Expand All @@ -955,6 +960,8 @@ def dm_messages(self):
- :class:`Message`
- :attr:`Client.cached_messages` (only for DMs)
- :meth:`Client.get_message` (only for DMs)
- :attr:`Client.polls` (only for DMs)
- :meth:`Client.get_poll` (only for DMs)
Note that due to an implicit relationship this also corresponds to the following events:
Expand Down Expand Up @@ -1079,6 +1086,7 @@ def message_content(self):
- :attr:`Message.embeds`
- :attr:`Message.attachments`
- :attr:`Message.components`
- :attr:`Message.poll`
These attributes will still be available for messages received from interactions,
the bot's own messages, messages the bot was mentioned in, and DMs.
Expand Down Expand Up @@ -1137,6 +1145,66 @@ def auto_moderation_execution(self):
"""
return 1 << 21

@flag_value
def guild_polls(self):
""":class:`bool`: Whether poll-related events in guilds are enabled.
See also :attr:`dm_polls` for DMs or :attr:`polls` for both.
This corresponds to the following events:
- :func:`on_poll_vote_add` (only for guilds)
- :func:`on_poll_vote_remove` (only for guilds)
- :func:`on_raw_poll_vote_add` (only for guilds)
- :func:`on_raw_poll_vote_remove` (only for guilds)
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`PollAnswer.count` (only for guild polls)
- :attr:`PollResults.answer_counts` (only for guild polls)
"""
return 1 << 24

@flag_value
def dm_polls(self):
""":class:`bool`: Whether poll-related events in direct messages are enabled.
See also :attr:`guild_polls` for guilds or :attr:`polls` for both.
This corresponds to the following events:
- :func:`on_poll_vote_add` (only for DMs)
- :func:`on_poll_vote_remove` (only for DMs)
- :func:`on_raw_poll_vote_add` (only for DMs)
- :func:`on_raw_poll_vote_remove` (only for DMs)
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`PollAnswer.count` (only for DM polls)
- :attr:`PollResults.answer_counts` (only for DM polls)
"""
return 1 << 25

@alias_flag_value
def polls(self):
""":class:`bool`: Whether poll-related events in guilds and direct messages are enabled.
This is a shortcut to set or get both :attr:`guild_polls` and :attr:`dm_polls`.
This corresponds to the following events:
- :func:`on_poll_vote_add` (both guilds and DMs)
- :func:`on_poll_vote_remove` (both guilds and DMs)
- :func:`on_raw_poll_vote_add` (both guilds and DMs)
- :func:`on_raw_poll_vote_remove` (both guilds and DMs)
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`PollAnswer.count` (both guild and DM polls)
- :attr:`PollResults.answer_counts` (both guild and DM polls)
"""
return (1 << 24) | (1 << 25)


@fill_with_flags()
class MemberCacheFlags(BaseFlags):
Expand Down
Loading

0 comments on commit 61dc2cd

Please sign in to comment.