4 Commits

Author SHA1 Message Date
e48493b36c Actually block out Python 3.9.7
reference PR https://github.com/iDevision/enhanced-discord.py/pull/93
2021-10-05 21:12:40 -05:00
4931100b44 Advise version incompatibility with Python 3.9.7
Due to a bug in Python 3.9.7, code situations where we call an __init__ function in a subclass will fail with a TypeError. 

This is only a bug within the Python language and was patched out with Python 3.10 and this doesn't affect Python 3.9.6. 

Here, we are advising the incompatibility.
2021-10-05 21:03:05 -05:00
ec1e2add21 Update user-agent (#92) 2021-10-04 21:11:10 +01:00
4277f65051 Implement _FakeSlashMessage.clean_content
Closes #83
2021-10-03 21:05:00 +01:00
8 changed files with 36 additions and 67 deletions

View File

@ -41,7 +41,9 @@ Key Features
Installing Installing
---------- ----------
**Python 3.8 or higher is required** **Python 3.8 or higher is required***
***Do not use 3.9.7 as Python 3.9.7 has a bug that causes a TypeError with __init__ methods in subclasses.** View more `here <https://bugs.python.org/issue45121/>`_.
To install the library without full voice support, you can just run the following command: To install the library without full voice support, you can just run the following command:

View File

@ -245,15 +245,6 @@ class Asset(AssetMixin):
animated=animated, animated=animated,
) )
@classmethod
def _from_role_icon(cls, state, role_id: int, role_hash: str) -> Asset:
return cls(
state,
url=f"{cls.BASE}/role-icons/{role_id}/{role_hash}.png",
key=role_hash,
animated=False,
)
def __str__(self) -> str: def __str__(self) -> str:
return self._url return self._url

View File

@ -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.

View File

@ -2448,8 +2448,6 @@ class Guild(Hashable):
colour: Union[Colour, int] = ..., colour: Union[Colour, int] = ...,
hoist: bool = ..., hoist: bool = ...,
mentionable: bool = ..., mentionable: bool = ...,
icon: bytes = ...,
emoji: str = ...,
) -> Role: ) -> Role:
... ...
@ -2463,8 +2461,6 @@ class Guild(Hashable):
color: Union[Colour, int] = ..., color: Union[Colour, int] = ...,
hoist: bool = ..., hoist: bool = ...,
mentionable: bool = ..., mentionable: bool = ...,
icon: bytes = ...,
emoji: str = ...,
) -> Role: ) -> Role:
... ...
@ -2477,8 +2473,6 @@ class Guild(Hashable):
colour: Union[Colour, int] = MISSING, colour: Union[Colour, int] = MISSING,
hoist: bool = MISSING, hoist: bool = MISSING,
mentionable: bool = MISSING, mentionable: bool = MISSING,
icon: bytes = MISSING,
emoji: str = MISSING,
reason: Optional[str] = None, reason: Optional[str] = None,
) -> Role: ) -> Role:
"""|coro| """|coro|
@ -2508,10 +2502,6 @@ class Guild(Hashable):
mentionable: :class:`bool` mentionable: :class:`bool`
Indicates if the role should be mentionable by others. Indicates if the role should be mentionable by others.
Defaults to ``False``. Defaults to ``False``.
emoji: :class:`str`
The unicode emoji that is shown next to users with the role.
icon: :class:`bytes`
A custom image that is shown next to users with the role.
reason: Optional[:class:`str`] reason: Optional[:class:`str`]
The reason for creating this role. Shows up on the audit log. The reason for creating this role. Shows up on the audit log.
@ -2550,12 +2540,6 @@ class Guild(Hashable):
if name is not MISSING: if name is not MISSING:
fields["name"] = name fields["name"] = name
if emoji is not MISSING:
fields["unicode_emoji"] = emoji
if icon is not MISSING:
fields["icon"] = utils._bytes_to_base64_data(icon)
data = await self._state.http.create_role(self.id, reason=reason, **fields) data = await self._state.http.create_role(self.id, reason=reason, **fields)
role = Role(guild=self, data=data, state=self._state) role = Role(guild=self, data=data, state=self._state)

View File

@ -188,7 +188,7 @@ 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}" user_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 = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
def recreate(self) -> None: def recreate(self) -> None:

View File

