Skip to content

Commit

Permalink
Merge branch 'master' into feat/default_forum_reaction
Browse files Browse the repository at this point in the history
Signed-off-by: plun1331 <[email protected]>
  • Loading branch information
plun1331 authored Dec 14, 2023
2 parents 4e840e6 + c1a57fa commit 64969e3
Show file tree
Hide file tree
Showing 33 changed files with 427 additions and 131 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand All @@ -25,8 +25,8 @@ jobs:
bandit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.1.0
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -70,4 +70,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand All @@ -31,8 +31,8 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
Expand All @@ -48,9 +48,9 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
todo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run tdg-github-action
uses: ribtoks/[email protected]
with:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.0
rev: v2.2.1
hooks:
- id: autoflake
# args:
Expand All @@ -19,7 +19,7 @@ repos:
# - --remove-duplicate-keys
# - --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -28,7 +28,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.11.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down Expand Up @@ -77,7 +77,7 @@ repos:
# - id: mypy

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
rev: v3.1.0
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
135 changes: 84 additions & 51 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def permissions_for(self, obj: Member | Role, /) -> Permissions:
return Permissions.all()

default = self.guild.default_role
base = Permissions(default.permissions.value)
base = Permissions(default.permissions.value if default else 0)

# Handle the role case first
if isinstance(obj, Role):
Expand Down
11 changes: 8 additions & 3 deletions discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Activity(BaseActivity):
type: :class:`ActivityType`
The type of activity currently being done.
state: Optional[:class:`str`]
The user's current state. For example, "In Game".
The user's current party status or text used for a custom status.
details: Optional[:class:`str`]
The detail of the user's current activity.
timestamps: Dict[:class:`str`, :class:`int`]
Expand Down Expand Up @@ -229,7 +229,6 @@ def __init__(self, **kwargs):
self.assets: ActivityAssets = kwargs.pop("assets", {})
self.party: ActivityParty = kwargs.pop("party", {})
self.application_id: int | None = _get_as_snowflake(kwargs, "application_id")
self.name: str | None = kwargs.pop("name", None)
self.url: str | None = kwargs.pop("url", None)
self.flags: int = kwargs.pop("flags", 0)
self.sync_id: str | None = kwargs.pop("sync_id", None)
Expand All @@ -242,6 +241,9 @@ def __init__(self, **kwargs):
if isinstance(activity_type, ActivityType)
else try_enum(ActivityType, activity_type)
)
self.name: str | None = kwargs.pop(
"name", "Custom Status" if self.type == ActivityType.custom else None
)

