Skip to content

Commit

Permalink
Merge branch 'master' into feat/poll_msg
Browse files Browse the repository at this point in the history
Signed-off-by: Snipy7374 <[email protected]>
  • Loading branch information
Snipy7374 authored Sep 2, 2024
2 parents ba5b685 + 2206241 commit 7ae5ada
Show file tree
Hide file tree
Showing 39 changed files with 1,348 additions and 134 deletions.
1 change: 1 addition & 0 deletions changelog/1012.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`Interaction`\s now always have a proper :attr:`~Interaction.channel` attribute, even when the bot is not part of the guild or cannot access the channel due to other reasons.
1 change: 1 addition & 0 deletions changelog/1160.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:attr:`InteractionReference.user` can now be a :class:`Member` in guild contexts.
6 changes: 6 additions & 0 deletions changelog/1175.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Add the new poll discord API feature. This includes the following new classes and events:

- New types: :class:`Poll`, :class:`PollAnswer`, :class:`PollMedia`, :class:`RawMessagePollVoteActionEvent` and :class:`PollLayoutType`.
- Edited :meth:`abc.Messageable.send`, :meth:`Webhook.send`, :meth:`ext.commands.Context.send` and :meth:`disnake.InteractionResponse.send_message` to be able to send polls.
- Edited :class:`Message` to store a new :attr:`Message.poll` attribute for polls.
- Edited :class:`Event` to contain the new :func:`on_message_poll_vote_add`, :func:`on_message_poll_vote_remove`, :func:`on_raw_message_poll_vote_add` and :func:`on_raw_message_poll_vote_remove`.
1 change: 1 addition & 0 deletions changelog/1180.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding some clarifying documentation around the type of :attr:`AuditLogEntry.extra` when the action is :attr:`~AuditLogAction.overwrite_create`.
1 change: 1 addition & 0 deletions changelog/1218.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new :attr:`Attachment.title` attribute.
1 change: 1 addition & 0 deletions changelog/1220.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :attr:`AppInfo.approximate_guild_count` and :attr:`AppInfo.approximate_user_install_count`.
1 change: 1 addition & 0 deletions changelog/1221.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new :meth:`.Client.fetch_sticker_pack` method.
1 change: 1 addition & 0 deletions disnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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
21 changes: 20 additions & 1 deletion disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .iterators import HistoryIterator
from .member import Member
from .message import Message, MessageReference, PartialMessage
from .poll import Poll
from .state import ConnectionState
from .threads import AnyThreadArchiveDuration, ForumTag
from .types.channel import (
Expand Down Expand Up @@ -640,6 +641,7 @@ def _apply_implict_permissions(self, base: Permissions) -> None:
if not base.send_messages:
base.send_tts_messages = False
base.send_voice_messages = False
base.send_polls = False
base.mention_everyone = False
base.embed_links = False
base.attach_files = False
Expand Down Expand Up @@ -887,6 +889,7 @@ async def set_permissions(
request_to_speak: Optional[bool] = ...,
send_messages: Optional[bool] = ...,
send_messages_in_threads: Optional[bool] = ...,
send_polls: Optional[bool] = ...,
send_tts_messages: Optional[bool] = ...,
send_voice_messages: Optional[bool] = ...,
speak: Optional[bool] = ...,
Expand Down Expand Up @@ -1435,6 +1438,7 @@ async def send(
mention_author: bool = ...,
view: View = ...,
components: Components[MessageUIComponent] = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1456,6 +1460,7 @@ async def send(
mention_author: bool = ...,
view: View = ...,
components: Components[MessageUIComponent] = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1477,6 +1482,7 @@ async def send(
mention_author: bool = ...,
view: View = ...,
components: Components[MessageUIComponent] = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1498,6 +1504,7 @@ async def send(
mention_author: bool = ...,
view: View = ...,
components: Components[MessageUIComponent] = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1520,6 +1527,7 @@ async def send(
mention_author: Optional[bool] = None,
view: Optional[View] = None,
components: Optional[Components[MessageUIComponent]] = None,
poll: Optional[Poll] = None,
):
"""|coro|
Expand All @@ -1528,7 +1536,7 @@ async def send(
The content must be a type that can convert to a string through ``str(content)``.
At least one of ``content``, ``embed``/``embeds``, ``file``/``files``,
``stickers``, ``components``, or ``view`` must be provided.
``stickers``, ``components``, ``poll`` or ``view`` must be provided.
To upload a single file, the ``file`` parameter should be used with a
single :class:`.File` object. To upload multiple files, the ``files``
Expand Down Expand Up @@ -1624,6 +1632,11 @@ async def send(
.. versionadded:: 2.9
poll: :class:`.Poll`
The poll to send with the message.
.. versionadded:: 2.10
Raises
------
HTTPException
Expand Down Expand Up @@ -1676,6 +1689,10 @@ async def send(
if stickers is not None:
stickers_payload = [sticker.id for sticker in stickers]

poll_payload = None
if poll:
poll_payload = poll._to_dict()

allowed_mentions_payload = None
if allowed_mentions is None:
allowed_mentions_payload = state.allowed_mentions and state.allowed_mentions.to_dict()
Expand Down Expand Up @@ -1737,6 +1754,7 @@ async def send(
message_reference=reference_payload,
stickers=stickers_payload,
components=components_payload,
poll=poll_payload,
flags=flags_payload,
)
finally:
Expand All @@ -1753,6 +1771,7 @@ async def send(
message_reference=reference_payload,
stickers=stickers_payload,
components=components_payload,
poll=poll_payload,
flags=flags_payload,
)

Expand Down
19 changes: 15 additions & 4 deletions disnake/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class AppInfo:
.. versionadded:: 1.3
guild_id: Optional[:class:`int`]
If this application is a game sold on Discord,
this field will be the guild to which it has been linked to.
The ID of the guild associated with the application, if any.
.. versionadded:: 1.3
Expand Down Expand Up @@ -151,6 +150,15 @@ class AppInfo:
in the guild role verification configuration.
.. versionadded:: 2.8
approximate_guild_count: :class:`int`
The approximate number of guilds the application is installed to.
.. versionadded:: 2.10
approximate_user_install_count: :class:`int`
The approximate number of users that have installed the application
(for user-installable apps).
.. versionadded:: 2.10
"""

__slots__ = (
Expand All @@ -177,6 +185,8 @@ class AppInfo:
"install_params",
"custom_install_url",
"role_connections_verification_url",
"approximate_guild_count",
"approximate_user_install_count",
)

def __init__(self, state: ConnectionState, data: AppInfoPayload) -> None:
Expand Down Expand Up @@ -218,6 +228,8 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload) -> None:
self.role_connections_verification_url: Optional[str] = data.get(
"role_connections_verification_url"
)
self.approximate_guild_count: int = data.get("approximate_guild_count", 0)
self.approximate_user_install_count: int = data.get("approximate_user_install_count", 0)

def __repr__(self) -> str:
return (
Expand Down Expand Up @@ -245,8 +257,7 @@ def cover_image(self) -> Optional[Asset]:

@property
def guild(self) -> Optional[Guild]:
"""Optional[:class:`Guild`]: If this application is a game sold on Discord,
this field will be the guild to which it has been linked
"""Optional[:class:`Guild`]: The guild associated with the application, if any.
.. versionadded:: 1.3
"""
Expand Down
27 changes: 27 additions & 0 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,33 @@ async def fetch_sticker(self, sticker_id: int, /) -> Union[StandardSticker, Guil
cls, _ = _sticker_factory(data["type"]) # type: ignore
return cls(state=self._connection, data=data) # type: ignore

async def fetch_sticker_pack(self, pack_id: int, /) -> StickerPack:
"""|coro|
Retrieves a :class:`.StickerPack` with the given ID.
.. versionadded:: 2.10
Parameters
----------
pack_id: :class:`int`
The ID of the sticker pack to retrieve.
Raises
------
HTTPException
Retrieving the sticker pack failed.
NotFound
Invalid sticker pack ID.
Returns
-------
:class:`.StickerPack`
The sticker pack you requested.
"""
data = await self.http.get_sticker_pack(pack_id)
return StickerPack(state=self._connection, data=data)

async def fetch_sticker_packs(self) -> List[StickerPack]:
"""|coro|
Expand Down
21 changes: 21 additions & 0 deletions disnake/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"OnboardingPromptType",
"SKUType",
"EntitlementType",
"PollLayoutType",
)


Expand Down Expand Up @@ -1216,6 +1217,14 @@ class Event(Enum):
"""Called when messages are bulk deleted.
Represents the :func:`on_bulk_message_delete` event.
"""
poll_vote_add = "poll_vote_add"
"""Called when a vote is added on a `Poll`.
Represents the :func:`on_poll_vote_add` event.
"""
poll_vote_remove = "poll_vote_remove"
"""Called when a vote is removed from a `Poll`.
Represents the :func:`on_poll_vote_remove` event.
"""
raw_message_edit = "raw_message_edit"
"""Called when a message is edited regardless of the state of the internal message cache.
Represents the :func:`on_raw_message_edit` event.
Expand All @@ -1228,6 +1237,14 @@ class Event(Enum):
"""Called when a bulk delete is triggered regardless of the messages being in the internal message cache or not.
Represents the :func:`on_raw_bulk_message_delete` event.
"""
raw_poll_vote_add = "raw_poll_vote_add"
"""Called when a vote is added on a `Poll` regardless of the internal message cache.
Represents the :func:`on_raw_poll_vote_add` event.
"""
raw_poll_vote_remove = "raw_poll_vote_remove"
"""Called when a vote is removed from a `Poll` regardless of the internal message cache.
Represents the :func:`on_raw_poll_vote_remove` event.
"""
reaction_add = "reaction_add"
"""Called when a message has a reaction added to it.
Represents the :func:`on_reaction_add` event.
Expand Down Expand Up @@ -1365,6 +1382,10 @@ class EntitlementType(Enum):
application_subscription = 8


class PollLayoutType(Enum):
default = 1


T = TypeVar("T")


Expand Down
1 change: 1 addition & 0 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ def default_member_permissions(
request_to_speak: bool = ...,
send_messages: bool = ...,
send_messages_in_threads: bool = ...,
send_polls: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
speak: bool = ...,
Expand Down
27 changes: 15 additions & 12 deletions disnake/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from disnake.interactions import ApplicationCommandInteraction

from ._types import MaybeCoro
from .bot import AutoShardedBot, AutoShardedInteractionBot, Bot, InteractionBot
from .context import Context
from .core import Command
Expand Down Expand Up @@ -491,7 +492,7 @@ def cog_unload(self) -> None:
pass

@_cog_special_method
def bot_check_once(self, ctx: Context) -> bool:
def bot_check_once(self, ctx: Context) -> MaybeCoro[bool]:
"""A special method that registers as a :meth:`.Bot.check_once`
check.
Expand All @@ -503,7 +504,7 @@ def bot_check_once(self, ctx: Context) -> bool:
return True

@_cog_special_method
def bot_check(self, ctx: Context) -> bool:
def bot_check(self, ctx: Context) -> MaybeCoro[bool]:
"""A special method that registers as a :meth:`.Bot.check`
check.
Expand All @@ -515,7 +516,7 @@ def bot_check(self, ctx: Context) -> bool:
return True

@_cog_special_method
def bot_slash_command_check_once(self, inter: ApplicationCommandInteraction) -> bool:
def bot_slash_command_check_once(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""A special method that registers as a :meth:`.Bot.slash_command_check_once`
check.
Expand All @@ -525,7 +526,7 @@ def bot_slash_command_check_once(self, inter: ApplicationCommandInteraction) ->
return True

@_cog_special_method
def bot_slash_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def bot_slash_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""A special method that registers as a :meth:`.Bot.slash_command_check`
check.
Expand All @@ -535,27 +536,29 @@ def bot_slash_command_check(self, inter: ApplicationCommandInteraction) -> bool:
return True

@_cog_special_method
def bot_user_command_check_once(self, inter: ApplicationCommandInteraction) -> bool:
def bot_user_command_check_once(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""Similar to :meth:`.Bot.slash_command_check_once` but for user commands."""
return True

@_cog_special_method
def bot_user_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def bot_user_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""Similar to :meth:`.Bot.slash_command_check` but for user commands."""
return True

@_cog_special_method
def bot_message_command_check_once(self, inter: ApplicationCommandInteraction) -> bool:
def bot_message_command_check_once(
self, inter: ApplicationCommandInteraction
) -> MaybeCoro[bool]:
"""Similar to :meth:`.Bot.slash_command_check_once` but for message commands."""
return True

@_cog_special_method
def bot_message_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def bot_message_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""Similar to :meth:`.Bot.slash_command_check` but for message commands."""
return True

@_cog_special_method
def cog_check(self, ctx: Context) -> bool:
def cog_check(self, ctx: Context) -> MaybeCoro[bool]:
"""A special method that registers as a :func:`~.check`
for every text command and subcommand in this cog.
Expand All @@ -567,7 +570,7 @@ def cog_check(self, ctx: Context) -> bool:
return True

@_cog_special_method
def cog_slash_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def cog_slash_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""A special method that registers as a :func:`~.check`
for every slash command and subcommand in this cog.
Expand All @@ -577,12 +580,12 @@ def cog_slash_command_check(self, inter: ApplicationCommandInteraction) -> bool:
return True

@_cog_special_method
def cog_user_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def cog_user_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""Similar to :meth:`.Cog.cog_slash_command_check` but for user commands."""
return True

@_cog_special_method
def cog_message_command_check(self, inter: ApplicationCommandInteraction) -> bool:
def cog_message_command_check(self, inter: ApplicationCommandInteraction) -> MaybeCoro[bool]:
"""Similar to :meth:`.Cog.cog_slash_command_check` but for message commands."""
return True

Expand Down
Loading

0 comments on commit 7ae5ada

Please sign in to comment.