diff options
author | 2022-02-22 21:27:35 +0000 | |
---|---|---|
committer | 2022-02-24 20:07:37 +0000 | |
commit | 953e255becbb1ba3daac96f07f2841d820ca931e (patch) | |
tree | 15a52572b346c23249fe6a8529e7e4ca4fc98fc6 | |
parent | Add disnake monkey patches (diff) |
Migrate to using disnake over Discord.py 2.0a0
-rw-r--r-- | CHANGELOG.md | 10 | ||||
-rw-r--r-- | botcore/__init__.py | 2 | ||||
-rw-r--r-- | botcore/exts/__init__.py | 2 | ||||
-rw-r--r-- | botcore/utils/__init__.py | 2 | ||||
-rw-r--r-- | botcore/utils/channel.py | 20 | ||||
-rw-r--r-- | botcore/utils/extensions.py | 4 | ||||
-rw-r--r-- | botcore/utils/members.py | 24 | ||||
-rw-r--r-- | botcore/utils/regex.py | 2 | ||||
-rw-r--r-- | docs/conf.py | 2 | ||||
-rw-r--r-- | poetry.lock | 2 | ||||
-rw-r--r-- | pyproject.toml | 3 |
11 files changed, 38 insertions, 35 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a4acba..918cf45c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2.0.0 22nd February 2022 - Breaking: Moved regex to botcore.utils namespace +- Feature: Migrate from discord.py 2.0a0 to disnake. +- Feature: Add common monkey patches. - Feature: Port many common utilities from our bots - caching - channel @@ -12,12 +14,12 @@ - Support: Added intersphinx to docs. ## 1.2.0 9th January 2022 -- Feature: Code block detection regex +- Feature: Add code block detection regex. ## 1.1.0 2nd December 2021 -- Support: Autogenerated docs. -- Feature: Regex utility. +- Support: Add autogenerated docs. +- Feature: Add a regex utility. ## 1.0.0 17th November 2021 -- Support: Core package, poetry, and linting CI. +- Support: Add the core package, poetry, and linting CI. diff --git a/botcore/__init__.py b/botcore/__init__.py index d910f393..a5835306 100644 --- a/botcore/__init__.py +++ b/botcore/__init__.py @@ -1,4 +1,4 @@ -"""Useful utilities and tools for discord bot development.""" +"""Useful utilities and tools for Discord bot development.""" from botcore import exts, utils diff --git a/botcore/exts/__init__.py b/botcore/exts/__init__.py index 029178a9..afd56166 100644 --- a/botcore/exts/__init__.py +++ b/botcore/exts/__init__.py @@ -1,4 +1,4 @@ -"""Reusable discord cogs.""" +"""Reusable Discord cogs.""" __all__ = [] __all__ = list(map(lambda module: module.__name__, __all__)) diff --git a/botcore/utils/__init__.py b/botcore/utils/__init__.py index 671ef49f..890f30da 100644 --- a/botcore/utils/__init__.py +++ b/botcore/utils/__init__.py @@ -1,4 +1,4 @@ -"""Useful utilities and tools for discord bot development.""" +"""Useful utilities and tools for Discord bot development.""" from botcore.utils import (caching, channel, extensions, logging, members, monkey_patches, regex, scheduling) diff --git a/botcore/utils/channel.py b/botcore/utils/channel.py index 17e70a2a..d586098f 100644 --- a/botcore/utils/channel.py +++ b/botcore/utils/channel.py @@ -1,14 +1,14 @@ -"""Useful helper functions for interacting with various discord.py channel objects.""" +"""Useful helper functions for interacting with various disnake channel objects.""" -import discord -from discord.ext.commands import Bot +import disnake +from disnake.ext.commands import Bot from botcore.utils import logging log = logging.get_logger(__name__) -def is_in_category(channel: discord.TextChannel, category_id: int) -> bool: +def is_in_category(channel: disnake.TextChannel, category_id: int) -> bool: """ Return whether the given ``channel`` in the the category with the id ``category_id``. @@ -22,22 +22,22 @@ def is_in_category(channel: discord.TextChannel, category_id: int) -> bool: return getattr(channel, "category_id", None) == category_id -async def get_or_fetch_channel(bot: Bot, channel_id: int) -> discord.abc.GuildChannel: +async def get_or_fetch_channel(bot: Bot, channel_id: int) -> disnake.abc.GuildChannel: """ Attempt to get or fetch the given ``channel_id`` from the bots cache, and return it. Args: - bot: The :obj:`discord.ext.commands.Bot` instance to use for getting/fetching. + bot: The :obj:`disnake.ext.commands.Bot` instance to use for getting/fetching. channel_id: The channel to get/fetch. Raises: - :exc:`discord.InvalidData` + :exc:`disnake.InvalidData` An unknown channel type was received from Discord. - :exc:`discord.HTTPException` + :exc:`disnake.HTTPException` Retrieving the channel failed. - :exc:`discord.NotFound` + :exc:`disnake.NotFound` Invalid Channel ID. - :exc:`discord.Forbidden` + :exc:`disnake.Forbidden` You do not have permission to fetch this channel. Returns: diff --git a/botcore/utils/extensions.py b/botcore/utils/extensions.py index 3f8d6e6d..053a58dc 100644 --- a/botcore/utils/extensions.py +++ b/botcore/utils/extensions.py @@ -1,4 +1,4 @@ -"""Utilities for loading discord extensions.""" +"""Utilities for loading Discord extensions.""" import importlib import inspect @@ -28,7 +28,7 @@ def walk_extensions(module: types.ModuleType) -> frozenset[str]: module (types.ModuleType): The module to look for extensions in. Returns: - A set of strings that can be passed directly to :obj:`discord.ext.commands.Bot.load_extension`. + A set of strings that can be passed directly to :obj:`disnake.ext.commands.Bot.load_extension`. """ def on_error(name: str) -> NoReturn: diff --git a/botcore/utils/members.py b/botcore/utils/members.py index e89b4618..f4a30eca 100644 --- a/botcore/utils/members.py +++ b/botcore/utils/members.py @@ -1,27 +1,27 @@ -"""Useful helper functions for interactin with :obj:`discord.Member` objects.""" +"""Useful helper functions for interactin with :obj:`disnake.Member` objects.""" import typing -import discord +import disnake from botcore.utils import logging log = logging.get_logger(__name__) -async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> typing.Optional[discord.Member]: +async def get_or_fetch_member(guild: disnake.Guild, member_id: int) -> typing.Optional[disnake.Member]: """ Attempt to get a member from cache; on failure fetch from the API. Returns: - The :obj:`discord.Member` or :obj:`None` to indicate the member could not be found. + The :obj:`disnake.Member` or :obj:`None` to indicate the member could not be found. """ if member := guild.get_member(member_id): log.trace(f"{member} retrieved from cache.") else: try: member = await guild.fetch_member(member_id) - except discord.errors.NotFound: + except disnake.errors.NotFound: log.trace(f"Failed to fetch {member_id} from API.") return None log.trace(f"{member} fetched from API.") @@ -29,28 +29,28 @@ async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> typing.Op async def handle_role_change( - member: discord.Member, + member: disnake.Member, coro: typing.Callable[..., typing.Coroutine], - role: discord.Role + role: disnake.Role ) -> None: """ Await the given ``coro`` with ``member`` as the sole argument. Handle errors that we expect to be raised from - :obj:`discord.Member.add_roles` and :obj:`discord.Member.remove_roles`. + :obj:`disnake.Member.add_roles` and :obj:`disnake.Member.remove_roles`. Args: member: The member to pass to ``coro``. - coro: This is intended to be :obj:`discord.Member.add_roles` or :obj:`discord.Member.remove_roles`. + coro: This is intended to be :obj:`disnake.Member.add_roles` or :obj:`disnake.Member.remove_roles`. """ try: await coro(role) - except discord.NotFound: + except disnake.NotFound: log.error(f"Failed to change role for {member} ({member.id}): member not found") - except discord.Forbidden: + except disnake.Forbidden: log.error( f"Forbidden to change role for {member} ({member.id}); " f"possibly due to role hierarchy" ) - except discord.HTTPException as e: + except disnake.HTTPException as e: log.error(f"Failed to change role for {member} ({member.id}): {e.status} {e.code}") diff --git a/botcore/utils/regex.py b/botcore/utils/regex.py index 036a5113..abcaf299 100644 --- a/botcore/utils/regex.py +++ b/botcore/utils/regex.py @@ -15,7 +15,7 @@ DISCORD_INVITE = re.compile( flags=re.IGNORECASE ) """ -Regex for discord server invites. +Regex for Discord server invites. :meta hide-value: """ diff --git a/docs/conf.py b/docs/conf.py index 476a4d36..73de7daf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -129,7 +129,7 @@ extlinks = { # -- Options for intersphinx extension --------------------------------------- intersphinx_mapping = { "python": ("https://docs.python.org/3", None), - "discord": ("https://discordpy.readthedocs.io/en/master/", None), + "disnake": ("https://docs.disnake.dev/en/latest/", None), } diff --git a/poetry.lock b/poetry.lock index bdd1dca2..ff72a744 100644 --- a/poetry.lock +++ b/poetry.lock @@ -932,7 +932,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "3.9.*" -content-hash = "42f5eb3043cb7978b883467bd251b0670265b20676592f9676a462b5a1954847" +content-hash = "b2585f0b1be17d986b433b20045d09a78f4262de870d8265f51a69c929955637" [metadata.files] aiohttp = [ diff --git a/pyproject.toml b/pyproject.toml index 5eab4fb1..2d67ff34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,8 @@ exclude = ["tests", "tests.*"] [tool.poetry.dependencies] python = "3.9.*" -disnake = ">=2.4" +# It is expected that bots that use bot-core will define a striciter version of disnake. +disnake = "^2" [tool.poetry.dev-dependencies] flake8 = "4.0.1" |