Merge branch 'iDevision:2.0' into 2.0
This commit is contained in:
12
README.rst
12
README.rst
@@ -17,18 +17,6 @@ The Future of enhanced-discord.py
|
|||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
Enhanced discord.py is a fork of Rapptz's discord.py, that went unmaintained (`gist <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1>`_)
|
Enhanced discord.py is a fork of Rapptz's discord.py, that went unmaintained (`gist <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1>`_)
|
||||||
|
|
||||||
It is currently maintained by (in alphabetical order)
|
|
||||||
|
|
||||||
- Chillymosh#8175
|
|
||||||
- Daggy#9889
|
|
||||||
- dank Had0cK#6081
|
|
||||||
- Dutchy#6127
|
|
||||||
- Eyesofcreeper#0001
|
|
||||||
- Gnome!#6669
|
|
||||||
- IAmTomahawkx#1000
|
|
||||||
- Jadon#2494
|
|
||||||
|
|
||||||
An overview of added features is available on the `custom features page <https://enhanced-dpy.readthedocs.io/en/latest/index.html#custom-features>`_.
|
An overview of added features is available on the `custom features page <https://enhanced-dpy.readthedocs.io/en/latest/index.html#custom-features>`_.
|
||||||
|
|
||||||
Key Features
|
Key Features
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
import collections
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import importlib.util
|
import importlib.util
|
||||||
@@ -72,7 +73,9 @@ from .cog import Cog
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
|
|
||||||
|
from discord.role import Role
|
||||||
from discord.message import Message
|
from discord.message import Message
|
||||||
|
from discord.abc import PartialMessageableChannel
|
||||||
from ._types import (
|
from ._types import (
|
||||||
Check,
|
Check,
|
||||||
CoroFunc,
|
CoroFunc,
|
||||||
@@ -94,10 +97,17 @@ CXT = TypeVar("CXT", bound="Context")
|
|||||||
|
|
||||||
class _FakeSlashMessage(discord.PartialMessage):
|
class _FakeSlashMessage(discord.PartialMessage):
|
||||||
activity = application = edited_at = reference = webhook_id = None
|
activity = application = edited_at = reference = webhook_id = None
|
||||||
attachments = components = reactions = stickers = mentions = []
|
attachments = components = reactions = stickers = []
|
||||||
author: Union[discord.User, discord.Member]
|
|
||||||
tts = False
|
tts = False
|
||||||
|
|
||||||
|
raw_mentions = discord.Message.raw_mentions
|
||||||
|
clean_content = discord.Message.clean_content
|
||||||
|
channel_mentions = discord.Message.channel_mentions
|
||||||
|
raw_role_mentions = discord.Message.raw_role_mentions
|
||||||
|
raw_channel_mentions = discord.Message.raw_channel_mentions
|
||||||
|
|
||||||
|
author: Union[discord.User, discord.Member]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_interaction(
|
def from_interaction(
|
||||||
cls, interaction: discord.Interaction, channel: Union[discord.TextChannel, discord.DMChannel, discord.Thread]
|
cls, interaction: discord.Interaction, channel: Union[discord.TextChannel, discord.DMChannel, discord.Thread]
|
||||||
@@ -108,6 +118,22 @@ class _FakeSlashMessage(discord.PartialMessage):
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def mentions(self) -> List[Union[discord.Member, discord.User]]:
|
||||||
|
client = self._state._get_client()
|
||||||
|
if self.guild:
|
||||||
|
ensure_user = lambda id: self.guild.get_member(id) or client.get_user(id) # type: ignore
|
||||||
|
else:
|
||||||
|
ensure_user = client.get_user
|
||||||
|
|
||||||
|
return discord.utils._unique(filter(None, map(ensure_user, self.raw_mentions)))
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def role_mentions(self) -> List[Role]:
|
||||||
|
if self.guild is None:
|
||||||
|
return []
|
||||||
|
return discord.utils._unique(filter(None, map(self.guild.get_role, self.raw_role_mentions)))
|
||||||
|
|
||||||
|
|
||||||
def when_mentioned(bot: Union[Bot, AutoShardedBot], msg: Message) -> List[str]:
|
def when_mentioned(bot: Union[Bot, AutoShardedBot], msg: Message) -> List[str]:
|
||||||
"""A callable that implements a command prefix equivalent to being mentioned.
|
"""A callable that implements a command prefix equivalent to being mentioned.
|
||||||
@@ -1266,7 +1292,7 @@ class BotBase(GroupMixin):
|
|||||||
|
|
||||||
# Make our fake message so we can pass it to ext.commands
|
# Make our fake message so we can pass it to ext.commands
|
||||||
message: discord.Message = _FakeSlashMessage.from_interaction(interaction, channel) # type: ignore
|
message: discord.Message = _FakeSlashMessage.from_interaction(interaction, channel) # type: ignore
|
||||||
message.content = f"/{command_name} "
|
message.content = f"/{command_name}"
|
||||||
|
|
||||||
# Add arguments to fake message content, in the right order
|
# Add arguments to fake message content, in the right order
|
||||||
ignore_params: List[inspect.Parameter] = []
|
ignore_params: List[inspect.Parameter] = []
|
||||||
@@ -1281,7 +1307,7 @@ class BotBase(GroupMixin):
|
|||||||
else:
|
else:
|
||||||
prefix = param.annotation.__commands_flag_prefix__
|
prefix = param.annotation.__commands_flag_prefix__
|
||||||
delimiter = param.annotation.__commands_flag_delimiter__
|
delimiter = param.annotation.__commands_flag_delimiter__
|
||||||
message.content += f"{prefix}{name} {option['value']}{delimiter}" # type: ignore
|
message.content += f" {prefix}{name}{delimiter}{option['value']}" # type: ignore
|
||||||
continue
|
continue
|
||||||
|
|
||||||
option = next((o for o in command_options if o["name"] == name), None)
|
option = next((o for o in command_options if o["name"] == name), None)
|
||||||
@@ -1297,9 +1323,9 @@ class BotBase(GroupMixin):
|
|||||||
):
|
):
|
||||||
# String with space in without "consume rest"
|
# String with space in without "consume rest"
|
||||||
option = cast(_ApplicationCommandInteractionDataOptionString, option)
|
option = cast(_ApplicationCommandInteractionDataOptionString, option)
|
||||||
message.content += f"{_quote_string_safe(option['value'])} "
|
message.content += f" {_quote_string_safe(option['value'])}"
|
||||||
else:
|
else:
|
||||||
message.content += f'{option.get("value", "")} '
|
message.content += f' {option.get("value", "")}'
|
||||||
|
|
||||||
ctx = await self.get_context(message)
|
ctx = await self.get_context(message)
|
||||||
ctx._ignored_params = ignore_params
|
ctx._ignored_params = ignore_params
|
||||||
|
|||||||
@@ -136,6 +136,14 @@ application_option_type_lookup = {
|
|||||||
discord.Role: 8,
|
discord.Role: 8,
|
||||||
float: 10,
|
float: 10,
|
||||||
}
|
}
|
||||||
|
application_option_channel_types = {
|
||||||
|
discord.VoiceChannel: [2],
|
||||||
|
discord.TextChannel: [0, 5, 6],
|
||||||
|
discord.CategoryChannel: [4],
|
||||||
|
discord.Thread: [10, 11, 12],
|
||||||
|
discord.StageChannel: [13],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
P = ParamSpec("P")
|
P = ParamSpec("P")
|
||||||
@@ -1265,12 +1273,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
for python_type, discord_type in application_option_type_lookup.items():
|
for python_type, discord_type in application_option_type_lookup.items():
|
||||||
if issubclass(annotation, python_type):
|
if issubclass(annotation, python_type):
|
||||||
option["type"] = discord_type
|
option["type"] = discord_type
|
||||||
|
# Set channel types
|
||||||
|
if discord_type == 7:
|
||||||
|
option["channel_types"] = application_option_channel_types[annotation]
|
||||||
break
|
break
|
||||||
|
|
||||||
elif origin is Union:
|
elif origin is Union:
|
||||||
if annotation in {Union[discord.Member, discord.Role], Union[MemberConverter, RoleConverter]}:
|
if annotation in {Union[discord.Member, discord.Role], Union[MemberConverter, RoleConverter]}:
|
||||||
option["type"] = 9
|
option["type"] = 9
|
||||||
|
|
||||||
|
elif all([arg in application_option_channel_types for arg in annotation.__args__]):
|
||||||
|
option["type"] = 7
|
||||||
|
option["channel_types"] = [discord_value for arg in annotation.__args__ for discord_value in application_option_channel_types[arg]]
|
||||||
|
|
||||||
elif origin is Literal:
|
elif origin is Literal:
|
||||||
literal_values = annotation.__args__
|
literal_values = annotation.__args__
|
||||||
python_type = type(literal_values[0])
|
python_type = type(literal_values[0])
|
||||||
@@ -1694,7 +1709,9 @@ class Group(GroupMixin[CogT], Command[CogT, P, T]):
|
|||||||
"name": self.name,
|
"name": self.name,
|
||||||
"type": int(not (nested - 1)) + 1,
|
"type": int(not (nested - 1)) + 1,
|
||||||
"description": self.short_doc or "no description",
|
"description": self.short_doc or "no description",
|
||||||
"options": [cmd.to_application_command(nested=nested + 1) for cmd in sorted(self.commands, key=lambda x: x.name)],
|
"options": [
|
||||||
|
cmd.to_application_command(nested=nested + 1) for cmd in sorted(self.commands, key=lambda x: x.name)
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ class BadInviteArgument(BadArgument):
|
|||||||
This inherits from :exc:`BadArgument`
|
This inherits from :exc:`BadArgument`
|
||||||
|
|
||||||
.. versionadded:: 1.5
|
.. versionadded:: 1.5
|
||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
-----------
|
-----------
|
||||||
argument: :class:`str`
|
argument: :class:`str`
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ class HTTPClient:
|
|||||||
self.proxy_auth: Optional[aiohttp.BasicAuth] = proxy_auth
|
self.proxy_auth: Optional[aiohttp.BasicAuth] = proxy_auth
|
||||||
self.use_clock: bool = not unsync_clock
|
self.use_clock: bool = not unsync_clock
|
||||||
|
|
||||||
user_agent = "DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
|
u_agent = "DiscordBot (https://github.com/iDevision/enhanced-discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
|
||||||
self.user_agent: str = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
self.user_agent: str = u_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
||||||
|
|
||||||
def recreate(self) -> None:
|
def recreate(self) -> None:
|
||||||
if self.__session.closed:
|
if self.__session.closed:
|
||||||
|
|||||||
1274
docs/api.rst
1274
docs/api.rst
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,7 @@ autodoc_typehints = "none"
|
|||||||
# napoleon_attr_annotations = False
|
# napoleon_attr_annotations = False
|
||||||
|
|
||||||
extlinks = {
|
extlinks = {
|
||||||
"issue": ("https://github.com/Rapptz/discord.py/issues/%s", "GH-"),
|
"issue": ("https://github.com/iDevision/enhanced-discord.py/issues/%s", "GH-"),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Links used for cross-referencing stuff in other documentation
|
# Links used for cross-referencing stuff in other documentation
|
||||||
@@ -168,9 +168,8 @@ html_context = {
|
|||||||
|
|
||||||
resource_links = {
|
resource_links = {
|
||||||
"discord": "https://discord.gg/TvqYBrGXEm",
|
"discord": "https://discord.gg/TvqYBrGXEm",
|
||||||
"issues": "https://github.com/Rapptz/discord.py/issues",
|
"issues": "https://github.com/iDevision/enhanced-discord.py/issues",
|
||||||
"discussions": "https://github.com/Rapptz/discord.py/discussions",
|
"examples": f"https://github.com/iDevision/enhanced-discord.py/tree/{branch}/examples",
|
||||||
"examples": f"https://github.com/Rapptz/discord.py/tree/{branch}/examples",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Theme options are theme-specific and customize the look and feel of a theme
|
# Theme options are theme-specific and customize the look and feel of a theme
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ If you're having trouble with something, these resources might help.
|
|||||||
- Ask us and hang out with us in our :resource:`Discord <discord>` server.
|
- Ask us and hang out with us in our :resource:`Discord <discord>` server.
|
||||||
- If you're looking for something specific, try the :ref:`index <genindex>` or :ref:`searching <search>`.
|
- If you're looking for something specific, try the :ref:`index <genindex>` or :ref:`searching <search>`.
|
||||||
- Report bugs in the :resource:`issue tracker <issues>`.
|
- Report bugs in the :resource:`issue tracker <issues>`.
|
||||||
- Ask in our :resource:`GitHub discussions page <discussions>`.
|
|
||||||
|
|
||||||
Extensions
|
Extensions
|
||||||
------------
|
------------
|
||||||
|
|||||||
Reference in New Issue
Block a user