Skip to content

Commit

Permalink
Merge branch 'Pycord-Development:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
plun1331 authored Jun 26, 2024
2 parents b0c815f + a4b44ca commit 5706da0
Show file tree
Hide file tree
Showing 56 changed files with 2,011 additions and 210 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# Python 3.8/3.9 are on macos-13 but not macos-latest (macos-14-arm64)
# https://github.com/actions/setup-python/issues/696#issuecomment-1637587760
exclude:
- { python-version: "3.8", os: "macos-latest" }
- { python-version: "3.9", os: "macos-latest" }
include:
- { python-version: "3.8", os: "macos-13" }
- { python-version: "3.9", os: "macos-13" }

env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
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/[email protected].10-beta
uses: ribtoks/[email protected].11-beta
with:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
Expand Down
4 changes: 2 additions & 2 deletions .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 All @@ -28,7 +28,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ These changes are available on the `master` branch, but have not yet been releas
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
- Added `Guild.search_members`.
([#2418](https://github.com/Pycord-Development/pycord/pull/2418))
- Added bulk banning up to 200 users through `Guild.bulk_ban`.
([#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.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)

### Fixed

Expand All @@ -42,6 +50,16 @@ These changes are available on the `master` branch, but have not yet been releas
([#2411](https://github.com/Pycord-Development/pycord/pull/2411))
- Fixed option typehints being ignored when using `parameter_name`.
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
- Fixed parameter `embed=None` causing `AttributeError` on `PartialMessage.edit`.
([#2446](https://github.com/Pycord-Development/pycord/pull/2446))
- Fixed paginator to revert state if a page update callback fails.
([#2448](https://github.com/Pycord-Development/pycord/pull/2448))
- Fixed missing `application_id` in `Entitlement.delete`.
([#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 All @@ -55,6 +73,17 @@ These changes are available on the `master` branch, but have not yet been releas
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
- `Guild.query_members` now accepts `limit=None` to retrieve all members.
([#2419](https://github.com/Pycord-Development/pycord/pull/2419))
- `ApplicationCommand.guild_only` is now deprecated in favor of
`ApplicationCommand.contexts`.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409))
- `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`.
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)

### Removed

- Removed the `delete_message_days` parameter from ban methods. Please use
`delete_message_seconds` instead.
([#2421](https://github.com/Pycord-Development/pycord/pull/2421))

## [2.5.0] - 2024-03-02

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
28 changes: 22 additions & 6 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 All @@ -115,7 +116,7 @@ async def _single_delete_strategy(


async def _purge_messages_helper(
channel: TextChannel | Thread | VoiceChannel,
channel: TextChannel | StageChannel | Thread | VoiceChannel,
*,
limit: int | None = 100,
check: Callable[[Message], bool] = MISSING,
Expand Down Expand Up @@ -1345,12 +1346,13 @@ async def send(
file: File = ...,
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
nonce: int | str = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1365,12 +1367,13 @@ async def send(
files: list[File] = ...,
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
nonce: int | str = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1385,12 +1388,13 @@ async def send(
file: File = ...,
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
nonce: int | str = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
view: View = ...,
poll: Poll = ...,
suppress: bool = ...,
silent: bool = ...,
) -> Message: ...
Expand All @@ -1405,12 +1409,13 @@ async def send(
files: list[File] = ...,
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
nonce: int | str = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
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 @@ -1465,7 +1471,7 @@ async def send(
The file to upload.
files: List[:class:`~discord.File`]
A list of files to upload. Must be a maximum of 10.
nonce: :class:`int`
nonce: Union[:class:`str`, :class:`int`]
The nonce to use for sending this message. If the message was successfully sent,
then the message will have a nonce with this value.
enforce_nonce: Optional[:class:`bool`]
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
10 changes: 5 additions & 5 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ def _transform_type(

def _transform_actions(
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
) -> AutoModAction | None:
) -> list[AutoModAction] | None:
if data is None:
return None
else:
return [AutoModAction.from_dict(d) for d in data]


def _transform_trigger_metadata(
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
) -> AutoModAction | None:
entry: AuditLogEntry, data: AutoModTriggerMetadataPayload | None
) -> AutoModTriggerMetadata | None:
if data is None:
return None
else:
Expand Down Expand Up @@ -309,7 +309,7 @@ def __init__(
"$add_allow_list",
]:
self._handle_trigger_metadata(
self.before, self.after, entry, elem["new_value"], attr
self.before, self.after, entry, elem["new_value"], attr # type: ignore
)
continue
elif attr in [
Expand All @@ -318,7 +318,7 @@ def __init__(
"$remove_allow_list",
]:
self._handle_trigger_metadata(
self.after, self.before, entry, elem["new_value"], attr
self.after, self.before, entry, elem["new_value"], attr # type: ignore
)
continue

Expand Down
52 changes: 50 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
UserCommand,
command,
)
from .enums import InteractionType
from .enums import IntegrationType, InteractionContextType, InteractionType
from .errors import CheckFailure, DiscordException
from .interactions import Interaction
from .shard import AutoShardedClient
Expand Down Expand Up @@ -125,6 +125,13 @@ def add_application_command(self, command: ApplicationCommand) -> None:

if self._bot.debug_guilds and command.guild_ids is None:
command.guild_ids = self._bot.debug_guilds
if self._bot.default_command_contexts and command.contexts is None:
command.contexts = self._bot.default_command_contexts
if (
self._bot.default_command_integration_types
and command.integration_types is None
):
command.integration_types = self._bot.default_command_integration_types

for cmd in self.pending_application_commands:
if cmd == command:
Expand Down Expand Up @@ -271,7 +278,6 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
else:
as_dict = cmd.to_dict()
to_check = {
"dm_permission": None,
"nsfw": None,
"default_member_permissions": None,
"name": None,
Expand All @@ -287,6 +293,8 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
"name_localizations",
"description_localizations",
],
"contexts": None,
"integration_types": None,
}
for check, value in to_check.items():
if type(to_check[check]) == list:
Expand Down Expand Up @@ -1157,6 +1165,21 @@ def __init__(self, description=None, *args, **options):
self.auto_sync_commands = options.get("auto_sync_commands", True)

self.debug_guilds = options.pop("debug_guilds", None)
self.default_command_contexts = options.pop(
"default_command_contexts",
{
InteractionContextType.guild,
InteractionContextType.bot_dm,
InteractionContextType.private_channel,
},
)

self.default_command_integration_types = options.pop(
"default_command_integration_types",
{
IntegrationType.guild_install,
},
)

if self.owner_id and self.owner_ids:
raise TypeError("Both owner_id and owner_ids are set.")
Expand All @@ -1167,6 +1190,20 @@ def __init__(self, description=None, *args, **options):
raise TypeError(
f"owner_ids must be a collection not {self.owner_ids.__class__!r}"
)
if not isinstance(self.default_command_contexts, collections.abc.Collection):
raise TypeError(
f"default_command_contexts must be a collection not {self.default_command_contexts.__class__!r}"
)
if not isinstance(
self.default_command_integration_types, collections.abc.Collection
):
raise TypeError(
f"default_command_integration_types must be a collection not {self.default_command_integration_types.__class__!r}"
)
self.default_command_contexts = set(self.default_command_contexts)
self.default_command_integration_types = set(
self.default_command_integration_types
)

self._checks = []
self._check_once = []
Expand Down Expand Up @@ -1447,6 +1484,17 @@ class Bot(BotBase, Client):
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
.. versionadded:: 2.0
default_command_contexts: Collection[:class:`InteractionContextType`]
The default context types that the bot will use for commands.
Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
:attr:`InteractionContextType.private_channel`.
.. versionadded:: 2.6
default_command_integration_types: Collection[:class:`IntegrationType`]]
The default integration types that the bot will use for commands.
Defaults to a set containing :attr:`IntegrationType.guild_install`.
.. versionadded:: 2.6
"""

@property
Expand Down
2 changes: 1 addition & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ async def create_thread(
A list of stickers to upload. Must be a maximum of 3.
delete_message_after: :class:`int`
The time to wait before deleting the thread.
nonce: :class:`int`
nonce: Union[:class:`str`, :class:`int`]
The nonce to use for sending this message. If the message was successfully sent,
then the message will have a nonce with this value.
allowed_mentions: :class:`~discord.AllowedMentions`
Expand Down
Loading

0 comments on commit 5706da0

Please sign in to comment.