emoji = kwargs.pop("emoji", None)
self.emoji: PartialEmoji | None = (
Expand All @@ -252,6 +254,7 @@ def __repr__(self) -> str:
attrs = (
("type", self.type),
("name", self.name),
("state", self.state),
("url", self.url),
("details", self.details),
("application_id", self.application_id),
Expand Down Expand Up @@ -760,6 +763,8 @@ class CustomActivity(BaseActivity):
The custom activity's name.
emoji: Optional[:class:`PartialEmoji`]
The emoji to pass to the activity, if any.
state: Optional[:class:`str`]
The text used for the custom activity.
"""

__slots__ = ("name", "emoji", "state")
Expand All @@ -769,7 +774,7 @@ def __init__(
):
super().__init__(**extra)
self.name: str | None = name
self.state: str | None = extra.pop("state", None)
self.state: str | None = extra.pop("state", name)
if self.name == "Custom Status":
self.name = self.state

Expand Down
4 changes: 2 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ async def on_connect():
lambda cmd: cmd.name == i["name"]
and cmd.type == i.get("type")
and cmd.guild_ids is not None
# TODO: fix this type error (guild_id is not defined in ApplicationCommand Typed Dict)
and int(i["guild_id"]) in cmd.guild_ids, # type: ignore
and (guild_id := i.get("guild_id"))
and guild_id in cmd.guild_ids,
self.pending_application_commands,
)
if not cmd:
Expand Down
12 changes: 11 additions & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
"user_limit",
"_state",
"position",
"slowmode_delay",
"_overwrites",
"category_id",
"rtc_region",
Expand Down Expand Up @@ -1397,6 +1398,7 @@ def _update(
data, "last_message_id"
)
self.position: int = data.get("position")
self.slowmode_delay = data.get("rate_limit_per_user", 0)
self.bitrate: int = data.get("bitrate")
self.user_limit: int = data.get("user_limit")
self.flags: ChannelFlags = ChannelFlags._from_value(data.get("flags", 0))
Expand Down Expand Up @@ -1504,6 +1506,13 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
The ID of the last message sent to this channel. It may not always point to an existing or valid message.
.. versionadded:: 2.0
slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages
in this channel. A value of `0` denotes that it is disabled.
Bots and users with :attr:`~Permissions.manage_channels` or
:attr:`~Permissions.manage_messages` bypass slowmode.
.. versionadded:: 2.5
flags: :class:`ChannelFlags`
Extra features of the channel.
Expand Down Expand Up @@ -1812,6 +1821,7 @@ async def edit(
overwrites: Mapping[Role | Member, PermissionOverwrite] = ...,
rtc_region: VoiceRegion | None = ...,
video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
reason: str | None = ...,
) -> VoiceChannel | None:
...
Expand Down Expand Up @@ -2838,7 +2848,7 @@ def __init__(
self._state: ConnectionState = state
self.recipient: User | None = None
if r := data.get("recipients"):
self.recipient: state.store_user(r[0])
self.recipient = state.store_user(r[0])
self.me: ClientUser = me
self.id: int = int(data["id"])

Expand Down
6 changes: 4 additions & 2 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,12 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
option = next(option_gen, Option())
# Handle Optional
if self._is_typing_optional(type_hint):
option.input_type = get_args(type_hint)[0]
option.input_type = SlashCommandOptionType.from_datatype(
get_args(type_hint)[0]
)
option.default = None
else:
option.input_type = type_hint
option.input_type = SlashCommandOptionType.from_datatype(type_hint)

if self._is_typing_union(option):
if self._is_typing_optional(option):
Expand Down
8 changes: 8 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"AutoModActionType",
"AutoModKeywordPresetType",
"ApplicationRoleConnectionMetadataType",
"ReactionType",
)


Expand Down Expand Up @@ -944,6 +945,13 @@ class ApplicationRoleConnectionMetadataType(Enum):
boolean_not_equal = 8


class ReactionType(Enum):
"""The reaction type"""

normal = 0
burst = 1


T = TypeVar("T")


Expand Down
11 changes: 9 additions & 2 deletions discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

from ...commands import (
ApplicationCommand,
Option,
_BaseCommand,
message_command,
slash_command,
Expand Down Expand Up @@ -562,7 +563,13 @@ async def dispatch_error(self, ctx: Context, error: Exception) -> None:
ctx.bot.dispatch("command_error", ctx, error)

async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
required = param.default is param.empty
if isinstance(param.annotation, Option):
default = param.annotation.default
required = param.annotation.required
else:
default = param.default
required = default is param.empty

converter = get_converter(param)
consume_rest_is_special = (
param.kind == param.KEYWORD_ONLY and not self.rest_is_raw
Expand Down Expand Up @@ -599,7 +606,7 @@ async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
):
return await converter._construct_default(ctx)
raise MissingRequiredArgument(param)
return param.default
return default

previous = view.index
if consume_rest_is_special:
Expand Down
22 changes: 15 additions & 7 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _get_next_sleep_time(self) -> datetime.datetime:
if self._current_loop == 0:
# if we're at the last index on the first iteration, we need to sleep until tomorrow
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(self._time[0].tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
self._time[0],
)
Expand All @@ -584,18 +584,26 @@ def _get_next_sleep_time(self) -> datetime.datetime:

if self._current_loop == 0:
self._time_index += 1
if next_time > datetime.datetime.now(datetime.timezone.utc).timetz():
if (
next_time
> datetime.datetime.now(
next_time.tzinfo or datetime.timezone.utc
).timetz()
):
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc), next_time
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc),
next_time,
)
else:
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
next_time,
)

next_date = cast(datetime.datetime, self._last_iteration)
next_date = cast(
datetime.datetime, self._last_iteration.astimezone(next_time.tzinfo)
)
if next_time < next_date.timetz():
next_date += datetime.timedelta(days=1)

Expand All @@ -611,9 +619,9 @@ def _prepare_time_index(self, now: datetime.datetime = MISSING) -> None:
now
if now is not MISSING
else datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
).timetz()
)
for idx, time in enumerate(self._time):
if time >= time_now:
if time >= time_now.astimezone(time.tzinfo).timetz():
self._time_index = idx
break
else:
Expand Down
4 changes: 2 additions & 2 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ def __init__(self, **kwargs: bool):
@classmethod
def all(cls: type[Intents]) -> Intents:
"""A factory method that creates a :class:`Intents` with everything enabled."""
bits = max(cls.VALID_FLAGS.values()).bit_length()
value = (1 << bits) - 1
value = sum({1 << (flag.bit_length() - 1) for flag in cls.VALID_FLAGS.values()})

self = cls.__new__(cls)
self.value = value
return self
Expand Down
Loading

0 comments on commit 64969e3

Please sign in to comment.