@ -23,14 +23,13 @@ DEALINGS IN THE SOFTWARE.
""" """
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING from typing import Any, Dict, List, Optional, TypeVar, Union, overload, TYPE_CHECKING
from .asset import Asset
from .permissions import Permissions from .permissions import Permissions
from .errors import InvalidArgument from .errors import InvalidArgument
from .colour import Colour from .colour import Colour
from .mixins import Hashable from .mixins import Hashable
from .utils import snowflake_time, _get_as_snowflake, MISSING, _bytes_to_base64_data from .utils import snowflake_time, _get_as_snowflake, MISSING
__all__ = ( __all__ = (
"RoleTags", "RoleTags",
@ -159,15 +158,7 @@ class Role(Hashable):
guild: :class:`Guild` guild: :class:`Guild`
The guild the role belongs to. The guild the role belongs to.
hoist: :class:`bool` hoist: :class:`bool`
Indicates if the role will be displayed separately from other members. Indicates if the role will be displayed separately from other members.
icon: Optional[:class:`Asset`]
A custom image that is shown next to users with the role.
.. versionadded:: 2.0
emoji: Optional[:class:`str`]
The unicode emoji that is shown next to users with the role.
.. versionadded:: 2.0
position: :class:`int` position: :class:`int`
The position of the role. This number is usually positive. The bottom The position of the role. This number is usually positive. The bottom
role has a position of 0. role has a position of 0.
@ -200,8 +191,6 @@ class Role(Hashable):
"hoist", "hoist",
"guild", "guild",
"tags", "tags",
"_icon",
"emoji",
"_state", "_state",
) )
@ -262,8 +251,6 @@ class Role(Hashable):
self.position: int = data.get("position", 0) self.position: int = data.get("position", 0)
self._colour: int = data.get("color", 0) self._colour: int = data.get("color", 0)
self.hoist: bool = data.get("hoist", False) self.hoist: bool = data.get("hoist", False)
self.emoji: Optional[str] = data.get("unicode_emoji")
self._icon: Optional[str] = data.get("icon")
self.managed: bool = data.get("managed", False) self.managed: bool = data.get("managed", False)
self.mentionable: bool = data.get("mentionable", False) self.mentionable: bool = data.get("mentionable", False)
self.tags: Optional[RoleTags] self.tags: Optional[RoleTags]
@ -331,13 +318,6 @@ class Role(Hashable):
""":class:`str`: Returns a string that allows you to mention a role.""" """:class:`str`: Returns a string that allows you to mention a role."""
return f"<@&{self.id}>" return f"<@&{self.id}>"
@property
def icon(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the custom icon shown next to users with the role, if it exists."""
if self._icon is None:
return
return Asset._from_role_icon(self._state, self.id, self._icon)
@property @property
def members(self) -> List[Member]: def members(self) -> List[Member]:
"""List[:class:`Member`]: Returns all the members with this role.""" """List[:class:`Member`]: Returns all the members with this role."""
@ -381,8 +361,6 @@ class Role(Hashable):
hoist: bool = MISSING, hoist: bool = MISSING,
mentionable: bool = MISSING, mentionable: bool = MISSING,
position: int = MISSING, position: int = MISSING,
icon: bytes = MISSING,
emoji: str = MISSING,
reason: Optional[str] = MISSING, reason: Optional[str] = MISSING,
) -> Optional[Role]: ) -> Optional[Role]:
"""|coro| """|coro|
@ -415,10 +393,6 @@ class Role(Hashable):
position: :class:`int` position: :class:`int`
The new role's position. This must be below your top role's The new role's position. This must be below your top role's
position or it will fail. position or it will fail.
emoji: :class:`str`
The unicode emoji that is shown next to users with the role.
icon: :class:`bytes`
A custom image that is shown next to users with the role.
reason: Optional[:class:`str`] reason: Optional[:class:`str`]
The reason for editing this role. Shows up on the audit log. The reason for editing this role. Shows up on the audit log.
@ -462,12 +436,6 @@ class Role(Hashable):
if mentionable is not MISSING: if mentionable is not MISSING:
payload["mentionable"] = mentionable payload["mentionable"] = mentionable
if emoji is not MISSING:
payload["unicode_emoji"] = emoji
if icon is not MISSING:
payload["icon"] = _bytes_to_base64_data(icon)
data = await self._state.http.edit_role(self.guild.id, self.id, reason=reason, **payload) data = await self._state.http.edit_role(self.guild.id, self.id, reason=reason, **payload)
return Role(guild=self.guild, data=data, state=self._state) return Role(guild=self.guild, data=data, state=self._state)

View File

@ -29,9 +29,7 @@ from .snowflake import Snowflake
class _RoleOptional(TypedDict, total=False): class _RoleOptional(TypedDict, total=False):
icon: str
tags: RoleTags tags: RoleTags
unicode_emoji: str
class Role(_RoleOptional): class Role(_RoleOptional):

View File

@ -70,7 +70,7 @@ setup(
include_package_data=True, include_package_data=True,
install_requires=requirements, install_requires=requirements,
extras_require=extras_require, extras_require=extras_require,
python_requires=">=3.8.0", python_requires=">=3.8.0, !=3.9.7",
classifiers=[ classifiers=[
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",